Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make it possible to specify monotonic_cst with feature names in all tree-based estimators #28850

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

Closed
alxhslm opened this issue Apr 16, 2024 · 1 comment
Labels
Needs Triage Issue requires triage New Feature

Comments

@alxhslm
Copy link

alxhslm commented Apr 16, 2024

Describe the workflow you want to enable

Instead of passing an array of monotonicity constraints (-1 for a decrease constraint, +1 for an increase constraint or 0 for no constraint) specified by feature positions in the training set, it would be more convenient to pass a dict to pass constraints spec only for the required feature names. For instance

from sklearn.datasets import load_diabetes
from sklearn.ensemble import RandomForestRegressor

X, y = load_diabetes(return_X_y=True, as_frame=True)

reg = RandomForestRegressor(
    monotonic_cst={"bmi": +1, "s3": -1}
)
reg.fit(X, y)

Not that here X has column names because it is a pd.DataFrame.

Note that this already supported for HistGradientBoostingRegressor. Ideally this would be supported across all tree-based models for consistency.

Describe your proposed solution

Use the _check_monotonic_cst function to validate the monotonic_cst argument in all estimators.

Describe alternatives you've considered, if relevant

This has already been implemented for HistGradientBoostingRegressor in #24855.

Additional context

See #24855 for the implementation of this for HistGradientBoostingRegressor.

@alxhslm alxhslm added Needs Triage Issue requires triage New Feature labels Apr 16, 2024
@alxhslm alxhslm changed the title Make it possible to specify interaction_cst and monotonic_cst with feature names in all tree-based estimators Make it possible to specify monotonic_cst with feature names in all tree-based estimators Apr 16, 2024
@adrinjalali
Copy link
Member

I don't think we'd be adding this for all tree based models. But we'll be moving HistGradientBoosting under general GradientBoosting most probably. (#27873)

cc @adam2392 @lorentzenchr @glemaitre

@adrinjalali adrinjalali closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Triage Issue requires triage New Feature
Projects
None yet
Development

No branches or pull requests

2 participants