Created
February 2, 2017 15:42
-
-
Save erickguan/d1134f974d4624c119e9d32af21ba83a to your computer and use it in GitHub Desktop.
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
library("class") | |
iris <- read.csv("/Users/fantasticfears/Downloads/iris.csv", header=FALSE) | |
irisShuffled <- iris[sample(nrow(iris)),] | |
irisShuffledRaw <- irisShuffled[,1:4] | |
train <- irisShuffledRaw[1:100,] | |
test <- irisShuffledRaw[101:nrow(iris),] | |
cl <- factor(as.array(irisShuffled[1:100,5])) | |
predicted <- knn(train, test, cl, prob=TRUE) | |
trueTarget <- irisShuffled[101:150,5] | |
table(predicted == trueTarget) | |
table(predicted, trueTarget) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment