SkactivemlClassifier#
- class skactiveml.base.SkactivemlClassifier(classes=None, missing_label=nan, cost_matrix=None, random_state=None, target_type='auto')[source]#
Bases:
ClassifierMixin,BaseEstimator,ABCSkactiveml Classifier
Base class for scikit-activeml classifiers such that missing labels, user-defined classes, and cost-sensitive classification (i.e., cost matrix) can be handled.
- Parameters:
- classesarray-like of shape (n_classes,) or a list of such array-likes, default=None
A flat vocabulary describes single-output classification and is applied to every annotator entry for multi-annotator components.
Nested binary vocabularies describe multi-label classification, one class vocabulary per label output. Nested non-binary vocabularies describe recognized multi-output classification semantics.
- missing_labelscalar, string, 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 and one-dimensional, which corresponds to single output classification.
- 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.
- target_type“auto” or “single-output” or “multi-label” or “multi-output”, default=”auto”
Declared target type. Components reject resolved target specifications outside their exact capabilities.
- Attributes:
- target_spec_skactiveml.utils.TargetSpec
Immutable target specification established by a successful fit. Its class vocabularies use the canonical ordering of classes_.
Methods
fit(X, y[, sample_weight])Fit the model using X as training data and y as class labels.
predict(X, **kwargs)Return class label predictions for the test samples X.
predict_proba(X, **kwargs)Return probability estimates for the test data X.
score(X, y[, sample_weight])Return the mean accuracy on the given test data and labels.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
set_fit_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
fitmethod.set_params(**params)Set the parameters of this estimator.
set_score_request(*[, sample_weight])Configure whether metadata should be requested to be passed to the
scoremethod.
- abstract SkactivemlClassifier.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, …)
The samples X whose shape depends on the respective classifier.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs) or (n_samples, n_annotators)
Labels of the training data set (possibly including unlabeled ones indicated by missing_label). For multioutput problems, a row y[i] must either contain only observed labels or only missing_label values, i.e., no mixing within a row. For multi-annotator classification, a row can contain labeled and unlabeled entries, where y[i, j] indicates the potential class label for sample X[i] from annotator j.
- sample_weightarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None
It contains the weights of the training samples. For two- dimensional targets, either one weight per sample or one weight per target entry can be provided.
- Returns:
- self: skactiveml.base.SkactivemlClassifier
The skactiveml.base.SkactivemlClassifier object fitted on the training data.
- SkactivemlClassifier.predict(X, **kwargs)[source]#
Return class label predictions for the test samples X.
- Parameters:
- Xarray-like of shape (n_samples, …)
Input samples.
- Returns:
- ynumpy.ndarray of shape (n_samples,)
Predicted class labels of the test samples X.
- SkactivemlClassifier.predict_proba(X, **kwargs)[source]#
Return probability estimates for the test data X.
- Parameters:
- Xarray-like of shape (n_samples, …)
Test samples.
- Returns:
- Pnumpy.ndarray of shape (n_samples, classes)
The class probabilities of the test samples. Classes are ordered according to self.classes_.
- SkactivemlClassifier.score(X, y, sample_weight=None)[source]#
Return the mean accuracy on the given test data and labels.
- Parameters:
- Xarray-like of shape (n_samples, …)
Test samples.
- yarray-like of shape (n_samples,)
True class labels of the test samples X.
- sample_weightarray-like of shape (n_samples,), default=None
Sample weights of the test sample X.
- Returns:
- scorefloat
Mean accuracy of self.predict(X) regarding y.
- SkactivemlClassifier.get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- SkactivemlClassifier.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.
- SkactivemlClassifier.set_fit_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SkactivemlClassifier#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif 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.Added in version 1.3.
- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter infit.
- Returns:
- selfobject
The updated object.
- SkactivemlClassifier.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.
- SkactivemlClassifier.set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SkactivemlClassifier#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif 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.Added in version 1.3.
- Parameters:
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
- Returns:
- selfobject
The updated object.
Examples using skactiveml.base.SkactivemlClassifier#
Batch Active Learning by Diverse Gradient Embedding (BADGE)
Batch Bayesian Active Learning by Disagreement (BatchBALD)
Fast Active Learning by Contrastive UNcertainty (FALCUN)
Batch Density-Diversity-Distribution-Distance Sampling (4DS)
Density-Diversity-Distribution-Distance Sampling (4DS)
Maximum Loss Reduction with Maximal Confidence (MMC)
Monte-Carlo Expected Error Reduction (EER) with Log-Loss
Monte-Carlo Expected Error Reduction (EER) with Misclassification-Loss
Query-by-Committee (QBC) with Kullback-Leibler Divergence
Querying Informative and Representative Examples (QUIRE)
Uncertainty Sampling with Expected Average Precision (USAP)
Cognitive Dual-Query Strategy with Fixed-Uncertainty
Cognitive Dual-Query Strategy with Random Sampling
Cognitive Dual-Query Strategy with Randomized-Variable-Uncertainty
Cognitive Dual-Query Strategy with Variable-Uncertainty