ENH: `_parameter_constraints` and `_fit_context` for base estimator classes

Open
#141 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Active
Tech stack
python

Research direction

This is a design discussion, not a ready task: the issue itself says it requires investigation into how scikit-learn's _parameter_constraints and _fit_context decorator work and how they would be tested here. Start by reading the referenced Emma PR upstream in sklearn and the linked comment (issuecomment-6375401621), then survey the base estimator classes in this repo to see where fit/partial_fit validation would hook in. Done means an agreed design (ideally in this thread) before any patch is attempted.

Written by the indexing model from the issue text.

Description

enhancement

In Emma's PR at sklearn, we define a parameter constraints dictionary that the sklearn test suite uses to see if the parameters for fit and partial_fit meet standards.

I'm opening this task/discussion if we wanted such a feature for this repo. This would require some work to review/investigate exactly how these are used and how to test them.

The example of _parameter_constraints is below and is usually right under the class YourEstimator() and before def __init__ in many, many sklearn estimators.

    _parameter_constraints: dict = {
        "hidden_layer_sizes": ["array-like"],
        "activation": [
            StrOptions(
                {
                    "identity",
                    "tanh",
                    "relu",
                    "logistic",
                    "softmax",
                    "softmin",
                    "log_sigmoid",
                    "log_softmax",
                }
            )
        ],
### other attributes with constraints defined
###
###
    }

And you usually put the decorator like below:

    @_fit_context(prefer_skip_nested_validation=True)
    def fit(self, X, y):

See comment below https://github.com/lanl/GFDL/issues/141#issuecomment-6375401621

Dominant language
Python
Stars
3
Forks
6
Avg merge
1d 3h
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lanl/GFDL

All issues in lanl/GFDL

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.