Icon

6.1 Practical Machine Learning with R Tuning k-Nearest Neighbors (Wine Data)

This workflow shows how to tune a k-Nearest Neighbors model to find the "best" value for the parameter k. The workflow uses cross-validation to asses different hyper parameter values.



URL: Practical Machine Learning with R https://ai.lange-analytics.com
URL: Open the related R analysis in RStudio https://ai.lange-analytics.com/exc/?file=06-TrainTestExerc100.Rmd
URL: Contact the author https://ai.lange-analytics.com/EmailForw.html

Finding the Best k Using the Best k (k=1) cross validation:collect resultscross validation:partition dataFolds=5Node 21Shows best k (k=1)Reading Training DataExecutek-Nearest Neighbors for all folds and for all hyper-parametersNode 27Node 29Reading Testing DataUses k-Nearest Neighbor with k=1 (manually entered)Node 32Node 33 X-Aggregator X-Partitioner Parameter OptimizationLoop Start ParameterOptimization Loop End File Reader K Nearest Neighbor Scorer Scorer File Reader K Nearest Neighbor Normalizer Normalizer Finding the Best k Using the Best k (k=1) cross validation:collect resultscross validation:partition dataFolds=5Node 21Shows best k (k=1)Reading Training DataExecutek-Nearest Neighbors for all folds and for all hyper-parametersNode 27Node 29Reading Testing DataUses k-Nearest Neighbor with k=1 (manually entered)Node 32Node 33 X-Aggregator X-Partitioner Parameter OptimizationLoop Start ParameterOptimization Loop End File Reader K Nearest Neighbor Scorer Scorer File Reader K Nearest Neighbor Normalizer Normalizer

Nodes

Extensions

Links