Skip to content

Instantly share code, notes, and snippets.

@HackerEarthBlog
Last active May 17, 2020 10:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HackerEarthBlog/98dca27a7e48694506db6ae413d7570e to your computer and use it in GitHub Desktop.
Save HackerEarthBlog/98dca27a7e48694506db6ae413d7570e to your computer and use it in GitHub Desktop.
Apriori Algorithm in R
> library(arules)
> data("Adult")
> rules <- apriori(Adult,parameter = list(supp = 0.5, conf = 0.9, target = "rules"))
> summary(rules)
#set of 52 rules
#rule length distribution (lhs + rhs):sizes
# 1 2 3 4
# 2 13 24 13
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 1.000 2.000 3.000 2.923 3.250 4.000
# summary of quality measures:
# support confidence lift
# Min. :0.5084 Min. :0.9031 Min. :0.9844
# 1st Qu.:0.5415 1st Qu.:0.9155 1st Qu.:0.9937
# Median :0.5974 Median :0.9229 Median :0.9997
# Mean :0.6436 Mean :0.9308 Mean :1.0036
# 3rd Qu.:0.7426 3rd Qu.:0.9494 3rd Qu.:1.0057
# Max. :0.9533 Max. :0.9583 Max. :1.0586
# mining info:
# data ntransactions support confidence
# Adult 48842 0.5 0.9
> inspect(rules) #It gives the list of all significant association rules. Some of them are shown below
# lhs rhs support confidence lift
# [1] {} => {capital-gain=None} 0.9173867 0.9173867 1.0000000
# [2] {} => {capital-loss=None} 0.9532779 0.9532779 1.0000000
# [3] {hours-per-week=Full-time} => {capital-gain=None} 0.5435895 0.9290688 1.0127342
# [4] {hours-per-week=Full-time} => {capital-loss=None} 0.5606650 0.9582531 1.0052191
# [5] {sex=Male} => {capital-gain=None} 0.6050735 0.9051455 0.9866565
# [6] {sex=Male} => {capital-loss=None} 0.6331027 0.9470750 0.9934931
# [7] {workclass=Private} => {capital-gain=None} 0.6413742 0.9239073 1.0071078
# [8] {workclass=Private} => {capital-loss=None} 0.6639982 0.9564974 1.0033773
# [9] {race=White} => {native-country=United-States} 0.7881127 0.9217231 1.0270761
# [10] {race=White} => {capital-gain=None} 0.7817862 0.9143240 0.9966616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment