[go: nahoru, domu]

Skip to content
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

RMSLE (root mean squared log error) #20326

Merged
merged 22 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions doc/whats_new/v1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ Changelog
:func:`~sklearn.utils.check_array` in 1.0 and will raise a `TypeError` in
1.2. :pr:`20165` by `Thomas Fan`_.

:mod: `sklearn.metrics`
.........................
- |Feature| :func:`~sklearn.metrics.mean_square_log_error` now supports
`squared='False'`. :pr:`20322` by :user: `Uttam kumar <helper-uttam>`.
helper-uttam marked this conversation as resolved.
Show resolved Hide resolved

Code and Documentation Contributors
-----------------------------------

Expand Down
16 changes: 15 additions & 1 deletion sklearn/metrics/_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# Konstantin Shmelkov <konstantin.shmelkov@polytechnique.edu>
# Christian Lorentzen <lorentzen.ch@googlemail.com>
# Ashutosh Hathidara <ashutoshhathidara98@gmail.com>
# Uttam kumar <bajiraouttamsinha@gmail.com>
# License: BSD 3 clause

import numpy as np
Expand Down Expand Up @@ -437,7 +438,7 @@ def mean_squared_error(


def mean_squared_log_error(
y_true, y_pred, *, sample_weight=None, multioutput="uniform_average"
y_true, y_pred, *, sample_weight=None, multioutput="uniform_average", squared=True
):
"""Mean squared logarithmic error regression loss.

Expand Down Expand Up @@ -467,6 +468,10 @@ def mean_squared_log_error(
'uniform_average' :
Errors of all outputs are averaged with uniform weight.

'squared' : bool, default=True
If True returns MSLE(mean squared log error) value.
If False returns RMSLE(root mean squared log error) value.
helper-uttam marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
loss : float or ndarray of floats
Expand All @@ -480,14 +485,22 @@ def mean_squared_log_error(
>>> y_pred = [2.5, 5, 4, 8]
>>> mean_squared_log_error(y_true, y_pred)
0.039...
>>> mean_squared_log_error(y_true, y_pred, squared=False)
0.199...
>>> y_true = [[0.5, 1], [1, 2], [7, 6]]
>>> y_pred = [[0.5, 2], [1, 2.5], [8, 8]]
>>> mean_squared_log_error(y_true, y_pred)
0.044...
>>> mean_squared_log_error(y_true, y_pred, squared=False)
0.210...
>>> mean_squared_log_error(y_true, y_pred, multioutput='raw_values')
array([0.00462428, 0.08377444])
>>> mean_squared_log_error(y_true, y_pred, multioutput='raw_values',squared=False)
array([0.06800207, 0.28943815]))
ogrisel marked this conversation as resolved.
Show resolved Hide resolved
>>> mean_squared_log_error(y_true, y_pred, multioutput=[0.3, 0.7])
0.060...
>>> mean_squared_log_error(y_true, y_pred, multioutput=[0.3, 0.7], squared=False)
0.245...
"""
y_type, y_true, y_pred, multioutput = _check_reg_targets(
y_true, y_pred, multioutput
Expand All @@ -505,6 +518,7 @@ def mean_squared_log_error(
np.log1p(y_pred),
sample_weight=sample_weight,
multioutput=multioutput,
squared=squared,
)


Expand Down