R版本是4.1.1的
rmarkdown版本是2.11
knitr版本是1.36
`---
title: "shopping_p78t5"
author: '197103027'
date: "2021/11/12"
output:
html_document:
fig_width: 15
fig_height: 8
word_document: default
pdf_document: default
(a)
library(arules)
library(arulesViz)
library(dplyr)
shopdata<-read.csv("C:\\Users\\86176\\Desktop\\study\\Data Mining\\all data\\data-exe\\shopping.csv")
shopdata<-shopdata%>%mutate(across(where(is.integer),factor))%>%mutate(across(where(is.character),factor))%>%as_tibble()
mutate(across(everything(),factor))%>%as_tibble()
来源于:https://blog.csdn.net/weixin_54000907/article/details/114559529
(b)
rules<-apriori(shopdata,parameter = list(supp=0.8,conf=0.8,target="rules"))
summary(rules)
rules_pruned<-rules[!is.redundant(rules)]
options(digits = 4)
inspect(rules_pruned)
plot(rules_pruned,method = "graph")
(c)
rules_rhs_ready_made<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Ready_made=1")),
control = list(verbose=F))
inspect(head(rules_rhs_ready_made[!is.redundant(rules_rhs_ready_made)],by="lift"))
rules_rhs_frozen_foods<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Frozen_foods=1")),
control = list(verbose=F))
inspect(head(rules_rhs_frozen_foods[!is.redundant(rules_rhs_frozen_foods)],by="lift"))
rules_rhs_Alcohol<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Alcohol=1")),
control = list(verbose=F))
inspect(head(rules_rhs_Alcohol[!is.redundant(rules_rhs_Alcohol)],by="lift"))
rules_rhs_Fresh_Vegetables<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Fresh_Vegetables=1")),
control = list(verbose=F))
inspect(head(rules_rhs_Fresh_Vegetables[!is.redundant(rules_rhs_Fresh_Vegetables)],by="lift"))
rules_rhs_Milk<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Milk=1")),
control = list(verbose=F))
inspect(head(rules_rhs_Milk[!is.redundant(rules_rhs_Milk)],by="lift"))
rules_rhs_Bakery_goods<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Bakery_goods=1")),
control = list(verbose=F))
inspect(head(rules_rhs_Bakery_goods[!is.redundant(rules_rhs_Bakery_goods)],by="lift"))
rules_rhs_Fresh_meat<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Fresh_meat=1")),
control = list(verbose=F))
inspect(head(rules_rhs_Fresh_meat[!is.redundant(rules_rhs_Fresh_meat)],by="lift"))
rules_rhs_Toiletries<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Toiletries=1")),
control = list(verbose=F))
inspect(head(rules_rhs_Toiletries[!is.redundant(rules_rhs_Toiletries)],by="lift"))
rules_rhs_Snacks<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Snacks=1")),
control = list(verbose=F))
inspect(head(rules_rhs_Snacks[!is.redundant(rules_rhs_Snacks)],by="lift"))
rules_rhs_Tinned_goods<-apriori(shopdata,parameter = list(supp=0.1,conf=0.8),
appearance = list(rhs=c("Tinned_goods=1")),
control = list(verbose=F))
inspect(head(rules_rhs_Tinned_goods[!is.redundant(rules_rhs_Tinned_goods)],by="lift"))
`