Skip to content

score


method score(X, y=None, metric=None, sample_weight=None, verbose=None)[source]
Get a metric score on new data.

New data is first transformed through the model's pipeline. Transformers that are only applied on the training set are skipped. If called from atom, the best model (under the winner attribute) is used. If called from a model, that model is used.

Read more in the user guide.

Info

If the metric parameter is left to its default value, the method returns atom's metric score, not the metric returned by sklearn's score method for estimators.

ParametersX: int, str, slice, sequence or dataframe-like
Names or indices of rows in the dataset, or new feature set with shape=(n_samples, n_features).

y: int, str or sequence
Target column corresponding to X. - If int: Position of the target column in X. - If str: Name of the target column in X. - Else: Array with shape=(n_samples,) to use as target.

metric: str, func, scorer or None, default=None
Metric to calculate. Choose from any of sklearn's scorers, a function with signature metric(y_true, y_pred) -> score or a scorer object. If None, it uses atom's metric (the main metric for multi-metric runs).

sample_weight: sequence or None, default=None
Sample weights corresponding to y.

verbose: int or None, default=None
Verbosity level of the output. If None, it uses the transformer's own verbosity.

Returnsfloat
Metric score of X with respect to y.

Example

>>> from atom import ATOMClassifier
>>> from sklearn.datasets import load_breast_cancer

>>> # Load data and separate last 5 rows for predictions
>>> X, y = load_breast_cancer(return_X_y=True, as_frame=True)
>>> X_new, y_new = X.iloc[-5:], y.iloc[-5:]
>>> X, y = X.iloc[:-5], y.iloc[:-5]

>>> atom = ATOMClassifier(data)
>>> atom.run("LR", metric="f1")

>>> # Using new data
>>> atom.score(X_new, y_new)

1.0

>>> # Using indices
>>> atom.score(slice(10, 92))

0.975609756097561

>>> # Using a custom metric
>>> atom.score(slice(10, 92))

0.9824561403508771  # f1 score