Last active
March 6, 2017 01:38
-
-
Save ac00std/928bc57b2091e157f02a3f69fe513d15 to your computer and use it in GitHub Desktop.
leaf.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#データの読み込み | |
#事前にデータの二行目(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