공유자료 HOME > 자료실 > 공유자료
 
[정보기술활용연구] 연관분석 R 코드
관리자 16-05-17 09:41 614
install.packages("arules")
library(arules)
#Breast Cancer Winconsin dataset:
Dane = read.table("http://www.ipipan.eu/~teisseyrep/TEACHING/DM/DANE/breast-cancer-wisconsin.data",h=T,sep=",")
Dane = Dane[,-1]
#Discretization is necessary:
for(j in 1:ncol(Dane)) Dane[,j] =as.factor(Dane[,j])
# as()는 임의의 클라스로 변경하려고 할 때 사용하는 것
Dane1 = as(Dane,"transactions")
# Vizualize data (do not run for large tables!)
image(Dane1)
#Itemsets:
itemFrequencyPlot(Dane1)
#Itemsets with support >=0.1
itemFrequencyPlot(Dane1, support = 0.1, cex.names = 0.8)
#Association rules:
rules <- apriori(Dane1, parameter = list(support = 0.01, confidence = 0.6))
summary(rules)
#Rules with specified rhs.
rulesClassmalignant <- subset(rules, subset = rhs %in% "Class=malignant" & lift > 1.2)
 
#Sort the results:
inspect(head(sort(rulesClassmalignant, by = "confidence"), n = 3))