SelfTrainingClassifier
- class sklearn.semi_supervised.SelfTrainingClassifier(estimator=None, threshold=0.75, criterion='threshold', k_best=10, max_iter=10, verbose=False
Self-training classifier.
This metaestimator allows a given supervised classifier to function as a semi-supervised classifier, allowing it to learn from unlabeled data. It does this by iteratively predicting pseudo-labels for the unlabeled data and adding them to the training set.
The classifier will continue iterating until either max_iter is reached, or no pseudo-labels were added to the training set in the previous iteration.
Read more in the User Guide.
An estimator object implementing fit and predict_proba.
Invoking the fit method will fit a clone of the passed estimator,
which will be stored in the estimator_ attribute.
The decision threshold for use with criterion='threshold'.
Should be in [0, 1). When using the 'threshold' criterion, a
well calibrated classifier should be used.
The selection criterion used to select which labels to add to the
training set. If 'threshold', pseudo-labels with prediction
probabilities above threshold are added to the dataset. If 'k_best',
the k_best pseudo-labels with highest prediction probabilities are
added to the dataset. When using the ‘threshold’ criterion, a
well calibrated classifier should be used.
The amount of samples to add in each iteration. Only used when
criterion='k_best'.
Maximum number of iterations allowed. Should be greater than or equal
to 0. If it is None, the classifier will continue to predict labels
until no new pseudo-labels are added, or all unlabeled samples have
been labeled.
Enable verbose output.
The fitted estimator.
Class labels for each output. (Taken from the trained
estimator_).
The labels used for the final fit of the classifier, including pseudo-labels added during fit.
The iteration in which each sample was labeled. When a sample has iteration 0, the sample was already labeled in the original dataset. When a sample has iteration -1, the sample was not labeled in any iteration.
Number of features seen during fit.
>>> import numpy as np
>>> from sklearn import datasets
>>> from sklearn.semi_supervised import SelfTrainingClassifier
>>> from sklearn.linear_model import LogisticRegression
>>> rng = np.random.RandomState(
Call decision function of the estimator.
Array representing the data.
Parameters to pass to the underlying estimator’s
decision_function method.
Fit self-training classifier using X, y as training data.
Array representing the data.
Array representing the labels. Unlabeled samples should have the label -1.
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Get parameters for this estimator.
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Parameter names mapped to their values.
Predict the classes of X.
Array representing the data.
Parameters to pass to the underlying estimator’s predict method.
Predict log probability for each possible outcome.
Array representing the data.
Parameters to pass to the underlying estimator’s
predict_log_proba method.
Predict probability for each possible outcome.
Array representing the data.
Parameters to pass to the underlying estimator’s
predict_proba method.
Call score on the estimator.
Array representing the data.
Array representing the labels.
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.
Estimator parameters.
Decision boundary of semi-supervised classifiers versus SVM on the Iris dataset
Added in version 0.24.
n_features_in_,)Names of features seen during fit. Defined only when X
has feature names that are all strings.
The number of rounds of self-training, that is the number of times the base estimator is fitted on relabeled variants of the training set.
The reason that fitting was stopped.
'max_iter': n_iter_ reached max_iter.
'no_change': no new labels were predicted.
'all_labeled': all unlabeled samples were labeled before max_iter
was reached.
Added in version 1.6: Only available if enable_metadata_routing=True,
which can be set by using
sklearn.set_config(enable_metadata_routing=True).
See Metadata Routing User Guide for
more details.
Result of the decision function of the estimator.
Parameters to pass to the underlying estimators.
Fitted estimator.
Added in version 1.6: Only available if enable_metadata_routing=True,
which can be set by using
sklearn.set_config(enable_metadata_routing=True).
See Metadata Routing User Guide for
more details.
Array with predicted labels.
Added in version 1.6: Only available if enable_metadata_routing=True,
which can be set by using
sklearn.set_config(enable_metadata_routing=True).
See Metadata Routing User Guide for
more details.
Array with log prediction probabilities.
Added in version 1.6: Only available if enable_metadata_routing=True,
which can be set by using
sklearn.set_config(enable_metadata_routing=True).
See Metadata Routing User Guide for
more details.
Array with prediction probabilities.
Parameters to pass to the underlying estimator’s score method.
Result of calling score on the estimator.
Estimator instance.