Repository navigation
[WIP] [POC] FEA public objective function methods in estimators - #28505
jeremiedbb wants to merge 7 commits into
Conversation
ogrisel
left a comment
There was a problem hiding this comment.
I put it in sklearn.base for now but open to suggestions.
I think it's fine this way.
Overall, I think the design look good but I am not sure what to do of this PR in the short term. It's good to have a concrete proof of concept to help back the redaction of a SLEP on this extension to the public estimator API of scikit-learn.
I think however that it would be worth doing the same exercise for at least a few unrelated estimators (e.g. LogisticRegression, DecisionTreeClassifier, HistGradientBoostingClassifier) to check that the design hold in a generic enough way. I don't know if it's best to draft those as part of this PR or in dedicated draft PRs targeting this one (to reuse the base dataclass) or using a feature branch to host additional common elements shall the need arise?
Some more inline feedback below.
|
|
||
| normalized : bool | ||
| Whether each term and the total value of the objective function is | ||
| per-sample or not. |
There was a problem hiding this comment.
Are there cases where we want normalized=False? Maybe for backward compat with existing objective functions such as KMeans' inertia? I general I think we should always use per-sample normalization to make those values easier to interpret.
There was a problem hiding this comment.
Personally I always normalize the objective function, and I would not even add this parameter here.
The reason I added it is that usually in the literature and even in our docstrings and user guides the formula of the objective function is not normalized, so I thought that it might be less confusing for some people. (although they just have to multiply by n_samples).
If we're all on the same page, I'd be in favor of not having the param and always normalize.
There was a problem hiding this comment.
I suppose that if the docstring is explicit enough, it's fine to always normalize by sample size.
| + alpha_H * l1_ratio * n_samples * H.sum() | ||
| + 0.5 * alpha_W * (1 - l1_ratio) * n_features * (W**2).sum() | ||
| + 0.5 * alpha_H * (1 - l1_ratio) * n_samples * (H**2).sum() | ||
| ) |
There was a problem hiding this comment.
Ideally, one might also want to check that the objective function is actually monotonically decreasing at each iteration but this kind of tests would only be easy to write once we have the callbacks API.
There was a problem hiding this comment.
We'll be able to add such tests easily when we have the callbacks
I'm starting to work on that to have a better overview |
towards #28169
Not sure where to put the
ObjectiveFunctiondataclass. I put it in sklearn.base for now but open to suggestions.The design is not final. This PR is there to help discussing the design in the linked issue #28169 where discussion regarding the general design of this API should be discussed.