Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. Here is the code.
  2.  
  3. # Clearing variables 
  4. rm(list = ls())
  5.  
  6. library(arules)
  7. library(arulesViz)
  8.  
  9. # set the working directory
  10. setwd("/Users/mhasan1/Desktop")
  11.  
  12. #read/import csv file into R
  13. trans_mat<-read.csv("Superstore",header=TRUE,sep=",")
  14.  
  15. #convert it into a data matrix
  16. a_matrix<-data.matrix(trans_mat)
  17.  
  18. #remove the transaction_ID column i.e., column 1
  19. a_matrix<-a_matrix[,-1]
  20.  
  21. #use logical function to convert binary to T/F
  22. basket2<-apply(a_matrix,2,as.logical)
  23.  
  24. #Now coerce it into a matrix
  25. basket<-as(as.matrix(basket2),"transactions")
  26.  
  27. # Using mine association rules - Apriori Algorithm 
  28. rules <- apriori(basket, parameter = list(support=0.03, confidence=0.8))
  29.  
  30. rules1<- apriori(basket, parameter = list(support=0.04, confidence=0.8))
  31.  
  32. inspect(head(rules, n=3 , by ="lift"))
  33.  
  34. inspect(head(rules1, n=3 , by ="lift"))
  35.  
  36. plot(rules)
  37.  
  38. #parallel Cordinates plot 
  39. plot(rules, method = "paracoord")
  40.  
  41. plot(rules, method = "paracoord", control = list(reorder = TRUE))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement