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 …

Properties

property

truncated documentation

_repr_html_

HTML representation of estimator. This is redundant with the logic of _repr_mimebundle_. The latter should …

Methods

method

truncated documentation

__init__

__repr__

Overloads repr as scikit-learn now relies on the constructor signature.

decision_function

Calls decision_function.

fit

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

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)

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
  • estimatorsklearn.linear_model.LogisiticRegression by default

  • clus – clustering applied on each class, by default k-means with two classes

  • kwargs – sent to set_params, see its documentation to understand how to specify parameters

source on GitHub

__init__(estimator=None, clus=None, **kwargs)
Parameters
  • estimatorsklearn.linear_model.LogisiticRegression by default

  • clus – clustering applied on each class, by default k-means with two classes

  • kwargs – sent to set_params, see its documentation to understand how to specify parameters

source on GitHub

__repr__()

Overloads repr as scikit-learn now relies on the constructor signature.

source on GitHub

decision_function(X)

Calls decision_function.

source on GitHub

fit(X, y, sample_weight=None)

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 : returns an instance of self.

Fitting attributes: * labels_: dictionary of clustering models * clus_: array of clustering models * estimator_: trained classifier

source on GitHub

get_params(deep=True)

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)

Runs the predictions.

source on GitHub

predict_proba(X)

Converts predictions into probabilities.

source on GitHub

set_params(**values)

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)

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

Parameters

X – features

Returns

extended features

source on GitHub