TEST 11
V dnešním cvičení využijeme datový soubor weather.csv. Pro hledání asociačních pravidel v R budeme potřebovat balíček arules.
Příklad: Hráči chodí hrát tenis, ale hrají pouze za příznivého počasí. Příklady jejich rozhodnutí jsou v následující tabulce. Atributy jsou outlook, temperature, humidity, windy a rozhodnutí je ve sloupečku play.
| outlook | temperature | humidity | windy | play |
|---|---|---|---|---|
| sunny | hot | high | false | no |
| sunny | hot | high | true | no |
| overcast | hot | high | false | yes |
| rainy | mild | high | false | yes |
| rainy | cool | normal | false | yes |
| rainy | cool | normal | true | no |
| overcast | cool | normal | true | yes |
| sunny | mild | high | false | no |
| sunny | cool | normal | false | yes |
| rainy | mild | normal | false | yes |
| sunny | mild | normal | true | yes |
| overcast | mild | high | true | yes |
| overcast | hot | normal | false | yes |
| rainy | mild | high | true | no |
sets <- apriori(weather,
parameter = list(minlen=1, supp = 0.4, target = "frequent itemsets"))
summary(sets)
inspect(sets)
rules <- apriori(weather,
parameter = list(minlen=2, supp = 0.1, conf = 0.5, target = "rules"),
appearance = list(rhs=c("play=no", "play=yes"), default="lhs"))
summary(rules)
inspect(rules[1:10])
Pro vizualizaci pravidel budeme potřebovat balíčky vcd, arulesViz
Vizualizace nalezených pravidel:
rules <- apriori(weather,
parameter = list(minlen=2, supp = 0.2, conf = 0, target = "rules"),
appearance = list(rhs=c("play=no", "play=yes"), default="lhs")
)
plot(rules, interactive=TRUE)
plot(rules, method="grouped")
plot(rules, method="graph")
plot(rules, method="paracoord")
Vizualizace krátkých pravidel pomocí metody Mosaic Plot (mosaic nebo mosaicplot)
mosaicplot(~ play, data=weather, main = "Tennis", shade = FALSE, legend = FALSE) mosaicplot(~ outlook + play, data=weather, main = "Tennis", shade = FALSE, legend = FALSE) mosaicplot(~ play+humidity, data=weather, main = "Tennis", shade = FALSE, legend = FALSE) mosaicplot(~ outlook + humidity + play, data=weather, main = "Tennis", shade = FALSE, legend = FALSE)
Vhodná data pro další pokusy s pravidly: mushroom
Najděte pravidla, kdy jsou houby jedlé a určitě se neotrávíte.
Více informací na UCI repository mushroom