Practical Machine Learning with R and Python: Machine Learning in Stereo by Tinniam V Ganesh

Practical Machine Learning with R and Python: Machine Learning in Stereo by Tinniam V Ganesh

Author:Tinniam V Ganesh [Ganesh, Tinniam V]
Language: eng
Format: azw3, pdf
Published: 2017-12-01T05:00:00+00:00


# Fit a model for 1,3,5,10 and 15 neighbors

cMat <- NULL

neighbors <-c(1,3,5,10,15)

for(i in seq_along(neighbors)){

fit =knn(train.X,test.X,train.y,k=i)

table(fit,test.y)

a<-confusionMatrix(fit,test.y)

cMat[i] <- a$overall[1]

print(a$overall[1])

}

## Accuracy

## 0.7835831

## Accuracy

## 0.8162047

## Accuracy

## 0.8089113

## Accuracy

## 0.8209787

## Accuracy

## 0.8184591

#Plot the Accuracy for each of the KNN models

df <- data.frame(neighbors,Accuracy=cMat)

ggplot(df,aes(x=neighbors,y=Accuracy)) + geom_point() +geom_line(color="blue") +

xlab("Number of neighbors") + ylab("Accuracy") +

ggtitle("KNN regression - Accuracy vs Number of Neighors (Unnormalized)")



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.