skactiveml.classifier.multiannotator.AnnotatorEnsembleClassifier#

class skactiveml.classifier.multiannotator.AnnotatorEnsembleClassifier(estimators, voting='hard', classes=None, missing_label=nan, cost_matrix=None, random_state=None)[source]#

Bases: _BaseHeterogeneousEnsemble, SkactivemlClassifier

This strategy consists of fitting one classifier per annotator.

Parameters
estimatorslist of (str, estimator) tuples

The ensemble of estimators to use in the ensemble. Each element of the list is defined as a tuple of string (i.e. name of the estimator) and an estimator instance.

voting‘hard’ or ‘soft’, default=’hard’

If ‘hard’, uses predicted class labels for majority rule voting. Else if ‘soft’, predicts the class label based on the argmax of the sums of the predicted probabilities, which is recommended for an ensemble of well-calibrated classifiers.

classesarray-like of shape (n_classes,), default=None

Holds the label for each class. If none, the classes are determined during the fit.

missing_labelscalar or str or np.nan or None, default=np.nan

Value to represent a missing label.

cost_matrixarray-like of shape (n_classes, n_classes)

Cost matrix with cost_matrix[i,j] indicating cost of predicting class classes[j] for a sample of class `classes[i]. Can be only set, if classes is not none.

random_stateint or RandomState instance or None, default=None

Determines random number for ‘predict’ method. Pass an int for reproducible results across multiple method calls.

Attributes
classes_np.ndarray of shape (n_classes,)

Holds the label for each class after fitting.

cost_matrix_np.ndarray of shape (classes, classes)

Cost matrix with cost_matrix_[i,j] indicating cost of predicting class classes_[j] for a sample of class `classes_[i].

estimators_list of estimators

The elements of the estimators parameter, having been fitted on the training data. If an estimator has been set to ‘drop’, it will not appear in estimators_.

Methods

fit(X, y[, sample_weight])

Fit the model using X as training data and y as class labels.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get the parameters of an estimator from the ensemble.

predict(X)

Return class label predictions for the test samples X.

predict_proba(X)

Return probability estimates for the test data X.

score(X, y[, sample_weight])

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

set_fit_request(*[, sample_weight])

Request metadata passed to the fit method.

set_params(**params)

Set the parameters of an estimator from the ensemble.

set_score_request(*[, sample_weight])

Request metadata passed to the score method.

Attributes

named_estimators

Dictionary to access any fitted sub-estimators by name.

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

Fit the model using X as training data and y as class labels.

Parameters
Xarray-like of shape (n_samples, n_features)

The sample matrix X is the feature matrix representing the samples.

yarray-like of shape (n_samples, n_estimators)

It contains the class labels of the training samples. The number of class labels may be variable for the samples, where missing labels are represented the attribute missing_label.

sample_weightarray-like of shape (n_samples, n_estimators)

It contains the weights of the training samples’ class labels. It must have the same shape as y.

Returns
self: skactiveml.classifier.multiannotator.AnnotatorEnsembleClassifier,

The AnnotatorEnsembleClassifier object fitted on the training data.

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get the parameters of an estimator from the ensemble.

Returns the parameters given in the constructor as well as the estimators contained within the estimators parameter.

Parameters
deepbool, default=True

Setting it to True gets the various estimators and the parameters of the estimators as well.

Returns
paramsdict

Parameter and estimator names mapped to their values or parameter names mapped to their values.

property named_estimators#

Dictionary to access any fitted sub-estimators by name.

Returns
Bunch
predict(X)#

Return class label predictions for the test samples X.

Parameters
Xarray-like of shape (n_samples, n_features)

Input samples.

Returns
ynumpy.ndarray of shape (n_samples)

Predicted class labels of the test samples X. Classes are ordered according to classes_.

predict_proba(X)[source]#

Return probability estimates for the test data X.

Parameters
Xarray-like of shape (n_samples, n_features)

Test samples.

Returns
Pnp.ndarray of shape (n_samples, classes)

The class probabilities of the test samples. Classes are ordered according to classes_.

score(X, y, sample_weight=None)#

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

Parameters
Xarray-like of shape (n_samples, n_features)

Test samples.

yarray-like of shape (n_samples,)

True labels for X.

sample_weightarray-like of shape (n_samples,), default=None

Sample weights.

Returns
scorefloat

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

set_fit_request(*, sample_weight: Union[bool, None, str] = '$UNCHANGED$') AnnotatorEnsembleClassifier#

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in fit.

Returns
selfobject

The updated object.

set_params(**params)#

Set the parameters of an estimator from the ensemble.

Valid parameter keys can be listed with get_params(). Note that you can directly set the parameters of the estimators contained in estimators.

Parameters
**paramskeyword arguments

Specific parameters using e.g. set_params(parameter_name=new_value). In addition, to setting the parameters of the estimator, the individual estimator of the estimators can also be set, or can be removed by setting them to ‘drop’.

Returns
selfobject

Estimator instance.

set_score_request(*, sample_weight: Union[bool, None, str] = '$UNCHANGED$') AnnotatorEnsembleClassifier#

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

New in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns
selfobject

The updated object.

steps: List[Any]#