skactiveml.pool.utils.IndexClassifierWrapper#
- class skactiveml.pool.utils.IndexClassifierWrapper(clf, X, y, sample_weight=None, set_base_clf=False, ignore_partial_fit=False, enforce_unique_samples=False, use_speed_up=False, missing_label=nan)[source]#
Bases:
object
Classifier to simplify retraining classifiers in an active learning scenario. The idea is to pass all instances at once and use their indices to access them. Thereby, optimization is possible e.g. by pre-computing kernel-matrices. Moreover, this wrapper implements partial fit for all classifiers and includes a base classifier that can be used to simulate adding different instance-label pairs to the same classifier.
- Parameters
- clfskactiveml.base.SkactivemlClassifier
The base classifier implementing the methods fit and predict_proba.
- Xarray-like of shape (n_samples, n_features)
Training data set, usually complete, i.e. including the labeled and unlabeled samples.
- yarray-like of shape (n_samples)
Labels of the training data set (possibly including unlabeled ones indicated by self.missing_label).
- sample_weightarray-like of shape (n_samples), optional (default=None)
Weights of training samples in X.
- set_base_clfbool, default=False
If True, the base classifier will be set to the newly fitted classifier
- ignore_partial_fitbool, optional (default: True)
Specifies if the partial_fit function of self.clf should be used (if implemented).
- enforce_unique_samplesbool, optional (default: False)
If True, partial_fit will not simply append additional samples but replace the current labels by the new one. If False, instances might appear multiple times if their indices are repeated.
- use_speed_upbool, optional (default: True)
Specifies if potentially available speed ups should be used. Currently implemented for Parzen Window Classifier.
- missing_labelscalar or string or np.nan or None, default=np.nan
Value to represent a missing label.
Methods
fit
(idx[, y, sample_weight, set_base_clf])Fit the model using self.X[idx] as training data and self.y[idx] as class labels.
is_fitted
([base_clf])Returns if the classifier (resp.
partial_fit
(idx[, y, sample_weight, ...])Update the fitted model using additional samples in self.X[idx] and y as class labels.
precompute
(idx_fit, idx_pred[, fit_params, ...])Function to describe for which samples we should precompute something.
predict
(idx)Return class label predictions for the input data X[idx].
predict_freq
(idx)Return class frequency estimates for the input samples 'X[idx]'.
predict_proba
(idx)Return probability estimates for the input data X[idx].
- fit(idx, y=None, sample_weight=None, set_base_clf=False)[source]#
Fit the model using self.X[idx] as training data and self.y[idx] as class labels.
- Parameters
- idxarray-like of shape (n_sub_samples)
Indices of samples in X that will be used to fit the classifier.
- yarray-like of shape (n_sub_samples), optional (default=None)
Class labels of the training samples corresponding to X[idx]. Missing labels are represented the attribute ‘missing_label’. If None, labels passed in the init will be used.
- sample_weight: array-like of shape (n_sub_samples), optional
(default=None) Weights of training samples in X[idx]. If None, weights passed in the init will be used.
- set_base_clfbool, default=False
If True, the base classifier will be set to the newly fitted classifier
- Returns
- self: IndexClassifierWrapper,
The fitted IndexClassifierWrapper.
- is_fitted(base_clf=False)[source]#
Returns if the classifier (resp. the base classifier) is fitted.
- Parameters
- base_clfbool, default=False
If True, the result will describe if the base classifier is fitted.
- Returns
- is_fittedboolean
Boolean describing if the classifier is fitted.
- partial_fit(idx, y=None, sample_weight=None, use_base_clf=False, set_base_clf=False)[source]#
Update the fitted model using additional samples in self.X[idx] and y as class labels.
- Parameters
- idxarray-like of shape (n_sub_samples)
Indices of samples in X that will be used to fit the classifier.
- yarray-like of shape (n_sub_samples), optional (default=None)
Class labels of the training samples corresponding to X[idx]. Missing labels are represented the attribute ‘missing_label’.
- sample_weight: array-like of shape (n_sub_samples), optional
(default=None) Weights of training samples in X[idx].
- use_base_clfbool, default=False
If True, the base classifier will be used to update the fit instead of the current classifier. Here, it is necessary that the base classifier has been set once.
- set_base_clfbool, default=False
If True, the base classifier will be set to the newly fitted classifier.
- Returns
- self: IndexClassifierWrapper,
The fitted IndexClassifierWrapper.
- precompute(idx_fit, idx_pred, fit_params='all', pred_params='all')[source]#
Function to describe for which samples we should precompute something. Will be internally handled differently for different classifiers. The function consists of pairs of idx_fit and idx_predict to describe which sequences of fitting and predicting are to be expected.
- Parameters
- idx_fitarray-like of shape (n_fit_samples)
Indices of samples in X that will be used to fit the classifier.
- idx_predarray-like of shape (n_predict_samples)
Indices of samples in X that the classifier will predict for.
- fit_paramsstring, optional (default=’all’)
Parameter to specify if only a subset of the idx_fit indices will be used later. Can be of value ‘all’, ‘labeled’, or ‘unlabeled’.
- pred_paramsstring, optional (default=’all’)
Parameter to specify if only a subset of the idx_predict indices will be used later. Can be of value ‘all’, ‘labeled’, or ‘unlabeled’.
- predict(idx)[source]#
Return class label predictions for the input data X[idx].
- Parameters
- idxarray-like of shape (n_sub_samples)
Indices of samples in X that are to be predicted.
- Returns
- yarray-like, shape (n_sub_samples)
Predicted class labels of the input samples.
- predict_freq(idx)[source]#
Return class frequency estimates for the input samples ‘X[idx]’.
- Parameters
- idxarray-like of shape (n_sub_samples)
Indices of samples in X that are to be predicted.
- Returns
- F: array-like of shape (n_sub_samples, classes)
The class frequency estimates of the input samples. Classes are ordered according to classes_.
- predict_proba(idx)[source]#
Return probability estimates for the input data X[idx].
- Parameters
- idxarray-like of shape (n_sub_samples)
Indices of samples in X that are to be predicted.
- Returns
- Parray-like, shape (n_sub_samples, classes)
The class probabilities of the input samples. Classes are ordered by lexicographic order.