fcaR

Mushroom

library(arules)
library(fcaR)


data("Mushroom", package = "arules")
Mushroom
## transactions in sparse format with
##  8124 transactions (rows) and
##  114 items (columns)
mushroom_rules <- apriori(Mushroom, parameter = list(conf = 1))
## Apriori
## 
## Parameter specification:
##  confidence minval smax arem  aval originalSupport maxtime support minlen
##           1    0.1    1 none FALSE            TRUE       5     0.1      1
##  maxlen target   ext
##      10  rules FALSE
## 
## Algorithmic control:
##  filter tree heap memopt load sort verbose
##     0.1 TRUE TRUE  FALSE TRUE    2    TRUE
## 
## Absolute minimum support count: 812 
## 
## set item appearances ...[0 item(s)] done [0.00s].
## set transactions ...[114 item(s), 8124 transaction(s)] done [0.01s].
## sorting and recoding items ... [53 item(s)] done [0.00s].
## creating transaction tree ... done [0.00s].
## checking subsets of size 1 2 3 4 5 6 7 8 9 10 done [2.93s].
## writing ... [1799427 rule(s)] done [0.48s].
## creating S4 object  ... done [1.26s].

Planet

#https://cran.r-project.org/web/packages/fcaR/vignettes/concept_lattice.html
planets
##         small medium large near far moon no_moon
## Mercury     1      0     0    1   0    0       1
## Venus       1      0     0    1   0    0       1
## Earth       1      0     0    1   0    1       0
## Mars        1      0     0    1   0    1       0
## Jupiter     0      0     1    0   1    1       0
## Saturn      0      0     1    0   1    1       0
## Uranus      0      1     0    0   1    1       0
## Neptune     0      1     0    0   1    1       0
## Pluto       1      0     0    0   1    1       0
fc_planets <- FormalContext$new(planets)
fc_planets$to_transactions()
## transactions in sparse format with
##  9 transactions (rows) and
##  7 items (columns)
fc_planets$find_implications()
fc_planets$implications$to_arules(quality = TRUE)
## set of 10 rules
fc_planets$concepts
## A set of 12 concepts:
## 1: ({Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto}, {})
## 2: ({Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto}, {moon})
## 3: ({Jupiter, Saturn, Uranus, Neptune, Pluto}, {far, moon})
## 4: ({Jupiter, Saturn}, {large, far, moon})
## 5: ({Uranus, Neptune}, {medium, far, moon})
## 6: ({Mercury, Venus, Earth, Mars, Pluto}, {small})
## 7: ({Earth, Mars, Pluto}, {small, moon})
## 8: ({Pluto}, {small, far, moon})
## 9: ({Mercury, Venus, Earth, Mars}, {small, near})
## 10: ({Mercury, Venus}, {small, near, no_moon})
## 11: ({Earth, Mars}, {small, near, moon})
## 12: ({}, {small, medium, large, near, far, moon, no_moon})
fc_planets$implications
## Implication set with 10 implications.
## Rule 1: {no_moon} -> {small, near}
## Rule 2: {far} -> {moon}
## Rule 3: {near} -> {small}
## Rule 4: {large} -> {far, moon}
## Rule 5: {medium} -> {far, moon}
## Rule 6: {medium, large, far, moon} -> {small, near, no_moon}
## Rule 7: {small, near, moon, no_moon} -> {medium, large, far}
## Rule 8: {small, near, far, moon} -> {medium, large, no_moon}
## Rule 9: {small, large, far, moon} -> {medium, near, no_moon}
## Rule 10: {small, medium, far, moon} -> {large, near, no_moon}
fc_planets$concepts$plot()

fc_planets <- FormalContext$new(planets)
print(fc_planets)
## Warning: Too many attributes, output will be truncated.
## FormalContext with 9 objects and 7 attributes.
## Attributes' names are: small, medium, large, near, far, moon, ...
## Matrix:
##         small medium large near far moon no_moon
## Mercury     1      0     0    1   0    0       1
## Venus       1      0     0    1   0    0       1
## Earth       1      0     0    1   0    1       0
## Mars        1      0     0    1   0    1       0
## Jupiter     0      0     1    0   1    1       0
## Saturn      0      0     1    0   1    1       0
fc_planets$plot()