{{indexmenu_n>13}}
Obsah této stránky bude přístupný od 4. 1. 2018.
====== Cvičení 9 - Asociační pravidla ======
Test: https://goo.gl/mi1W4V
V dnešním cvičení využijeme datový soubor {{courses:a6m33dvz:cviceni:weather.csv|weather.csv}}. Pro hledání asociačních pravidel v R budeme potřebovat balíček **arules**.
==== Hledání častých položek ====
* Co je to podpora (support) množiny položek?
* Co je množina častých položek a jak je definována?
* Jak byste definovali "apriori vlastnost podmnožin"?
* Vysvětlete, jak funguje apriori algoritmus.
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 |
==Úkoly==
- Nalezněte pomocí apriori algoritmu časté skupiny položek (target = "frequent itemsets") s podporou větší než 0.22. Kolik takových skupin je?
- Zvolte několik hodnot parametru //"supp"// a zjistěte, kolik množin častých položek s danou podporou najdete.
sets <- apriori(weather,
parameter = list(minlen=1, supp = 0.4, target = "frequent itemsets"))
summary(sets)
inspect(sets)
==== Asociační pravidla ====
* Co je čtyřpolní tabulka?
* Jak je definována spolehlivost (confidence)?
* Popište proces generování asociačních pravidel.
==Úkoly==
- Nalezněte asociační pravidla s podporou //supp//>0.22 a se spolehlivostí //conf=1//.
- Zkuste najít asociační pravidla i pro jiná nastavení spolehlivosti (confidence).
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])
==== Vizualizace pravidel ====
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: {{courses:a6m33dvz:cviceni:mushroom.csv.txt|mushroom}}**
Najděte pravidla, kdy jsou houby jedlé a **určitě** se neotrávíte.
Více informací na [[https://archive.ics.uci.edu/ml/datasets
/Mushroom|UCI repository mushroom]]