Skip to content

Instantly share code, notes, and snippets.

@yumaueno
Created January 16, 2018 05:59
Show Gist options
  • Save yumaueno/f81346e28b915f9444d45a6bf93bbb27 to your computer and use it in GitHub Desktop.
Save yumaueno/f81346e28b915f9444d45a6bf93bbb27 to your computer and use it in GitHub Desktop.
iris
library(randomForest)
library(rpart)
library(kernlab)
library(nnet)
data<-iris
ndata<-nrow(data)
ridx<-sample(ndata,ndata*0.5)
data.learn<-data[ridx,]
data.test<-data[-ridx,]
#randomforest
forest<-randomForest(Species~.,data=data.learn)
pred.forest<-predict(forest,newdata=data.test,type="class")
table(pred.forest,data.test[,5])
#決定木
cart<-rpart(Species~.,data=data.learn)
pred.cart<-predict(cart,newdata=data.test,type="class")
table(pred.cart,data.test[,5])
#svm
svm<-ksvm(Species~.,data=data.learn)
pred.svm<-predict(svm,newdata=data.test)
table(pred.svm,data.test[,5])
#nn
nn<-nnet(Species~.,data=data.learn,size=10)
pred.nn<-predict(nn,newdata=data.test,type="class")
table(pred.nn,data.test[,5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment