Create a gist now

Instantly share code, notes, and snippets.

@ac00std /leaf.R
Last active Mar 6, 2017

leaf.R
#データの読み込み
#事前にデータの二行目(id)を削除しておいた
leaf=read.csv("leaf_mod.csv")
#散布図を描く
y=leaf$Class
x=leaf[,-1]
pairs(x,main="leaf",pch = 21, bg=y+2)
plot(x[1:7],pch=21,bg=y+2)
plot(x[8:14],pch=21,bg=y+2)
#kNN
library(class)
p3=knn(x,x,y,k=3)
kNN.tab=table(y,p3)
kNN.tab
#識別率
sum(kNN.tab[row(kNN.tab)==col(kNN.tab)])/sum(kNN.tab)
p10=knn(x,x,y,k=10)
kNN.tab=table(y,p10)
kNN.tab
#識別率
sum(kNN.tab[row(kNN.tab)==col(kNN.tab)])/sum(kNN.tab)
#線形判別分析
library(MASS)
leaf_lda=lda(x,y)
p1=predict(leaf_lda)$class
lda.tab=table(y,p1)
lda.tab
#識別率
sum(lda.tab[row(lda.tab)==col(lda.tab)])/sum(lda.tab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment