mushrooms.csv
1.17MB

 

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 규칙기반 알고리즘을 이용하여 식용버섯과 독버섯 분류하기 (oneR)
mushroom <- read.csv('c:/data/mushrooms.csv',header=T,stringsAsFactors = T)
train_cnt <- round( 0.75 * dim(mushroom)[1]) # 6093
 
# shuffle
set.seed(11)
train_index <- sample(1:dim(mushroom)[1], train_cnt, replace=F)
 
# train (75%) / test (25%)
mushroom_train <- mushroom[train_index,  ]
mushroom_test  <- mushroom[-train_index, ]
 
# oneR로 모델 생성
install.packages("OneR")
library(OneR)
 
model1 <- OneR(type~. ,  data=mushroom_train)
model1
summary(model1)
 
# 예측
result1 <- predict( model1, mushroom_test[   , -1] )
 
# 정확도
library(gmodels)
= CrossTable( mushroom_test[ , 1],  result1)
x$prop.tbl[1]+x$prop.tbl[4# 0.9862137
 
 
##########################################################
# 규칙기반 알고리즘을 이용하여 식용버섯과 독버섯 분류하기 (JRip)
# JRip로 모델 생성
install.packages("RWeka")
library(RWeka)
 
model2 <- JRip(type~ ., data=mushroom_train)
model2
 
summary(model2) # 작은 이원교차표가 하나 보임
 
# 예측
result2 <- predict( model2, mushroom_test[   , -1] )
 
# 정확도
library(gmodels)
<- CrossTable( mushroom_test[ , 1],  result2)  
x$prop.tbl[1]+x$prop.tbl[4# 1
 
cs

+ Recent posts