【发布时间】:2020-05-30 14:11:08
【问题描述】:
我正在尝试在 R 中整理以下数据集(在链接中),然后在下面运行关联规则。
https://www.kaggle.com/fanatiks/shopping-cart
install.packages("dplyr")
library(dplyr)
df <- read.csv("Groceries (2).csv", header = F, stringsAsFactors = F, na.strings=c(""," ","NA"))
install.packages("stringr")
library(stringr)
temp1<- (str_extract(df$V1, "[a-z]+"))
temp2<- (str_extract(df$V1, "[^a-z]+"))
df<- cbind(temp1,df)
df[2] <- NULL
df[35] <- NULL
View(df)
summary(df)
str(df)
trans <- as(df,"transactions")
当我运行上面的 trans
警告信息: 列 2、3、4、5、6、7、8、9、10、11、12、13、14、15、16、17、18、19、20、21、22、23、24、 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 不合逻辑或因素。应用默认离散化(参见'? discretizeDF')。
summary(trans)
当我运行上面的代码时,我得到以下信息:
transactions as itemMatrix in sparse format with
1499 rows (elements/itemsets/transactions) and
1268 columns (items) and a density of 0.01529042
most frequent items:
V5= vegetables V6= vegetables temp1=vegetables V2= vegetables
140 113 109 108
V9= vegetables (Other)
103 28490
附加的结果将所有蔬菜值显示为单独的项目,而不是组合蔬菜分数,这显然增加了我的列数。我不确定为什么会这样?
fit<-apriori(trans,parameter=list(support=0.006,confidence=0.25,minlen=2))
fit<-sort(fit,by="support")
inspect(head(fit))
【问题讨论】:
标签: r algorithm associations rules