KNNClassificationVoter

class proglearn.KNNClassificationVoter(k=None, kwargs={}, classes=[])[source]

A class used to vote on data under any transformer outputting data in continuous Euclidean space, which inherits from the BaseClassificationVoter class in base.py.

Parameters

k : int

integer indicating number of neighbors to use for each prediction during fitting and voting

kwargs : dictionary, default={}

contains all keyword arguments for the underlying KNN

classes : list, default=[]

list of all possible output label values

Attributes

missing_label_indices_

(list) a (potentially empty) list of label values that exist in the classes parameter but are missing in the latest fit function call

knn_

(sklearn.neighbors.KNeighborsClassifier) the internal sklearn instance of KNN classifier

Methods Summary

KNNClassificationVoter.fit(X, y)

Fits data X given class labels y.

KNNClassificationVoter.get_params([deep])

Get parameters for this estimator.

KNNClassificationVoter.predict(X)

Returns the predicted class labels for data X.

KNNClassificationVoter.predict_proba(X)

Returns the posterior probabilities of each class for data X.

KNNClassificationVoter.score(X, y[, ...])

Return the mean accuracy on the given test data and labels.

KNNClassificationVoter.set_params(**params)

Set the parameters of this estimator.


KNNClassificationVoter.fit(X, y)[source]

Fits data X given class labels y.

Parameters

X : array of shape [n_samples, n_features]

the transformed data that will be trained on

y : array of shape [n_samples]

the label for class membership of the given data

Returns

self : KNNClassificationVoter

The object itself.

KNNClassificationVoter.get_params(deep=True)

Get parameters for this estimator.

Parameters

deep : bool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns

params : dict

Parameter names mapped to their values.

KNNClassificationVoter.predict(X)[source]

Returns the predicted class labels for data X.

Parameters

X : array of shape [n_samples, n_features]

the transformed input data

Returns

y_hat : ndarray of shape [n_samples]

predicted class label per example

Raises

NotFittedError

When the model is not fitted.

KNNClassificationVoter.predict_proba(X)[source]

Returns the posterior probabilities of each class for data X.

Parameters

X : array of shape [n_samples, n_features]

the transformed input data

Returns

y_proba_hat : ndarray of shape [n_samples, n_classes]

posteriors per example

Raises

NotFittedError

When the model is not fitted.

KNNClassificationVoter.score(X, y, sample_weight=None)

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Parameters

X : array-like of shape (n_samples, n_features)

Test samples.

y : array-like of shape (n_samples,) or (n_samples, n_outputs)

True labels for X.

sample_weight : array-like of shape (n_samples,), default=None

Sample weights.

Returns

score : float

Mean accuracy of self.predict(X) wrt. y.

KNNClassificationVoter.set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it's possible to update each component of a nested object.

Parameters

**params : dict

Estimator parameters.

Returns

self : estimator instance

Estimator instance.