skmultiflow.meta.
MultiOutputLearner
Multi-Output Learner for multi-target classification or regression.
Each member of the ensemble is an instance of the base estimator.
Notes
Use this meta learner to make single output predictors capable of learning a multi output problem, by applying them individually to each output. In the classification context, this is the “binary relevance” estimator.
A Multi-Output Learner model learns to predict multiple outputs for each instance. The outputs may either be discrete (i.e., classification), or continuous (i.e., regression). This estimator takes any base learner (which by default is LogisticRegression) and builds a separate model for each output, and will distribute each instance to each model for individual learning and prediction.
Examples
>>> from skmultiflow.meta.multi_output_learner import MultiOutputLearner >>> from skmultiflow.data.file_stream import FileStream >>> from sklearn.linear_model import Perceptron >>> # Setup the file stream >>> stream = FileStream("https://raw.githubusercontent.com/scikit-multiflow/" ... "streaming-datasets/master/moving_squares.csv", 0, 6) >>> # Setup the MultiOutputLearner using sklearn Perceptron >>> classifier = MultiOutputLearner(base_estimator=Perceptron()) >>> # Setup the pipeline >>> # Pre training the classifier with 150 samples >>> X, y = stream.next_sample(150) >>> classifier.partial_fit(X, y, classes=stream.target_values) >>> # Keeping track of sample count, true labels and predictions to later >>> # compute the classifier's hamming score >>> count = 0 >>> true_labels = [] >>> predicts = [] >>> while stream.has_more_samples(): ... X, y = stream.next_sample() ... p = classifier.predict(X) ... classifier.partial_fit(X, y) ... predicts.extend(p) ... true_labels.extend(y) ... count += 1 >>> >>> perf = hamming_score(true_labels, predicts) >>> print('Total samples analyzed: ' + str(count)) >>> print("The classifier's static Hamming score : " + str(perf))
Methods
fit(self, X, y[, classes, sample_weight])
fit
Fit the model.
get_info(self)
get_info
Collects and returns the information about the configuration of the estimator
get_params(self[, deep])
get_params
Get parameters for this estimator.
partial_fit(self, X, y[, classes, sample_weight])
partial_fit
Partially (incrementally) fit the model.
predict(self, X)
predict
Predict target values for the passed data.
predict_proba(self, X)
predict_proba
Estimates the probability of each sample in X belonging to each of the existing labels for each of the classification tasks.
reset(self)
reset
Resets the estimator to its initial state.
score(self, X, y[, sample_weight])
score
Returns the mean accuracy on the given test data and labels.
set_params(self, **params)
set_params
Set the parameters of this estimator.
Fit n-estimators, one for each learning task.
The features to train the model.
An array-like with the target values of all samples in X.
Array with all possible/known class labels. Usage varies depending on the base estimator. Not used for regression.
Samples weight. If not provided, uniform weights are assumed. Usage varies depending on the base estimator.
self
Configuration of the estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Partially fit each of the estimators on the X matrix and the corresponding y matrix.
Array with all possible/known class labels. This is an optional parameter, except for the first partial_fit call where it is compulsory. Not used for regression.
Iterates over all the estimators, predicting with each one, to obtain the multi output prediction.
The set of data samples to predict the target values for.
numpy.ndarray of shape (n_samples, n_targets) All the predictions for the samples in X.
It’s a simple call to all of the classifier’s predict_proba function, return the probabilities for all the classification problems.
Not applicable for regression tasks.
The set of data samples to predict the class labels for.
An array of shape (n_samples, n_classification_tasks, n_labels), in which we store the probability that each sample in X belongs to each of the labels, in each of the classification tasks.
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.
Test samples.
True labels for X.
Sample weights.
Mean accuracy of self.predict(X) wrt. y.
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.
<component>__<parameter>