module mlmodel.classification_kmeans

Inheritance diagram of mlinsights.mlmodel.classification_kmeans

Short summary

module mlinsights.mlmodel.classification_kmeans

Combines a k-means followed by a predictor.

source on GitHub

Classes

class

truncated documentation

ClassifierAfterKMeans

Applies a k-means (see sklearn.cluster.KMeans) for each class, then adds the distance to each cluster …

Methods

method

truncated documentation

__init__

decision_function

Calls decision_function.

fit

Runs a k-means on each class then trains a classifier on the extended set of features. Parameters …

get_params

Returns the parameters for both the clustering and the classifier.

predict

Runs the predictions.

predict_proba

Converts predictions into probabilities.

set_params

Sets the parameters before training. Every parameter prefixed by 'e_' is an estimator parameter, every …

transform_features

Applies all the clustering objects on every observations and extends the list of features.

Documentation

Combines a k-means followed by a predictor.

source on GitHub

class mlinsights.mlmodel.classification_kmeans.ClassifierAfterKMeans(estimator=None, clus=None, **kwargs)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.ClassifierMixin

Applies a k-means (see sklearn.cluster.KMeans) for each class, then adds the distance to each cluster as a feature for a classifier. See notebook LogisticRegression and Clustering.

source on GitHub

Parameters

source on GitHub

__init__(estimator=None, clus=None, **kwargs)[source]
Parameters

source on GitHub

decision_function(X)[source]

Calls decision_function.

source on GitHub

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

Runs a k-means on each class then trains a classifier on the extended set of features.

Parameters
  • X (numpy array or sparse matrix of shape [n_samples,n_features]) – Training data

  • y (numpy array of shape [n_samples, n_targets]) – Target values. Will be cast to X’s dtype if necessary

  • sample_weight (numpy array of shape [n_samples]) – Individual weights for each sample

Returns

self

Return type

returns an instance of self.

labels_
Type

dictionary of clustering models

clus_
Type

array of clustering models

estimator_
Type

trained classifier

source on GitHub

get_params(deep=True)[source]

Returns the parameters for both the clustering and the classifier.

Parameters

deep – unused here

Returns

dict

set_params describes the pattern parameters names follow.

source on GitHub

predict(X)[source]

Runs the predictions.

source on GitHub

predict_proba(X)[source]

Converts predictions into probabilities.

source on GitHub

set_params(**values)[source]

Sets the parameters before training. Every parameter prefixed by 'e_' is an estimator parameter, every parameter prefixed by 'c_' is for the sklearn.cluster.KMeans.

Parameters

values – valeurs

Returns

dict

source on GitHub

transform_features(X)[source]

Applies all the clustering objects on every observations and extends the list of features.

Parameters

X – features

Returns

extended features

source on GitHub