Skip to content

Update regression.py added root_mean_square_deviation method #7531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions sklearn/metrics/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,60 @@ def mean_squared_error(y_true, y_pred,
return np.average(output_errors, weights=multioutput)


def root_mean_square_deviation(y_true, y_pred,
sample_weight=None,
multioutput='uniform_average'):
"""Root mean squared deviation

Parameters
----------
y_true : array-like of shape = (n_samples) or (n_samples, n_outputs)
Ground truth (correct) target values.

y_pred : array-like of shape = (n_samples) or (n_samples, n_outputs)
Estimated target values.

sample_weight : array-like of shape = (n_samples), optional
Sample weights.

multioutput : string in ['raw_values', 'uniform_average']
or array-like of shape (n_outputs)
Defines aggregating of multiple output values.
Array-like value defines weights used to average errors.

'raw_values' :
Returns a full set of errors in case of multioutput input.

'uniform_average' :
Errors of all outputs are averaged with uniform weight.

Returns
-------
loss : float or ndarray of floats
A non-negative floating point value (the best value is 0.0), or an
array of floating point values, one for each individual target.

Examples
--------
>>> from sklearn.metrics import root_mean_squared_deviation
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> root_mean_squared_deviation(y_true, y_pred)
0.612...
>>> y_true = [[0.5, 1],[-1, 1],[7, -6]]
>>> y_pred = [[0, 2],[-1, 2],[8, -5]]
>>> root_mean_squared_deviation(y_true, y_pred) # doctest: +ELLIPSIS
0.841...
>>> root_mean_squared_deviation(y_true, y_pred, multioutput='raw_values')
... # doctest: +ELLIPSIS
array([ 0.64549722, 1. ])
>>> root_mean_squared_deviation(y_true, y_pred, multioutput=[0.3, 0.7])
... # doctest: +ELLIPSIS
0.908...
"""

return np.sqrt(mean_squared_error(y_true, y_pred, sample_weight, multioutput))

def median_absolute_error(y_true, y_pred):
"""Median absolute error regression loss

Expand Down