> library(arules)
> data(Groceries)
> inspect(Groceries)
9834 {semi-finished bread,
bottled water,
soda,
bottled beer}
9835 {chicken,
tropical fruit,
other vegetables,
vinegar,
shopping bags}
> rules=apriori(Groceries,parameter=list(support=0.01,confidence=0.5))
parameter specification:
confidence minval smax arem aval originalSupport support minlen maxlen target ext
0.5 0.1 1 none FALSE TRUE 0.01 1 10 rules FALSE
algorithmic control:
filter tree heap memopt load sort verbose
0.1 TRUE TRUE FALSE TRUE 2 TRUE
apriori - find association rules with the apriori algorithm
version 4.21 (2004.05.09) (c) 1996-2004 Christian Borgelt
set item appearances ...[0 item(s)] done [0.00s].
set transactions ...[169 item(s), 9835 transaction(s)] done [0.00s].
sorting and recoding items ... [88 item(s)] done [0.00s].
creating transaction tree ... done [0.00s].
checking subsets of size 1 2 3 4 done [0.00s].
writing ... [15 rule(s)] done [0.00s].
creating S4 object ... done [0.02s].
> summary(rules)
set of 15 rules
rule length distribution (lhs + rhs):sizes
3
15
Min. 1st Qu. Median Mean 3rd Qu. Max.
3 3 3 3 3 3
summary of quality measures:
support confidence lift
Min. :0.01007 Min. :0.5000 Min. :1.984
1st Qu.:0.01174 1st Qu.:0.5151 1st Qu.:2.036
Median :0.01230 Median :0.5245 Median :2.203
Mean :0.01316 Mean :0.5411 Mean :2.299
3rd Qu.:0.01403 3rd Qu.:0.5718 3rd Qu.:2.432
Max. :0.02227 Max. :0.5862 Max. :3.030
mining info:
data ntransactions support confidence
Groceries 9835 0.01 0.5
> inspect(rules)
lhs rhs support confidence lift
1 {curd,
yogurt} => {whole milk} 0.01006609 0.5823529 2.279125
2 {other vegetables,
butter} => {whole milk} 0.01148958 0.5736041 2.244885
3 {other vegetables,
domestic eggs} => {whole milk} 0.01230300 0.5525114 2.162336
4 {yogurt,
whipped/sour cream} => {whole milk} 0.01087951 0.5245098 2.052747
5 {other vegetables,
whipped/sour cream} => {whole milk} 0.01464159 0.5070423 1.984385
6 {pip fruit,
other vegetables} => {whole milk} 0.01352313 0.5175097 2.025351
7 {citrus fruit,
root vegetables} => {other vegetables} 0.01037112 0.5862069 3.029608
8 {tropical fruit,
root vegetables} => {other vegetables} 0.01230300 0.5845411 3.020999
9 {tropical fruit,
root vegetables} => {whole milk} 0.01199797 0.5700483 2.230969
10 {tropical fruit,
yogurt} => {whole milk} 0.01514997 0.5173611 2.024770
11 {root vegetables,
yogurt} => {other vegetables} 0.01291307 0.5000000 2.584078
12 {root vegetables,
yogurt} => {whole milk} 0.01453991 0.5629921 2.203354
13 {root vegetables,
rolls/buns} => {other vegetables} 0.01220132 0.5020921 2.594890
14 {root vegetables,
rolls/buns} => {whole milk} 0.01270971 0.5230126 2.046888
15 {other vegetables,
yogurt} => {whole milk} 0.02226741 0.5128806 2.007235
> x=subset(rules,subset=rhs%in%"whole milk"&lift>=1.2)
> x
set of 11 rules
> inspect(x)
lhs rhs support confidence lift
1 {curd,
yogurt} => {whole milk} 0.01006609 0.5823529 2.279125
2 {other vegetables,
butter} => {whole milk} 0.01148958 0.5736041 2.244885
3 {other vegetables,
domestic eggs} => {whole milk} 0.01230300 0.5525114 2.162336
4 {yogurt,
whipped/sour cream} => {whole milk} 0.01087951 0.5245098 2.052747
5 {other vegetables,
whipped/sour cream} => {whole milk} 0.01464159 0.5070423 1.984385
6 {pip fruit,
other vegetables} => {whole milk} 0.01352313 0.5175097 2.025351
7 {tropical fruit,
root vegetables} => {whole milk} 0.01199797 0.5700483 2.230969
8 {tropical fruit,
yogurt} => {whole milk} 0.01514997 0.5173611 2.024770
9 {root vegetables,
yogurt} => {whole milk} 0.01453991 0.5629921 2.203354
10 {root vegetables,
rolls/buns} => {whole milk} 0.01270971 0.5230126 2.046888
11 {other vegetables,
yogurt} => {whole milk} 0.02226741 0.5128806 2.007235
> inspect(sort(x,by="support")[1:5])
lhs rhs support confidence lift
1 {other vegetables,
yogurt} => {whole milk} 0.02226741 0.5128806 2.007235
2 {tropical fruit,
yogurt} => {whole milk} 0.01514997 0.5173611 2.024770
3 {other vegetables,
whipped/sour cream} => {whole milk} 0.01464159 0.5070423 1.984385
4 {root vegetables,
yogurt} => {whole milk} 0.01453991 0.5629921 2.203354
5 {pip fruit,
other vegetables} => {whole milk} 0.01352313 0.5175097 2.025351
> inspect(sort(x,by="support")[1:11])
lhs rhs support confidence lift
1 {other vegetables,
yogurt} => {whole milk} 0.02226741 0.5128806 2.007235
2 {tropical fruit,
yogurt} => {whole milk} 0.01514997 0.5173611 2.024770
3 {other vegetables,
whipped/sour cream} => {whole milk} 0.01464159 0.5070423 1.984385
4 {root vegetables,
yogurt} => {whole milk} 0.01453991 0.5629921 2.203354
5 {pip fruit,
other vegetables} => {whole milk} 0.01352313 0.5175097 2.025351
6 {root vegetables,
rolls/buns} => {whole milk} 0.01270971 0.5230126 2.046888
7 {other vegetables,
domestic eggs} => {whole milk} 0.01230300 0.5525114 2.162336
8 {tropical fruit,
root vegetables} => {whole milk} 0.01199797 0.5700483 2.230969
9 {other vegetables,
butter} => {whole milk} 0.01148958 0.5736041 2.244885
10 {yogurt,
whipped/sour cream} => {whole milk} 0.01087951 0.5245098 2.052747
11 {curd,
yogurt} => {whole milk} 0.01006609 0.5823529 2.279125
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27573546/viewspace-747773/
,如需转载,请注明出处,否则将追究法律责任。