skmultiflow.prototype.RobustSoftLearningVectorQuantization

class skmultiflow.prototype.RobustSoftLearningVectorQuantization(prototypes_per_class=1, initial_prototypes=None, sigma=1.0, random_state=None, gradient_descent='vanilla', gamma=0.9)[source]

Robust Soft Learning Vector Quantization for Streaming and Non-Streaming Data.

By choosing another gradient descent method the Robust Soft Learning Vector Quantization (RSLVQ) method can be used as an adaptive version.

Parameters
prototypes_per_class: int or list of int, optional (default=1)

Number of prototypes per class. Use list to specify different numbers per class, not implemented yet.

initial_prototypes: array-like, shape = [n_prototypes, n_features + 1], optional

Prototypes to start with. If not given initialization near the class means. Class label must be placed as last entry of each prototype.

Example for one prototype per class on a binary classification problem:
initial_prototypes = [[2.59922826, 2.57368134, 4.92501, 0], [6.05801971, 6.01383352, 5.02135783, 1]]
sigmafloat, optional (default=1.0)

Variance of the distribution.

random_stateint, RandomState instance or None, optional (default=None)

If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

gammafloat, Decay rate, optional (default=0.9)

Decay rate used for momentum-based algorithm

gradient_descent: string, specify gradient optimizer, optional
(default=’vanilla’)

To use momentum-based gradient descent, choose ‘adadelta’ instead of ‘vanilla’

Notes

The RSLVQ [2] can be used with vanilla SGD as gradient descent method or with a momentum-based gradient descent technique called Adadelta as proposed in [1].

References

1

Heusinger, M., Raab, C., Schleif, F.M.: Passive concept drift handling via momentum based robust soft learning vector quantization. In: Vellido, A., Gibert, K., Angulo, C., Martı́n Guerrero, J.D. (eds.) Advances in Self-Organizing Maps, Learning Vector Quantization, Clustering and Data Visualization. pp. 200–209. Springer International Publishing, Cham (2020)

2

Sambu Seo and Klaus Obermayer. 2003. Soft learning vector quantization. Neural Comput. 15, 7 (July 2003), 1589-1604

Examples

>>> # Imports
>>> from skmultiflow.data import SEAGenerator
>>> from skmultiflow.prototype import RobustSoftLearningVectorQuantization
>>>
>>> # Setup a data stream
>>> stream = SEAGenerator(random_state=1)
>>>
>>> # Pre-train the estimator with 200 samples
>>> X, y = stream.next_sample(200)
>>> rslvq = RobustSoftLearningVectorQuantization()
>>> rslvq.partial_fit(X, y)
>>>
>>> # Preparing the processing of 5000 samples and correct prediction count
>>> n_samples = 0
>>> correct_cnt = 0
>>> while n_samples < 5000 and stream.has_more_samples():
>>>     X, y = stream.next_sample()
>>>     y_pred = rslvq.predict(X)
>>>     if y[0] == y_pred[0]:
>>>         correct_cnt += 1
>>>     rslvq.partial_fit(X, y)
>>>     n_samples += 1
>>>
>>> # Display results
>>> print('Robust Soft Learning Vector Quantization usage example')
>>> print('{} samples analyzed.'.format(n_samples))
>>> print('Performance: {}'.format(correct_cnt / n_samples))
Attributes
prototypesarray-like, shape = [n_prototypes, n_features]

The prototypes

prototypes_classesarray-like, shape = [n_prototypes]

The prototypes classes

class_labelsarray-like, shape = [n_classes]

The class labels

Methods

fit(self, X, y[, classes, sample_weight])

Fit the model.

get_info(self)

Collects and returns the information about the configuration of the estimator

get_params(self[, deep])

Get parameters for this estimator.

partial_fit(self, X, y[, classes, sample_weight])

Fit the LVQ model to the given training data and parameters using gradient ascent.

predict(self, X)

Predict class membership index for each input sample.

predict_proba(self, X)

Not implemented for this method.

reset(self)

Resets the estimator to its initial state.

score(self, X, y[, sample_weight])

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

set_params(self, **params)

Set the parameters of this estimator.

Attributes

class_labels

The class labels

prototypes

The prototypes

prototypes_classes

The prototypes classes

property class_labels

The class labels

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

Fit the model.

Parameters
Xnumpy.ndarray of shape (n_samples, n_features)

The features to train the model.

y: numpy.ndarray of shape (n_samples, n_targets)

An array-like with the class labels of all samples in X.

classes: numpy.ndarray, optional (default=None)

Contains all possible/known class labels. Usage varies depending on the learning method.

sample_weight: numpy.ndarray, optional (default=None)

Samples weight. If not provided, uniform weights are assumed. Usage varies depending on the learning method.

Returns
self
get_info(self)[source]

Collects and returns the information about the configuration of the estimator

Returns
string

Configuration of the estimator.

get_params(self, deep=True)[source]

Get parameters for this estimator.

Parameters
deepboolean, optional

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

Returns
paramsmapping of string to any

Parameter names mapped to their values.

partial_fit(self, X, y, classes=None, sample_weight=None)[source]

Fit the LVQ model to the given training data and parameters using gradient ascent.

Parameters
Xarray-like, shape = [n_samples, n_features]

Training vector, where n_samples in the number of samples and n_features is the number of features.

ynumpy.ndarray of shape (n_samples, n_targets)

An array-like with the class labels of all samples in X

classesnumpy.ndarray, optional (default=None)

Contains all possible/known class labels. Usage varies depending on the learning method.

sample_weightNot used.
Returns
self
predict(self, X)[source]

Predict class membership index for each input sample.

This function does classification on an array of test vectors X.

Parameters
Xarray-like, shape = [n_samples, n_features]
Returns
Carray, shape = (n_samples)

Returns predicted values.

predict_proba(self, X)[source]

Not implemented for this method.

property prototypes

The prototypes

property prototypes_classes

The prototypes classes

reset(self)[source]

Resets the estimator to its initial state.

Returns
self
score(self, X, y, sample_weight=None)[source]

Returns 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
Xarray-like, shape = (n_samples, n_features)

Test samples.

yarray-like, shape = (n_samples) or (n_samples, n_outputs)

True labels for X.

sample_weightarray-like, shape = [n_samples], optional

Sample weights.

Returns
scorefloat

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

set_params(self, **params)[source]

Set the parameters of this estimator.

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

Returns
self