Class: CalibratedClassifierCV
Probability calibration with isotonic regression or logistic regression.
This class uses cross-validation to both estimate the parameters of a classifier and subsequently calibrate a classifier. With default ensemble=True
, for each cv split it fits a copy of the base estimator to the training subset, and calibrates it using the testing subset. For prediction, predicted probabilities are averaged across these individual calibrated classifiers. When ensemble=False
, cross-validation is used to obtain unbiased predictions, via cross_val_predict
, which are then used for calibration. For prediction, the base estimator, trained using all the data, is used. This is the prediction method implemented when probabilities=True
for SVC
and NuSVC
estimators (see User Guide for details).
Already fitted classifiers can be calibrated via the parameter cv="prefit"
. In this case, no cross-validation is used and all provided data is used for calibration. The user has to take care manually that data for model fitting and calibration are disjoint.
The calibration is based on the decision_function method of the estimator
if it exists, else on predict_proba.
Read more in the User Guide. In order to learn more on the CalibratedClassifierCV class, see the following calibration examples: Probability calibration of classifiers, Probability Calibration curves, and Probability Calibration for 3-class classification.
Constructors
new CalibratedClassifierCV()
new CalibratedClassifierCV(
opts
?):CalibratedClassifierCV
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.cv ? | number | "prefit" | Determines the cross-validation splitting strategy. Possible inputs for cv are: |
opts.ensemble ? | boolean | Determines how the calibrator is fitted when cv is not 'prefit' . Ignored if cv='prefit' . If true , the estimator is fitted using training data, and calibrated using testing data, for each cv fold. The final estimator is an ensemble of n_cv fitted classifier and calibrator pairs, where n_cv is the number of cross-validation folds. The output is the average predicted probabilities of all pairs. If false , cv is used to compute unbiased predictions, via cross_val_predict , which are then used for calibration. At prediction time, the classifier used is the estimator trained on all the data. Note that this method is also internally implemented in sklearn.svm estimators with the probabilities=True parameter. |
opts.estimator ? | any | The classifier whose output need to be calibrated to provide more accurate predict_proba outputs. The default classifier is a LinearSVC . |
opts.method ? | "sigmoid" | "isotonic" | The method to use for calibration. Can be ‘sigmoid’ which corresponds to Platt’s method (i.e. a logistic regression model) or ‘isotonic’ which is a non-parametric approach. It is not advised to use isotonic calibration with too few calibration samples (<<1000) since it tends to overfit. |
opts.n_jobs ? | number | Number of jobs to run in parallel. undefined means 1 unless in a joblib.parallel_backend context. \-1 means using all processors. Base estimator clones are fitted in parallel across cross-validation iterations. Therefore parallelism happens only when cv != "prefit" . See Glossary for more details. |
Returns CalibratedClassifierCV
Defined in generated/calibration/CalibratedClassifierCV.ts:29
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/calibration/CalibratedClassifierCV.ts:27 |
_isInitialized | boolean | false | generated/calibration/CalibratedClassifierCV.ts:26 |
_py | PythonBridge | undefined | generated/calibration/CalibratedClassifierCV.ts:25 |
id | string | undefined | generated/calibration/CalibratedClassifierCV.ts:22 |
opts | any | undefined | generated/calibration/CalibratedClassifierCV.ts:23 |
Accessors
calibrated_classifiers_
Get Signature
get calibrated_classifiers_():
Promise
<number
>
The list of classifier and calibrator pairs.
Returns Promise
<number
>
Defined in generated/calibration/CalibratedClassifierCV.ts:514
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
The class labels.
Returns Promise
<ArrayLike
>
Defined in generated/calibration/CalibratedClassifierCV.ts:433
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Only defined if the underlying estimator exposes such an attribute when fit.
Returns Promise
<ArrayLike
>
Defined in generated/calibration/CalibratedClassifierCV.ts:487
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit. Only defined if the underlying estimator exposes such an attribute when fit.
Returns Promise
<number
>
Defined in generated/calibration/CalibratedClassifierCV.ts:460
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/calibration/CalibratedClassifierCV.ts:71
Methods
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/calibration/CalibratedClassifierCV.ts:127
fit()
fit(
opts
):Promise
<any
>
Fit the calibrated model.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.fit_params ? | any | Parameters to pass to the fit method of the underlying classifier. |
opts.sample_weight ? | ArrayLike | Sample weights. If undefined , then samples are equally weighted. |
opts.X ? | ArrayLike [] | Training data. |
opts.y ? | ArrayLike | Target values. |
Returns Promise
<any
>
Defined in generated/calibration/CalibratedClassifierCV.ts:144
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRouter encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/calibration/CalibratedClassifierCV.ts:195
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/calibration/CalibratedClassifierCV.ts:84
predict()
predict(
opts
):Promise
<ArrayLike
>
Predict the target of new samples.
The predicted class is the class that has the highest probability, and can thus be different from the prediction of the uncalibrated classifier.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The samples, as accepted by estimator.predict . |
Returns Promise
<ArrayLike
>
Defined in generated/calibration/CalibratedClassifierCV.ts:233
predict_proba()
predict_proba(
opts
):Promise
<ArrayLike
[]>
Calibrated probabilities of classification.
This function returns calibrated probabilities of classification according to each class on an array of test vectors X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The samples, as accepted by estimator.predict_proba . |
Returns Promise
<ArrayLike
[]>
Defined in generated/calibration/CalibratedClassifierCV.ts:271
score()
score(
opts
):Promise
<number
>
Return the mean accuracy on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. |
opts.y ? | ArrayLike | True labels for X . |
Returns Promise
<number
>
Defined in generated/calibration/CalibratedClassifierCV.ts:309
set_fit_request()
set_fit_request(
opts
):Promise
<any
>
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/calibration/CalibratedClassifierCV.ts:357
set_score_request()
set_score_request(
opts
):Promise
<any
>
Request metadata passed to the score
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in score . |
Returns Promise
<any
>
Defined in generated/calibration/CalibratedClassifierCV.ts:397