EstimatorReport#

class skore.EstimatorReport(estimator, *, fit='auto', X_train=None, y_train=None, X_test=None, y_test=None)[source]#

Report for a fitted estimator.

This class provides a set of tools to quickly validate and inspect a scikit-learn compatible estimator.

Parameters:
estimatorestimator object

Estimator to make the report from. When the estimator is not fitted, it is deep-copied to avoid side-effects. If it is fitted, it is cloned instead.

fit{“auto”, True, False}, default=”auto”

Whether to fit the estimator on the training data. If “auto”, the estimator is fitted only if the training data is provided.

X_train{array-like, sparse matrix} of shape (n_samples, n_features) or None

Training data.

y_trainarray-like of shape (n_samples,) or (n_samples, n_outputs) or None

Training target.

X_test{array-like, sparse matrix} of shape (n_samples, n_features) or None

Testing data. It should have the same structure as the training data.

y_testarray-like of shape (n_samples,) or (n_samples, n_outputs) or None

Testing target.

Attributes:
estimator_estimator object

The cloned or copied estimator.

estimator_name_str

The name of the estimator.

fit_time_float or None

The time taken to fit the estimator, in seconds. If the estimator is not internally fitted, the value is None.

See also

skore.sklearn.cross_validation.report.CrossValidationReport

Report of cross-validation results.

Examples

>>> from sklearn.datasets import make_classification
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import LogisticRegression
>>> X, y = make_classification(random_state=42)
>>> X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
>>> estimator = LogisticRegression().fit(X_train, y_train)
>>> from skore import EstimatorReport
>>> report = EstimatorReport(estimator, X_test=X_test, y_test=y_test)
cache_predictions(response_methods='auto', n_jobs=None)[source]#

Cache estimator’s predictions.

Parameters:
response_methods“auto” or list of str, default=”auto”

The response methods to precompute. If “auto”, the response methods are inferred from the ml task: for classification we compute the response of the predict_proba, decision_function and predict methods; for regression we compute the response of the predict method.

n_jobsint or None, default=None

The number of jobs to run in parallel. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.model_selection import train_test_split
>>> from skore import EstimatorReport
>>> X_train, X_test, y_train, y_test = train_test_split(
...     *load_breast_cancer(return_X_y=True), random_state=0
... )
>>> classifier = LogisticRegression(max_iter=10_000)
>>> report = EstimatorReport(
...     classifier,
...     X_train=X_train,
...     y_train=y_train,
...     X_test=X_test,
...     y_test=y_test,
... )
>>> report.cache_predictions()
>>> report._cache
{...}
clear_cache()[source]#

Clear the cache.

Note that the cache might not be empty after this method is run as some values need to be kept, such as the fit time.

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.model_selection import train_test_split
>>> from skore import EstimatorReport
>>> X_train, X_test, y_train, y_test = train_test_split(
...     *load_breast_cancer(return_X_y=True), random_state=0
... )
>>> classifier = LogisticRegression(max_iter=10_000)
>>> report = EstimatorReport(
...     classifier,
...     X_train=X_train,
...     y_train=y_train,
...     X_test=X_test,
...     y_test=y_test,
... )
>>> report.cache_predictions()
>>> report.clear_cache()
>>> report._cache
{}
feature_importance[source]#

alias of _FeatureImportanceAccessor

get_predictions(*, data_source, response_method, X=None, pos_label=None)[source]#

Get estimator’s predictions.

This method has the advantage to reload from the cache if the predictions were already computed in a previous call.

Parameters:
data_source{“test”, “train”, “X_y”}, default=”test”

The data source to use.

  • “test” : use the test set provided when creating the report.

  • “train” : use the train set provided when creating the report.

  • “X_y” : use the provided X and y to compute the metric.

response_method{“predict”, “predict_proba”, “decision_function”}

The response method to use.

Xarray-like of shape (n_samples, n_features), optional

When data_source is “X_y”, the input features on which to compute the response method.

pos_labelint, float, bool or str, default=None

The positive class when it comes to binary classification. When response_method="predict_proba", it will select the column corresponding to the positive class. When response_method="decision_function", it will negate the decision function if pos_label is different from estimator.classes_[1].

Returns:
np.ndarray of shape (n_samples,) or (n_samples, n_classes)

The predictions.

Raises:
ValueError

If the data source is invalid.

Examples

>>> from sklearn.datasets import make_classification
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import LogisticRegression
>>> X, y = make_classification(random_state=42)
>>> X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
>>> estimator = LogisticRegression().fit(X_train, y_train)
>>> from skore import EstimatorReport
>>> report = EstimatorReport(estimator, X_test=X_test, y_test=y_test)
>>> predictions = report.get_predictions(
...     data_source="test", response_method="predict"
... )
>>> predictions.shape
(25,)
help()[source]#

Display available methods using rich.

metrics[source]#

alias of _MetricsAccessor