fitrknn
Fit a k-nearest-neighbor regression model.
📝Syntax
mdl = fitrknn(X, Y)
mdl = fitrknn(X, Y, Name, Value)
yfit = predict(mdl, Xnew)
[yfit, D] = predict(mdl, Xnew)
📄Description

fitrknn creates a RegressionKNN object from numeric predictors X and numeric response Y.

Name-value arguments include NumNeighbors, Distance, DistanceWeight, Standardize, P, Scale, PredictorNames, and ResponseName. Prediction returns weighted neighbor response averages.

💡Examples
X = [0 0; 0 1; 1 0; 5 5; 5 6; 6 5];
Y = [1; 1.2; 1.1; 10; 10.2; 10.1];
mdl = fitrknn(X, Y, 'NumNeighbors', 3);
yfit = predict(mdl, [0.2 0.1; 5.2 5.1])
🔗See Also
fitcknnfitrtreeknnsearch
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub