Skip to content

score


method score(X, y, metric=None, sample_weights=None, verbose=None) [source]

Get a metric score on unseen 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 a trainer, the best model in the pipeline (under the winner attribute) is used. If called from a model, that model is used.

Parameters:

X: dataframe-like
Feature set with shape=(n_samples, n_features).

y: int, str or sequence
  • If int: Position of the target column in X.
  • If str: Name of the target column in X.
  • Else: Target column with shape=(n_samples,).

metric: str, func, scorer or None, optional (default=None)
Metric to calculate. Choose from any of sklearn's SCORERS, a function with signature metric(y_true, y_pred) or a scorer object. If None, it returns mean accuracy for classification tasks and r2 for regression tasks.

sample_weights: sequence or None, optional (default=None)
Sample weights corresponding to y.

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

Returns: np.float64
Metric score of X with respect to y.

Info

If the metric parameter is left to its default value, the method outputs the same value as sklearn's score method for an estimator.

Note

This method is intended to calculate metric scores on new data. To get the metric results on the train or test set, use the evaluate method.


Example

from atom import ATOMClassifier

atom = ATOMClassifier(X, y)
atom.run(["MNB", "KNN", "kSVM"], metric="precision")

# Get the mean accuracy on new data
predictions = atom.mnb.score(X_new, y_new)
Back to top