KNN
Nearest-neighbour classification or prediction with a holdout sample, automatic choice of k and feature selection.
Syntax
Section titled “Syntax”KNN target BY factors WITH covariates [/RESCALE COVARIATE=ADJNORMALIZED|NONE] [/PARTITION TRAINING=70 HOLDOUT=30 | VARIABLE=var] [/MODEL METRIC=EUCLID|CITYBLOCK NEIGHBORS=FIXED(K=3)|AUTO(KMIN=3, KMAX=5) FEATURES=ALL|AUTO] [/CRITERIA NUMFEATURES=AUTO|FIXED(n) MINCHANGE(0.01)] [/CROSSVALIDATION FOLDS=10] [/PRINT CPS NONE] [/SAVE PREDVAL PREDPROB PARTITION].Synopsis
Section titled “Synopsis”| Kind | Procedure (reads data, produces output) |
| Body | main /SUBCOMMAND[=] … |
| Changes data | yes, undoable |
| Subcommands | /CASELABELS, /CRITERIA, /CROSSVALIDATION, /EXCEPT, /FOCALCASES, /MISSING, /MODEL, /OUTFILE, /PARTITION, /PRINT, /RESCALE, /SAVE, /VIEWMODEL |
| Menu | Analyze ▸ Classify |
| Slot: Target | 1–1 variable(s); levels: nominal, ordinal, scale; types: numeric, string |
| Slot: Factors | 0+ variable(s); levels: nominal, ordinal; types: numeric, string |
| Slot: Covariates | 0+ variable(s); levels: scale; types: numeric |
Examples
Section titled “Examples”KNN churn BY plan WITH tenure spend /PARTITION TRAINING=70 HOLDOUT=30 /MODEL NEIGHBORS=AUTO(KMIN=3, KMAX=9) /SAVE PREDVAL.- A nominal or ordinal target is classified by majority vote; a scale target is predicted by the neighbours’ mean.
- Random partitions and folds follow SET SEED, so results are reproducible. Case weights are ignored.
- /MODEL WEIGHTFEATURES=YES weights features by their importance. /FOCALCASES VARIABLE=var lists each focal case’s neighbours and draws a peers chart.
Related
Section titled “Related”DISCRIMINANT, LOGISTIC REGRESSION
Generated from OrcStat’s command registry and reference. To suggest a change, open an issue.