skmultiflow.meta.
DynamicWeightedMajorityClassifier
Dynamic Weighted Majority ensemble classifier.
Maximum number of estimators to hold.
Each member of the ensemble is an instance of the base estimator.
Period between expert removal, creation, and weight update.
Factor for which to decrease weights by.
Minimum fraction of weight per model.
Notes
The dynamic weighted majority (DWM) [1], uses four mechanisms to cope with concept drift: It trains online learners of the ensemble, it weights those learners based on their performance, it removes them, also based on their performance, and it adds new experts based on the global performance of the ensemble.
References
Kolter and Maloof. Dynamic weighted majority: An ensemble method for drifting concepts. The Journal of Machine Learning Research, 8:2755-2790, December 2007. ISSN 1532-4435.
Examples
>>> # Imports >>> from skmultiflow.data import SEAGenerator >>>from skmultiflow.meta import DynamicWeightedMajorityClassifier >>> >>> # Setup a data stream >>> stream = SEAGenerator(random_state=1) >>> >>> # Setup Dynamic Weighted Majority Ensemble Classifier >>> dwm = DynamicWeightedMajorityClassifier() >>> >>> # Setup variables to control loop and track performance >>> n_samples = 0 >>> correct_cnt = 0 >>> max_samples = 200 >>> >>> # Train the classifier with the samples provided by the data stream >>> while n_samples < max_samples and stream.has_more_samples(): >>> X, y = stream.next_sample() >>> y_pred = dwm.predict(X) >>> if y[0] == y_pred[0]: >>> correct_cnt += 1 >>> dwm.partial_fit(X, y) >>> n_samples += 1 >>> >>> # Display results >>> print('{} samples analyzed.'.format(n_samples)) >>> print('Dynamic Weighted Majority accuracy: {}'.format(correct_cnt / n_samples))
Methods
fit(self, X, y[, classes, sample_weight])
fit
Fit the model.
fit_single_sample(self, X, y[, classes, …])
fit_single_sample
Fits a single sample of shape X.shape=(1, n_attributes) and y.shape=(1)
get_expert_predictions(self, X)
get_expert_predictions
Returns predictions of each class for each expert.
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 fits the model on the supplied X and y matrices.
predict(self, X)
predict
The predict function will take an average of the predictions of its learners, weighted by their respective weights, and return the most likely class.
predict_proba(self, X)
predict_proba
Estimates the probability of each sample in X belonging to each of the class-labels.
reset(self)
reset
Reset this ensemble learner.
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.
WeightedExpert
Wrapper that includes an estimator and its weight.
The estimator to wrap.
The estimator’s weight.
The features to train the model.
An array-like with the class labels of all samples in X.
Contains all possible/known class labels. Usage varies depending on the learning method.
Samples weight. If not provided, uniform weights are assumed. Usage varies depending on the learning method.
Aggregates all experts’ predictions, diminishes weight of experts whose predictions were wrong, and may create or remove experts every _period_ samples.
Finally, trains each individual expert on the provided data.
Train loop as described by Kolter and Maloof in the original paper.
Features matrix used for partially updating the model.
An array-like of all the class labels for the samples in X.
List of all existing classes. This is an optional parameter.
Samples weight. If not provided, uniform weights are assumed. Applicability depends on the base estimator.
Returns predictions of each class for each expert. In shape: (n_experts, n_samples)
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.
Since it’s an ensemble learner, if X and y matrix of more than one sample are passed, the algorithm will partial fit the model one sample at a time.
Array with all possible/known class labels. This is an optional parameter, except for the first partial_fit call where it is compulsory.
Samples weight. If not provided, uniform weights are assumed. Usage varies depending on the base estimator.
self
A matrix of the samples we want to predict.
A numpy.ndarray with the label prediction for all the samples in X.
The matrix of samples one wants to predict the class probabilities for.
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>