Use dataset “products” (in “datasets” file) to answer questions below.

Use dataset “products” (in “datasets” file) to answer questions below.

Q1: Read “products.rds” dataset using readRDS() function (same as the usage of read.csv()) and coerce it into transactions.

library(arules)  
tr <- read.transactions("products.rds", format = "basket")

Q2: Check the number of transactions and items in this transactions dataset and show the first 3 items.

### the number of transactions and items
dim(tr)
### View the first three items of associated data tr
inspect(head(tr,3))

Q3: Implement apriori algorithm using a minimum support of 0.002 and a minimum confidence of 0.25, and set the maximum length of rules to be 2.

rules <- apriori(tr,
	parameter = list(supp = 0.002, conf = 0.25, target = "rules",
	                 maxlen = 2))
#inspect(rul

你可能感兴趣的:(R语言大学作业,数据分析)