mushrooms <- read.csv("/cloud/project/Data/mushrooms.csv")
names(mushrooms)[1]<- paste("type")
mushrooms$type <- factor(mushrooms$type, levels = c("e","p"), labels = c("edible", "poisonous"))
mushrooms$odor <- factor(mushrooms$odor, levels = c("a","l","c", "y","f","m","n","p","s"), labels = c("almond","anise","creosote","fishy","foul","musty","none","pungent","spicy"))
note: variable in DF mush be a factor to analysis
mushrooms[sapply(mushrooms, is.character)] <- lapply(mushrooms[sapply(mushrooms, is.character)], as.factor)
install package
#install.packages("RWeka")
install.packages("dplyr")
## Installing package into '/home/rstudio-user/R/x86_64-pc-linux-gnu-library/4.0'
## (as 'lib' is unspecified)
library("RWeka")
library("dplyr")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
#view(mushrooms)
#str(mushrooms)
mushrooms$veil.type <- NULL
mushroom_1R <- OneR(formula = type ~., data = mushrooms)
mushroom_1R
## odor:
## almond -> edible
## anise -> edible
## creosote -> poisonous
## fishy -> poisonous
## foul -> poisonous
## musty -> poisonous
## none -> edible
## pungent -> poisonous
## spicy -> poisonous
## (8004/8124 instances correct)
summary(mushroom_1R)
##
## === Summary ===
##
## Correctly Classified Instances 8004 98.5229 %
## Incorrectly Classified Instances 120 1.4771 %
## Kappa statistic 0.9704
## Mean absolute error 0.0148
## Root mean squared error 0.1215
## Relative absolute error 2.958 %
## Root relative squared error 24.323 %
## Total Number of Instances 8124
##
## === Confusion Matrix ===
##
## a b <-- classified as
## 4208 0 | a = edible
## 120 3796 | b = poisonous
mushroom_JRip <- JRip(formula = type~., data = mushrooms)
mushroom_JRip
## JRIP rules:
## ===========
##
## (odor = foul) => type=poisonous (2160.0/0.0)
## (gill.size = n) and (gill.color = b) => type=poisonous (1152.0/0.0)
## (gill.size = n) and (odor = pungent) => type=poisonous (256.0/0.0)
## (odor = creosote) => type=poisonous (192.0/0.0)
## (spore.print.color = r) => type=poisonous (72.0/0.0)
## (stalk.surface.below.ring = y) and (stalk.surface.above.ring = k) => type=poisonous (68.0/0.0)
## (habitat = l) and (cap.surface = y) and (population = c) => type=poisonous (12.0/0.0)
## (cap.surface = g) => type=poisonous (4.0/0.0)
## => type=edible (4208.0/0.0)
##
## Number of Rules : 9
summary(mushroom_JRip)
##
## === Summary ===
##
## Correctly Classified Instances 8124 100 %
## Incorrectly Classified Instances 0 0 %
## Kappa statistic 1
## Mean absolute error 0
## Root mean squared error 0
## Relative absolute error 0 %
## Root relative squared error 0 %
## Total Number of Instances 8124
##
## === Confusion Matrix ===
##
## a b <-- classified as
## 4208 0 | a = edible
## 0 3916 | b = poisonous