mojolearn.CalibratedClassifierCV#
- class mojolearn.CalibratedClassifierCV(estimator=None, *, method='sigmoid', cv=None, n_jobs=None, ensemble=True)[source]#
Bases:
_TreesWrapperBaseCalibrate a classifier’s probabilities with cross-validation.
Follows scikit-learn’s
CalibratedClassifierCV. The calibrator reads the estimator’sdecision_function, else itspredict_proba(the positive column for a binary problem), and fits one calibrator per class (one-vs-rest): Platt’s sigmoid or isotonic regression (clipped outside the fitted range). Multiclass probabilities are normalized per row; a row of zeros becomes uniform. The folds fit one after another.Differs from scikit-learn: Platt’s sigmoid minimizes scikit-learn’s objective with Newton steps and a backtracking line search instead of L-BFGS, so its parameters can differ in the last digits.
- Parameters:
estimator (estimator, default None) – The mojolearn classifier to calibrate; it is cloned, never fitted in place. None uses
LinearSVC(), as scikit-learn does.method ({“sigmoid”, “isotonic”}, default “sigmoid”) – Platt’s sigmoid or isotonic regression. Any other value raises
ValueError.cv (int, splitter or iterable of (train, test), default None) – An int is the number of unshuffled stratified folds (
>= 2); None means 5. A splitter object’ssplit(X, y)or an iterable of index pairs is used as given; withensemble=Falsetheir test sets must cover every row exactly once, elseValueError.n_jobs (None) – Only None is accepted; any other value raises
NotImplementedError.ensemble (bool, default True) – True: one (classifier, calibrators) pair per fold, the classifier fitted on the fold’s training rows and calibrated on its test rows;
predict_probaaverages the pairs. False: one set of calibrators fitted on the out-of-fold scores, and the classifier refitted on all rows. Values other than True or False raiseNotImplementedError.
- Variables:
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 8), dtype=np.float32) >>> y = (X[:, 0] + 0.2 * rng.random(1000) > 0.6).astype(np.int32) >>> model = mojolearn.CalibratedClassifierCV(mojolearn.GaussianNB(), cv=3).fit(X, y) >>> model.predict_proba(X[:5]).shape (5, 2)
Methods
fit(X, y[, sample_weight])Fit the classifier and its calibrators over the cross-validation folds.
get_params([deep])numeric_mode_used()The numeric mode this estimator runs in.
predict(X)Predict the class with the highest calibrated probability.
Calibrated class probabilities.
set_params(**params)Set constructor parameters.
vendor_used()The GPU backend this estimator runs on.
- fit(X, y, sample_weight=None)[source]#
Fit the classifier and its calibrators over the cross-validation folds.
- Parameters:
X (array of shape (n_samples, n_features)) – Training data, converted to float32.
y (array of shape (n_samples,)) – Class labels; fewer than two classes raise
ValueError.sample_weight (None) – Only None is accepted; weights raise
NotImplementedError.
- Returns:
self
- Raises:
ValueError – When
cvasks for more folds than some class has members.