R version 2.9.2 (2009-08-24)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

>
>
> # if necessary,
> #
> # install.packages("arules")
>
> library(arules)
Loading required package: Matrix
Loading required package: lattice

Attaching package: 'Matrix'


The following object(s) are masked from package:stats :

contr.helmert,
contr.poly,
contr.SAS,
contr.sum,
contr.treatment,
xtabs


The following object(s) are masked from package:base :

rcond


Attaching package: 'arules'


The following object(s) are masked from package:base :

%in%

>
> # a data set that is setup for predicting (income > 50k)
> # but we will ignore that for now
>
> data(Adult)
>
> adult.rules = apriori(Adult, parameter=list(confidence=0.8))

parameter specification:
confidence minval smax arem aval originalSupport support minlen maxlen target
0.8 0.1 1 none FALSE TRUE 0.1 1 5 rules
ext
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 ...[115 item(s), 48842 transaction(s)] done [0.09s].
sorting and recoding items ... [31 item(s)] done [0.02s].
creating transaction tree ... done [0.12s].
checking subsets of size 1 2 3 4 5 done [0.16s].
writing ... [4175 rule(s)] done [0.00s].
creating S4 object ... done [0.04s].
>
> # print out rules sorted by support
>
> inspect(SORT(adult.rules, by='support')[1:10])
lhs rhs support confidence lift
1 {} => {capital-loss=None} 0.9532779 0.9532779 1.0000000
2 {} => {capital-gain=None} 0.9173867 0.9173867 1.0000000
3 {} => {native-country=United-States} 0.8974243 0.8974243 1.0000000
4 {capital-gain=None} => {capital-loss=None} 0.8706646 0.9490705 0.9955863
5 {capital-loss=None} => {capital-gain=None} 0.8706646 0.9133376 0.9955863
6 {} => {race=White} 0.8550428 0.8550428 1.0000000
7 {native-country=United-States} => {capital-loss=None} 0.8548380 0.9525461 0.9992323
8 {capital-loss=None} => {native-country=United-States} 0.8548380 0.8967354 0.9992323
9 {native-country=United-States} => {capital-gain=None} 0.8219565 0.9159062 0.9983862
10 {capital-gain=None} => {native-country=United-States} 0.8219565 0.8959761 0.9983862
>
> # print out rules sorted by confidence
>
> inspect(SORT(adult.rules, by='confidence')[1:10])
lhs rhs support confidence lift
1 {relationship=Husband,
income=large} => {sex=Male} 0.1211662 1 1.495926
2 {relationship=Husband,
hours-per-week=Over-time} => {sex=Male} 0.1472298 1 1.495926
3 {age=Senior,
relationship=Husband} => {sex=Male} 0.1479874 1 1.495926
4 {marital-status=Married-civ-spouse,
relationship=Husband,
income=large} => {sex=Male} 0.1210843 1 1.495926
5 {relationship=Husband,
race=White,
income=large} => {sex=Male} 0.1111339 1 1.495926
6 {relationship=Husband,
native-country=United-States,
income=large} => {sex=Male} 0.1110724 1 1.495926
7 {relationship=Husband,
capital-loss=None,
income=large} => {sex=Male} 0.1086155 1 1.495926
8 {marital-status=Married-civ-spouse,
relationship=Husband,
hours-per-week=Over-time} => {sex=Male} 0.1471275 1 1.495926
9 {relationship=Husband,
race=White,
hours-per-week=Over-time} => {sex=Male} 0.1387126 1 1.495926
10 {relationship=Husband,
hours-per-week=Over-time,
native-country=United-States} => {sex=Male} 0.1366447 1 1.495926
>
> # find rules that force income to be on the RHS
>
> adult.rules = apriori(Adult, appearance=list(rhs=c("income=small", "income=large")), parameter=list(confidence=0.5))

