Skip to content

Nearest Neighbor

Predicts each case’s target from the k most similar training cases: the majority category for a categorical target, or the average for a scale target.

  • When the relationship between predictors and outcome is irregular and hard to describe with a formula.
  • For classification or prediction where you mainly care about accuracy on new cases.
  • With a moderate number of predictors. Many irrelevant predictors make every case look alike; use automatic feature selection.
  • Similar predictor values mean similar outcomes. Distances need comparable scales, so keep covariate normalization on.
  • Enough training cases in every region of the predictor space. Rare categories are hard to predict.
  • The holdout sample is representative. Set a random seed (SET SEED) for reproducible partitions.
  • Case Processing Summary shows the training and holdout split.
  • K Selection Error Log gives the cross-validated error for each k. The chosen k has the smallest error.
  • Classification Table or Error Summary: judge the model on the holdout figures. Training figures leave each case out of its own neighbourhood.
  • Predictor Importance shows how much the error rises when each predictor is removed.

A k-nearest-neighbour classifier (k = 5 chosen by 10-fold cross-validation; Euclidean distance on normalized predictors) classified 92.4% of the 30% holdout sample correctly.

Syntax: KNN churn BY plan WITH tenure spend /PARTITION TRAINING=70 HOLDOUT=30 /MODEL NEIGHBORS=AUTO(KMIN=3, KMAX=9) /SAVE PREDVAL.


This page comes from OrcStat’s built-in help (the same text as in the app’s Help panel). To suggest a change, open an issue.