skactiveml.classifier.SklearnClassifier#
- class skactiveml.classifier.SklearnClassifier(estimator, classes=None, missing_label=nan, cost_matrix=None, random_state=None)[source]#
Bases:
SkactivemlClassifier
,MetaEstimatorMixin
Implementation of a wrapper class for scikit-learn classifiers such that missing labels can be handled. Therefor, samples with missing labels are filtered.
- Parameters
- estimatorsklearn.base.ClassifierMixin with predict_proba method
scikit-learn classifier that is able to deal with missing labels.
- 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 string 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_array-like of shape (n_classes,)
Holds the label for each class after fitting.
- cost_matrix_array-like 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].
- estimator_sklearn.base.ClassifierMixin with predict_proba method
The scikit-learn classifier after calling the fit method.
Methods
fit
(X, y[, sample_weight])Fit the model using X as training data and y as class labels.
Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
partial_fit
(X, y[, sample_weight])Partially fitting the model using X as training data and y as class labels.
predict
(X, **predict_kwargs)Return class label predictions for the input data X.
predict_proba
(X, **predict_proba_kwargs)Return probability estimates for the input 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 this estimator.
set_partial_fit_request
(*[, sample_weight])Request metadata passed to the
partial_fit
method.set_score_request
(*[, sample_weight])Request metadata passed to the
score
method.- fit(X, y, sample_weight=None, **fit_kwargs)[source]#
Fit the model using X as training data and y as class labels.
- Parameters
- Xmatrix-like, shape (n_samples, n_features)
The sample matrix X is the feature matrix representing the samples.
- yarray-like, shape (n_samples) or (n_samples, n_outputs)
It contains the class labels of the training samples. Missing labels are represented the attribute ‘missing_label’. In case of multiple labels per sample (i.e., n_outputs > 1), the samples are duplicated.
- sample_weightarray-like, shape (n_samples) or (n_samples, n_outputs)
It contains the weights of the training samples’ class labels. It must have the same shape as y.
- fit_kwargsdict-like
Further parameters as input to the ‘fit’ method of the ‘estimator’.
- Returns
- self: SklearnClassifier,
The SklearnClassifier is 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 parameters for this estimator.
- Parameters
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns
- paramsdict
Parameter names mapped to their values.
- partial_fit(X, y, sample_weight=None, **fit_kwargs)[source]#
Partially fitting the model using X as training data and y as class labels.
- Parameters
- Xmatrix-like, shape (n_samples, n_features)
The sample matrix X is the feature matrix representing the samples.
- yarray-like, shape (n_samples) or (n_samples, n_outputs)
It contains the class labels of the training samples. Missing labels are represented the attribute ‘missing_label’. In case of multiple labels per sample (i.e., n_outputs > 1), the samples are duplicated.
- sample_weightarray-like, shape (n_samples) or (n_samples, n_outputs)
It contains the weights of the training samples’ class labels. It must have the same shape as y.
- fit_kwargsdict-like
Further parameters as input to the ‘fit’ method of the ‘estimator’.
- Returns
- selfSklearnClassifier,
The SklearnClassifier is fitted on the training data.
- predict(X, **predict_kwargs)[source]#
Return class label predictions for the input data X.
- Parameters
- Xarray-like, shape (n_samples, n_features)
Input samples.
- predict_kwargsdict-like
Further parameters as input to the ‘predict’ method of the ‘estimator’.
- Returns
- yarray-like, shape (n_samples)
Predicted class labels of the input samples.
- predict_proba(X, **predict_proba_kwargs)[source]#
Return probability estimates for the input data X.
- Parameters
- Xarray-like, shape (n_samples, n_features)
Input samples.
- predict_proba_kwargsdict-like
Further parameters as input to the ‘predict_proba’ method of the ‘estimator’.
- Returns
- Parray-like, shape (n_samples, classes)
The class probabilities of the input samples. Classes are ordered by lexicographic order.
- 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$') SklearnClassifier #
Request metadata passed to the
fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed tofit
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it tofit
.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 infit
.
- Returns
- selfobject
The updated object.
- set_params(**params)#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline
). The latter have parameters of the form<component>__<parameter>
so that it’s possible to update each component of a nested object.- Parameters
- **paramsdict
Estimator parameters.
- Returns
- selfestimator instance
Estimator instance.
- set_partial_fit_request(*, sample_weight: Union[bool, None, str] = '$UNCHANGED$') SklearnClassifier #
Request metadata passed to the
partial_fit
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed topartial_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 topartial_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 inpartial_fit
.
- Returns
- selfobject
The updated object.
- set_score_request(*, sample_weight: Union[bool, None, str] = '$UNCHANGED$') SklearnClassifier #
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.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 inscore
.
- Returns
- selfobject
The updated object.
Examples using skactiveml.classifier.SklearnClassifier
#

Batch Bayesian Active Learning by Disagreement (BatchBALD)