module mltricks.sklearn_example_classifier
#
Short summary#
module papierstat.mltricks.sklearn_example_classifier
Defines SkCustomKnn
Classes#
class |
truncated documentation |
---|---|
Implements the k-Nearest Neighbors as an example. |
Methods#
method |
truncated documentation |
---|---|
constructor |
|
Computes the output of the model in case of a regressor, matrix with a score for each class and each sample … |
|
Converts a distance to weight. |
|
Train a k-NN model. There is not much to do except storing the training examples. |
|
Finds the k nearest neighbors for x. |
|
Predicts, usually, it calls the |
Documentation#
Defines SkCustomKnn
- class papierstat.mltricks.sklearn_example_classifier.SkCustomKnn(k=1)#
Bases :
SkBaseClassifier
Implements the k-Nearest Neighbors as an example.
constructor
- Paramètres:
k – number of neighbors to considers
- __init__(k=1)#
constructor
- Paramètres:
k – number of neighbors to considers
- decision_function(X)#
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.
- distance2weight(d)#
Converts a distance to weight.
- Paramètres:
d – distance
- Renvoie:
weight (1/(d+1))
- fit(X, y=None, sample_weight=None)#
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.
- knn_search(x)#
Finds the k nearest neighbors for x.
- Paramètres:
x – vector
- Renvoie:
k-nearest neighbors list( (distance**2, index) )
- predict(X)#
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.