parameter specification:
confidence minval smax arem aval originalSupport support minlen maxlen target
0.5 0.1 1 none FALSE TRUE 0.1 1 5 rules
ext
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 ...[2 item(s)] done [0.00s].
set transactions ...[115 item(s), 48842 transaction(s)] done [0.08s].
sorting and recoding items ... [31 item(s)] done [0.02s].
creating transaction tree ... done [0.12s].
checking subsets of size 1 2 3 4 5 done [0.18s].
writing ... [5401 rule(s)] done [0.00s].
creating S4 object ... done [0.04s].
> inspect(SORT(adult.rules, by='lift')[1:10])
lhs rhs support confidence lift
1 {age=Young,
marital-status=Never-married,
capital-gain=None} => {relationship=Own-child} 0.1014291 0.6181682 3.982663
2 {age=Young,
marital-status=Never-married} => {relationship=Own-child} 0.1038860 0.6165998 3.972559
3 {age=Young,
marital-status=Never-married,
capital-loss=None} => {relationship=Own-child} 0.1015315 0.6164843 3.971815
4 {marital-status=Never-married,
relationship=Own-child,
capital-gain=None} => {age=Young} 0.1014291 0.7541483 3.826125
5 {marital-status=Never-married,
relationship=Own-child,
capital-loss=None} => {age=Young} 0.1015315 0.7517053 3.813731
6 {marital-status=Never-married,
relationship=Own-child} => {age=Young} 0.1038860 0.7517037 3.813723
7 {relationship=Own-child,
capital-gain=None,
capital-loss=None} => {age=Young} 0.1020433 0.6942471 3.522221
8 {relationship=Own-child,
capital-gain=None} => {age=Young} 0.1045412 0.6939386 3.520655
9 {age=Young,
capital-gain=None} => {relationship=Own-child} 0.1045412 0.5462131 3.519079
10 {age=Young,
capital-gain=None,
capital-loss=None} => {relationship=Own-child} 0.1020433 0.5461319 3.518556
>
> # find rules that force income to be on the RHS and everything else on LHS
>
> adult.rules = apriori(Adult, appearance=list(rhs=c("income=small", "income=large"), default='lhs'), parameter=list(confidence=0.5))

parameter specification:
confidence minval smax arem aval originalSupport support minlen maxlen target
0.5 0.1 1 none FALSE TRUE 0.1 1 5 rules
ext
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 ...[2 item(s)] done [0.00s].
set transactions ...[115 item(s), 48842 transaction(s)] done [0.10s].
sorting and recoding items ... [31 item(s)] done [0.02s].
creating transaction tree ... done [0.12s].
checking subsets of size 1 2 3 4 5 done [0.16s].
writing ... [261 rule(s)] done [0.00s].
creating S4 object ... done [0.05s].
> inspect(SORT(adult.rules, by='lift')[1:10])
lhs rhs support confidence lift
1 {age=Young,
workclass=Private,
capital-loss=None} => {income=small} 0.1005282 0.6633342 1.310622
2 {age=Young,
workclass=Private} => {income=small} 0.1025961 0.6630938 1.310147
3 {age=Young,
marital-status=Never-married,
capital-gain=None,
capital-loss=None} => {income=small} 0.1060563 0.6616426 1.307279
4 {age=Young,
marital-status=Never-married,
capital-gain=None} => {income=small} 0.1084517 0.6609683 1.305947
5 {relationship=Own-child,
capital-loss=None} => {income=small} 0.1000983 0.6604972 1.305016
6 {relationship=Own-child} => {income=small} 0.1023914 0.6596755 1.303393
7 {age=Young,
marital-status=Never-married,
capital-loss=None} => {income=small} 0.1086360 0.6596221 1.303287
8 {age=Young,
marital-status=Never-married} => {income=small} 0.1110315 0.6590108 1.302080
9 {age=Young,
capital-gain=None,
capital-loss=None} => {income=small} 0.1229475 0.6580101 1.300102
10 {age=Young,
capital-gain=None} => {income=small} 0.1256910 0.6567180 1.297549
>
>
>

>
> proc.time()
user system elapsed
8.740 0.112 10.011
R script