skmultiflow.neural_networks.PerceptronMask

class skmultiflow.neural_networks.PerceptronMask(penalty=None, alpha=0.0001, fit_intercept=True, max_iter=1000, tol=0.001, shuffle=True, verbose=0, eta0=1.0, n_jobs=None, random_state=0, early_stopping=False, validation_fraction=0.1, n_iter_no_change=5, class_weight=None, warm_start=False)[source]

Mask for sklearn.linear_model.Perceptron.

scikit-multiflow requires a few interfaces, not present in scikit-learn, This mask serves as a wrapper for the Perceptron classifier.

Examples

>>> # Imports
>>> from skmultiflow.neural_networks import PerceptronMask
>>> from skmultiflow.data import SEAGenerator
>>>
>>> # Setup a data stream
>>> stream = SEAGenerator(random_state=1)
>>>
>>> # Setup the Perceptron Mask
>>> perceptron = PerceptronMask()
>>>
>>> n_samples = 0
>>> correct_cnt = 0
>>> while n_samples < 5000 and stream.has_more_samples():
>>>     X, y = stream.next_sample()
>>>     my_pred = perceptron.predict(X)
>>>     if y[0] == my_pred[0]:
>>>         correct_cnt += 1
>>>     perceptron.partial_fit(X, y, classes=stream.target_values)
>>>     n_samples += 1
>>>
>>> # Display the results
>>> print('Perceptron Mask usage example')
>>> print('{} samples analyzed'.format(n_samples))
>>> print("Perceptron's performance: {}".format(correct_cnt / n_samples))

Methods

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

Calls the Perceptron fit function from sklearn.

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])

Calls the Perceptron partial_fit from sklearn.

predict(self, X)

Uses the current model to predict samples in X.

predict_proba(self, X)

Predicts the probability of each sample belonging to each one of the known classes.

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.

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

Calls the Perceptron fit function from sklearn.

Parameters
X: numpy.ndarray of shape (n_samples, n_features)

The feature’s matrix.

y: Array-like

The class labels for all samples in X.

classes: Not used.
sample_weight:

Samples weight. If not provided, uniform weights are assumed.

Returns
PerceptronMask

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]

Calls the Perceptron partial_fit from sklearn.

Parameters
X: numpy.ndarray of shape (n_samples, n_features)

The feature’s matrix.

y: Array-like

The class labels for all samples in X.

classes: Not used.
sample_weight:

Samples weight. If not provided, uniform weights are assumed.

Returns
PerceptronMask

self

predict(self, X)[source]

Uses the current model to predict samples in X.

Parameters
X: numpy.ndarray of shape (n_samples, n_features)

The feature’s matrix.

Returns
numpy.ndarray

A numpy.ndarray containing the predicted labels for all instances in X.

predict_proba(self, X)[source]

Predicts the probability of each sample belonging to each one of the known classes.

Parameters
X: Numpy.ndarray of shape (n_samples, n_features)

A matrix of the samples we want to predict.

Returns
numpy.ndarray

An array of shape (n_samples, n_features), in which each outer entry is associated with the X entry of the same index. And where the list in index [i] contains len(self.target_values) elements, each of which represents the probability that the i-th sample of X belongs to a certain label.

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