battelle.knn.KNearestNeighborsClassifier

class battelle.knn.KNearestNeighborsClassifier(n_neighbors=5, tiebreaker='nearest', weights='uniform', p=2, metric='minkowski')

Instance of a k-Nearest Neighbors Classifier.

Parameters
  • n_neighbors (int, default=5) – Number of neighbors to use for kneighbors queries.

  • tiebreaker ({'nearest', 'random'}, default='nearest') – Methoed used to determine the winner class of the majority voting in case of a tie. Possible values: - ‘nearest’ : the nearest neighbor in the tied classes is used to break the tie. - ‘random’ : the winner is chosen randomly among the tied classes.

  • weights ({'uniform', 'distance'}, default='uniform') –

    Weight function used in prediction. Possible values: - ‘uniform’ : uniform weights. All points in each neighborhood

    are weighted equally.

    • ’distance’ : weight points by the inverse of their distance.

  • p (int, default=2) – Power parameter for the Minkowski metric.

  • metric ({'minkowski', 'hamming'}, default='minkowski') – The distance metric to use if weights is set to ‘distance’.

__init__(n_neighbors=5, tiebreaker='nearest', weights='uniform', p=2, metric='minkowski')

Methods

__init__([n_neighbors, tiebreaker, weights, ...])

predict(x)

Predict the class label for the provided point

train(x, y)

Fit the k-nearest neighbors classifier from the training dataset.