"NearestNeighbors" (Machine Learning Method)

Details & Suboptions

  • Nearest neighbors is a type of instance-based learning. In its simplest form, it picks the commonest class or averages the values among the k nearest neighbors.
  • The following options can be given:
  • "NeighborsNumber" Automaticthe number of neighbors to consider (k)
    "DistributionSmoothing" 0.5regularization parameter
    "NearestMethod" Automaticthe method to use for computing the k-nearest examples
  • Possible settings for "NearestMethod" include:
  • "KDtree"uses a kd tree data structure for storing the data
    "Octree"uses an octree data structure for storing the data
    "Scan"exaustive search on the entire dataset

Examples

open allclose all

Basic Examples  (2)

Train a classifier function on labeled examples:

Obtain information about the classifier:

Classify a new example:

Generate some data and visualize it:

Train a predictor function on it:

Compare the data with the predicted values and look at the standard deviation:

Options  (6)

"DistributionSmoothing"  (2)

Train a classifier using the "DistributionSmoothing" suboption:

Train two classifiers on an imbalanced dataset by varying the value of "DistributionSmoothing":

Look at the probabilities for the two classifiers:

"NearestMethod"  (2)

Train a classifier using a specific "NearestMethod":

Generate a large dataset and visualize it:

Train several classifiers using the different methods and compare their training times:

Compare the corresponding training times:

"NeighborsNumber"  (2)

Train a predictor function using a specific "NeighborsNumber":

Generate a labeled training set and visualize it:

Train a predictor using a small "NeighborsNumber":

Train a predictor using a large "NeighborsNumber":

Compare the two predictors: