Documentation |
ClassificationKNN.fit will be removed in a future release. Use fitcknn instead.
mdl = ClassificationKNN.fit(X,y)
mdl = ClassificationKNN.fit(X,y,Name,Value)
mdl = ClassificationKNN.fit(X,y) returns a classification model based on the input variables (also known as predictors, features, or attributes) X and output (response) y.
mdl = ClassificationKNN.fit(X,y,Name,Value) fits a model with additional options specified by one or more Name,Value pair arguments.
If you use one of these options, mdl is of class ClassificationPartitionedModel: 'CrossVal', 'KFold', 'Holdout', 'Leaveout', or 'CVPartition'. Otherwise, mdl is of class ClassificationKNN.
ClassificationKNN predicts the classification of a point Xnew using a procedure equivalent to this:
Find the NumNeighbors points in the training set X that are nearest to Xnew.
Find the NumNeighbors response values Y to those nearest points.
Assign the classification label Ynew that has the largest posterior probability among the values in Y.
For details, see Posterior Probability in the predict documentation.