EstimatorReport#

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

Report for a fitted estimator.

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

Refer to the Reporter for a single estimator section of the user guide for more details.

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)

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

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

Testing target.

pos_labelint, float, bool or str, default=None

For binary classification, the positive class to use for metrics and displays that need one. If None, skore does not infer a default positive class. Binary metrics and displays that support it will expose all classes instead. This parameter is rejected for non-binary tasks.

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.CrossValidationReport

Report of cross-validation results.

skore.ComparisonReport

Report of comparison between estimators.

Examples

>>> from sklearn.datasets import make_classification
>>> from skore import train_test_split
>>> from sklearn.linear_model import LogisticRegression
>>> X, y = make_classification(random_state=42)
>>> split_data = train_test_split(X=X, y=y, random_state=42, as_dict=True)
>>> estimator = LogisticRegression()
>>> from skore import EstimatorReport
>>> report = EstimatorReport(estimator, **split_data)
add_checks(checks)[source]#

Register additional diagnostic checks for this report.

Checks are defined by implementing the Check protocol.

Appends the given checks to the registry used by diagnose(). The next call to diagnose() runs any newly added checks (along with checks that have not yet been cached). Already-run built-in checks are not re-executed.

Parameters:
checkslist of Check

Additional checks to register

cache_predictions(data_source='both')[source]#

Cache estimator’s predictions.

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

The data source(s) for which to precompute predictions.

  • “test” : cache predictions for the test set only.

  • “train” : cache predictions for the train set only.

  • “both” : cache predictions for both train and test sets when available.

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.linear_model import LogisticRegression
>>> from skore import train_test_split
>>> from skore import EstimatorReport
>>> X, y = load_breast_cancer(return_X_y=True)
>>> split_data = train_test_split(X=X, y=y, random_state=0, as_dict=True)
>>> classifier = LogisticRegression(max_iter=10_000)
>>> report = EstimatorReport(classifier, **split_data)
>>> report.cache_predictions()
>>> report._cache
{...}
clear_cache()[source]#

Clear the cache.

Examples

>>> from sklearn.datasets import load_breast_cancer
>>> from sklearn.linear_model import LogisticRegression
>>> from skore import train_test_split
>>> from skore import EstimatorReport
>>> X, y = load_breast_cancer(return_X_y=True)
>>> split_data = train_test_split(X=X, y=y, random_state=0, as_dict=True)
>>> classifier = LogisticRegression(max_iter=10_000)
>>> report = EstimatorReport(classifier, **split_data)
>>> report.cache_predictions()
>>> report.clear_cache()
>>> report._cache
{}
diagnose(*, ignore=None)[source]#

Run checks and return a diagnostic with detected issues.

Checks look for common modeling problems such as overfitting and underfitting. Check codes can be muted per-call via ignore or globally via configuration() with ignore_checks=....

Parameters:
ignorelist of str or tuple of str or None, default=None

Check codes to exclude from the results, e.g. ["SKD001"].

Returns:
DiagnosticDisplay

A display object with an HTML representation, with the full list of detected issues accessible via the frame() method.

Examples

>>> from skore import evaluate
>>> from sklearn.dummy import DummyClassifier
>>> from sklearn.datasets import make_classification
>>> X, y = make_classification(random_state=42)
>>> report = evaluate(DummyClassifier(), X, y, splitter=0.2)
>>> report.diagnose()
Diagnostic: 1 issue(s) detected, 2 check(s) ran, 0 ignored.
- [SKD002] Potential underfitting.
...
>>> report.diagnose(ignore=["SKD002"])
Diagnostic: 0 issue(s) detected, 1 check(s) ran, 1 ignored.
- No issues were detected in your report!
classmethod from_state(state)[source]#

Rebuild a report from get_state() output.

get_predictions(*, data_source, response_method='predict')[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”}, 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.

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

The response method to use to get the predictions.

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 skore import train_test_split
>>> from sklearn.linear_model import LogisticRegression
>>> X, y = make_classification(random_state=42)
>>> split_data = train_test_split(X=X, y=y, random_state=42, as_dict=True)
>>> estimator = LogisticRegression()
>>> from skore import EstimatorReport
>>> report = EstimatorReport(estimator, **split_data)
>>> predictions = report.get_predictions(data_source="test")
>>> predictions.shape
(25,)
get_state()[source]#

Return a serializable representation of the report state.

This state is meant to ease serialization/deserialization of reports while preserving some backward compatibility across skore versions. In particular, this is more stable than pickling a report object directly, which can break when internal implementations change.

help()[source]#

Display report help using rich or HTML.