module mltricks.sklearn_example_classifier

Inheritance diagram of papierstat.mltricks.sklearn_example_classifier

Short summary

module papierstat.mltricks.sklearn_example_classifier

Defines SkCustomKnn

source on GitHub

Classes

class truncated documentation
SkCustomKnn Implements the k-Nearest Neighbors as an example.

Methods

method truncated documentation
__init__ constructor
decision_function Computes the output of the model in case of a regressor, matrix with a score for each class and each sample …
distance2weight Converts a distance to weight.
fit Train a k-NN model. There is not much to do except storing the training examples.
knn_search Finds the k nearest neighbors for x.
predict Predicts, usually, it calls the decision_function

Documentation

Defines SkCustomKnn

source on GitHub

class papierstat.mltricks.sklearn_example_classifier.SkCustomKnn(k=1)[source]

Bases : mlinsights.sklapi.sklearn_base_classifier.SkBaseClassifier

Implements the k-Nearest Neighbors as an example.

source on GitHub

constructor

Paramètres:k – number of neighbors to considers

source on GitHub

__init__(k=1)[source]

constructor

Paramètres:k – number of neighbors to considers

source on GitHub

decision_function(X)[source]

Computes the output of the model in case of a regressor, matrix with a score for each class and each sample for a classifier.

Paramètres:X – Samples, {array-like, sparse matrix}, shape = (n_samples, n_features)
Renvoie:array, shape = (n_samples,.), Returns predicted values.

source on GitHub

distance2weight(d)[source]

Converts a distance to weight.

Paramètres:d – distance
Renvoie:weight (1/(d+1))

source on GitHub

fit(X, y=None, sample_weight=None)[source]

Train a k-NN model. There is not much to do except storing the training examples.

Paramètres:
  • X – Training data, numpy array or sparse matrix of shape [n_samples,n_features]
  • y – Target values, numpy array of shape [n_samples, n_targets] (optional)
  • sample_weight – Weight values, numpy array of shape [n_samples, n_targets] (optional)
Renvoie:

self : returns an instance of self.

source on GitHub

Finds the k nearest neighbors for x.

Paramètres:x – vector
Renvoie:k-nearest neighbors list( (distance**2, index) )

source on GitHub

predict(X)[source]

Predicts, usually, it calls the decision_function method.

Paramètres:X – Samples, {array-like, sparse matrix}, shape = (n_samples, n_features)
Renvoie:self : returns an instance of self.

source on GitHub