Search
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.
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