evaluate_regression#

evaluate_regression(y_true, y_pred, multioutput='uniform_average') → dict[source]#

Errors and explained variance of the predictions of a regressor, with one or several targets.

Parameters:
  • y_true (array-like of shape (n_samples,) or (n_samples, n_targets)) – True values.

  • y_pred (array-like of shape (n_samples,) or (n_samples, n_targets)) – Predicted values.

  • multioutput ({'uniform_average', 'raw_values'} or array-like of shape (n_targets,), default='uniform_average') – With several targets, how the metric of each target is combined, as in sklearn.metrics: the mean, the value of each target (an array), or the mean weighted by the given weights.

Returns:

scores – r2, explained_variance, max_error, mean_absolute_error, mean_squared_error, median_absolute_error, mean_absolute_percentage_error and mean_squared_log_error (nan if some value is negative). With several targets, max_error is the largest error of each target, combined as the other metrics.

Return type:

dict

See also

sklearn.metrics

the definitions of the metrics.

Examples

>>> from sklearn.datasets import load_diabetes
>>> from RuleTree import RuleTreeRegressor
>>> from RuleTree.evaluation import evaluate_regression
>>> X, y = load_diabetes(return_X_y=True)
>>> model = RuleTreeRegressor(max_depth=3, random_state=0).fit(X, y)
>>> round(evaluate_regression(y, model.predict(X))["r2"], 3)
0.501

With two targets, the value of each of them:

>>> import numpy as np
>>> Y = np.column_stack([y, X[:, 2]])
>>> model = RuleTreeRegressor(max_depth=3, random_state=0).fit(X, Y)
>>> evaluate_regression(Y, model.predict(X), multioutput="raw_values")["r2"].round(3)
array([0.501, 0.822])