Advertisement
friedmusic

A20

Apr 9th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.16 KB | None | 0 0
  1. ---
  2. title: "A20 by Noah Perry & Andrew Hall"
  3. output: html_notebook
  4. ---
  5.  
  6. Use Association Rules to do a market basket analysis for Superstore Sales. As a result of your analysis, what advice would you give to Superstore Sales?
  7.  
  8. ```{r}
  9. library(readxl)
  10. library(arules)
  11. library(arulesViz)
  12.  
  13. url <- "https://community.tableau.com/servlet/JiveServlet/downloadBody/1236-102-2-15278/Sample%20-%20Superstore.xls"
  14. destfile <- "Sample_20_20Superstore.xls"
  15. curl::curl_download(url, destfile)
  16. ss <- read_excel(destfile)
  17.  
  18. #ss <- as (ss, "transactions") # convert to 'transactions' class
  19. write.csv(ss,'superstore.csv')
  20.  
  21. #convert to transactions file
  22. models <- read.transactions(file = "superstore.csv",
  23.  sep=",", format = 'single', cols = c(1,19))
  24. summary(models)
  25. size(head(models))
  26. LIST(head(models))
  27.  
  28. #Identify Frequent Item Sets
  29. frequentItems <- eclat (models, parameter = list(supp = 0.08, maxlen = 5))
  30. inspect(frequentItems)
  31. itemFrequencyPlot(models, topN=10, type="absolute", main="Item Frequency")
  32.  
  33. #Identify Rules
  34. rules <- apriori (models, parameter = list(supp = 0.06, conf = .7, maxlen = 3))
  35. rules_conf <- sort (rules, by="confidence", decreasing=TRUE)
  36. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement