Hi John,
You can use WRITE (see ? WRITE) to save rules to a file in the
from:
{a,b,c} => {d} 0.1 0.3 2.2
where the numbers after the rule are support, confidence and lift.
There is no csv export since the number of items in the rules varies and
the data structure can not be converted into a simple table.
Alternatively you can export the rules using PMML (XML) and use a XML
parser to get the rules.
Best,
Michael
On 01/-10/-28163 01:59 PM, johnistan wrote:
I am new to R( but quickly being awed by the range of this it can accomplish,
you have one more convert to the useR universe). I have successfully
implemented the apriori function and are getting great results. My question
concerns how to export these results. I have read lots about write.csv
functions and exporting data frames and other standard objects. Im having
difficulty working with these S4 objects. My object looks as follows.
str(rules)
Formal class 'rules' [package "arules"] with 4 slots
..@ lhs :Formal class 'itemMatrix' [package "arules"] with 3 slots
.. .. ..@ data :Formal class 'ngCMatrix' [package "Matrix"] with 5
slots
.. .. .. .. ..@ i : int [1:2133] 3907 3519 4172 3519 4182 3519 4172
4182 4172 4182 ...
.. .. .. .. ..@ p : int [1:790] 0 0 1 2 3 4 5 6 7 8 ...
.. .. .. .. ..@ Dim : int [1:2] 7002 789
.. .. .. .. ..@ Dimnames:List of 2
.. .. .. .. .. ..$ : NULL
.. .. .. .. .. ..$ : NULL
.. .. .. .. ..@ factors : list()
.. .. ..@ itemInfo :'data.frame': 7002 obs. of 1 variable:
.. .. .. ..$ labels:Class 'AsIs' chr [1:7002] "0171T_722.52"
"0171T_724.02" "0172T_724.02" "0197T_185" ...
.. .. ..@ itemsetInfo:'data.frame': 0 obs. of 0 variables
..@ rhs :Formal class 'itemMatrix' [package "arules"] with 3 slots
.. .. ..@ data :Formal class 'ngCMatrix' [package "Matrix"] with 5
slots
.. .. .. .. ..@ i : int [1:789] 4120 3704 4172 3519 4182 3519 4120
4182 4172 4120 ...
.. .. .. .. ..@ p : int [1:790] 0 1 2 3 4 5 6 7 8 9 ...
.. .. .. .. ..@ Dim : int [1:2] 7002 789
.. .. .. .. ..@ Dimnames:List of 2
.. .. .. .. .. ..$ : NULL
.. .. .. .. .. ..$ : NULL
.. .. .. .. ..@ factors : list()
.. .. ..@ itemInfo :'data.frame': 7002 obs. of 1 variable:
.. .. .. ..$ labels:Class 'AsIs' chr [1:7002] "0171T_722.52"
"0171T_724.02" "0172T_724.02" "0197T_185" ...
.. .. ..@ itemsetInfo:'data.frame': 0 obs. of 0 variables
..@ quality:'data.frame': 789 obs. of 3 variables:
.. ..$ support : num [1:789] 0.8258 0.0103 0.0102 0.0102 0.0102 ...
.. ..$ confidence: num [1:789] 0.826 1 0.987 0.925 0.987 ...
.. ..$ lift : num [1:789] 1 50.8 89.6 89.6 89.6 ...
..@ info :List of 4
.. ..$ data : symbol lij_trans
.. ..$ ntransactions: int 7266
.. ..$ support : num 0.01
.. ..$ confidence : num 0.7
and sample inspect statement:
95 {93510_411.1,
93556_411.1} => {93010_414.9} 0.01279934 1.0000000 1.21100
96 {93010_414.9,
93510_411.1} => {93556_411.1} 0.01279934 0.9687500 69.00919
97 {93010_414.9,
93556_411.1} => {93510_411.1} 0.01279934 0.9117647 69.00919
98 {93543_413.9,
93555_413.9} => {93556_413.9} 0.01541426 1.0000000 60.55000
99 {93543_413.9,
93556_413.9} => {93555_413.9} 0.01541426 1.0000000 64.87500
100 {93555_413.9,
93556_413.9} => {93543_413.9} 0.01541426 1.0000000 64.87500
101 {93543_413.9,
93555_413.9} => {93545_413.9} 0.01541426 1.0000000 60.04959
What is am most interested in is exporting to a csv or some form of table.
Where the 1,2 or n transactions on the left are listed in c(1,2,...n) and
the dependent data point is in c(4 or n+1)(I have limited the max number to
three) and the support/conf/lift is the next tree columns.
something like:
93543_413.9 | 93555_413.9 | 93545_413.9 | 0.01541426 | 1.0000000 |
60.04959
I have searched around but haven't found anything. Can someone help or
supply some more promising search terms to direct my dive into
documentation.
Thanks,
John
--
Michael Hahsler
email: mich...@hahsler.net
web: http://michael.hahsler.net
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.