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
[BUG] make_forecasting_scorer
fails for wrapped sklearn
metrics on newer sklearn
versions
#5715
Comments
Confirmed on current main, python 3.11, windnows. It seems like the bug is caused by In custom metrics, arguments of the class are passed to to the metric, if and only if the signature of the matric accepts it. The problem is that the signanture of The solution would be to control more stringently what |
The horror comes in through this decorator in @validate_params(
{
"y_true": ["array-like"],
"y_pred": ["array-like"],
"sample_weight": ["array-like", None],
"multioutput": [StrOptions({"raw_values", "uniform_average"}), "array-like"],
},
prefer_skip_nested_validation=True,
)
def mean_absolute_error(
y_true, y_pred, *, sample_weight=None, multioutput="uniform_average"
): Due to the decorator, it is no longer easy to parse which arguments the function accepts, e.g., |
minimal example: import pandas as pd
from sklearn.metrics import mean_absolute_error
from sktime.performance_metrics.forecasting import make_forecasting_scorer
scorer = make_forecasting_scorer(mean_absolute_error, name="RMSLE")
scorer.evaluate(pd.Series([1, 2, 3]), pd.Series([1, 2, 4])) |
make_forecasting_scorer
fails for wrapped sklearn
metrics on newer sklearn
versions
Fixed here: I consider the fix problematic, as it reads out private attributes of the A big question would be, is there a programmatic, public, stable way to ask an |
I see. Thanks for working so quickly on the fix. |
Understanding of the bug also suggests a temp workaround - use a wrapped ("de-decorated") def mean_absolute_error(y_true, y_pred, sample_weight, multioutput):
from sklearn.metrics import mean_absolute_error as _mae
return _mae(y_true, y_pred, sample_weight, multioutput) |
If I may ask, can you please tell what is the issue here? The keys of the decorator first argument and parameters in function definition look identical to me. There is no (I haven't seen sktime or sklearn code, asking just from noticing this issue.) |
@yarnabrina, the decorator Naive inspection fails (via For interface uniformity, we require that all metrics potentially accept things like But that condition is no longer valid, since with the decorator, |
…cs (#5717) Fixes #5715. The issue with `sklearn` metrics is coming from their decorator which no longer allows inspection of admissible arguments via `python` native `sigature`. Question for reviewers: is there an `sklearn` native way to inspect permissible signature, without reading private attriutes?
Describe the bug
The
evaluate
function fails with using a custom metric converted from sklearn using make_forecasting_scorer.To Reproduce
(I know mean_absolute_error is also present in sktime's API but that's beyond the point)
Results in:
Expected behavior
No error, and results for the mean_absolute_error metric.
Additional context
Versions
System:
python: 3.11.6 (tags/v3.11.6:8b6ee5b, Oct 2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)]
executable: C:\repos\ATOM\venv311\Scripts\python.exe
machine: Windows-10-10.0.22621-SP0
Python dependencies:
pip: 23.3.2
sktime: 0.25.0
sklearn: 1.3.2
skbase: 0.6.1
numpy: 1.26.3
scipy: 1.11.4
pandas: 2.1.4
matplotlib: 3.8.2
joblib: 1.3.2
numba: 0.58.1
statsmodels: 0.14.0
pmdarima: 2.0.4
statsforecast: 1.6.0
tsfresh: None
tslearn: None
torch: 2.1.1+cpu
tensorflow: 2.15.0
tensorflow_probability: None
The text was updated successfully, but these errors were encountered: