-
Notifications
You must be signed in to change notification settings - Fork 68
Stop using sklearn's private _scorer API for custom metrics in SKLL.
#751
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
Conversation
- Move all custom pre-defined metrics to `_PREDEFINED_CUSTOM_METRICS` dictionary in `metrics.py`. - Make a copy of the above dictionary as `CUSTOM _METRICS`. This dictionary will be the source of all custom metrics: pre-defined and user-definqed. - We need two dictionaries because at some points in the code, we need to be able to differentiate between pre-defined custom metrics and user-defined custom metrics. - Remove any use of `sklearn.metrics._scorer` private API and use `sklearn.metrics.get_scorer()` and `sklearn.metrics.get_scorer_names()` instead. - Use the actual metric function when using custom metrics instead of its name. This is the core change that makes everything work since sklearn validates callables but does not validate custom metric name strings.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #751 +/- ##
==========================================
+ Coverage 95.24% 95.30% +0.05%
==========================================
Files 29 29
Lines 3578 3576 -2
==========================================
Hits 3408 3408
+ Misses 170 168 -2
☔ View full report in Codecov by Sentry. |
Frost45
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to suggest a couple of changes to the custom_metrics documentation:
- Fix indentation in custom.py. There are a few spaces at the start of every line.
- Change
logtologsin the config file on the same page. Otherwise, you get a KeyError.
Frost45
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Tested it out with multiple custom metrics.
|
Tests passed for me just now. Will review shortly. |
Co-authored-by: Matt Mulholland <mulhodm@gmail.com>
_PREDEFINED_CUSTOM_METRICSdictionary inmetrics.py.CUSTOM _METRICS. This dictionary will be the source of all custom metrics: pre-defined and user-defined.sklearn.metrics._scorerprivate API and usesklearn.metrics.get_scorer()andsklearn.metrics.get_scorer_names()instead._SCORERSand fix a minor bug in another test related to scikit-learn v1.3.0.This PR closes #748 and closes #750.
To review this PR, please try to create some custom metrics for both the titanic and California examples and try to use them via both the API and the configuration file.