Skip to content

Added a new method to specify monotonicity constraints using dict of feature names in HistGradientBoostingClassifier/Regressor. Fixes #21961 - #21962

Closed
Anirudhsekar96 wants to merge 3 commits into
scikit-learn:mainfrom
Anirudhsekar96:monotonic_cst_dict
Closed

Anirudhsekar96 wants to merge 3 commits into
scikit-learn:mainfrom
Anirudhsekar96:monotonic_cst_dict

Conversation

@Anirudhsekar96

Copy link
Copy Markdown

Added a new method to specify monotonicity constraints using dict of feature names in HistGradientBoostingClassifier/Regressor.

Reference Issues/PRs

Fixes #21961

What does this implement/fix? Explain your changes.

This implementation adds a method to specify the monotonicity constraints for HistGradientBoostingClassifier and Regressor.

Changes:

  • sklearn/ensemble/_hist_gradient_boosting/grower.py
    • Added function to read a dict and generate an array-like representation of the constraints.
    • Changed docstring to accommodate accepting dict as a valid input type.
    • Added validation checks to verify if input X is a dataframe type and has string columns
  • sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py:
    • Added function to obtain column names for input X
    • Added parameter to pass the column names to grower.py
  • sklearn/ensemble/_hist_gradient_boosting/tests/test_monotonic_contraints.py:
    • Added tests
  • doc/modules/ensemble.rst:
    • Added documentation for accepting constraints as dict

Any other comments?

@ogrisel

ogrisel commented Dec 13, 2021 •

Copy link
Copy Markdown
Member

I agree with the expressed need, however I am not sure how we should do it taking into account the bigger picture on the way we want to deal with feature names in scikit-learn.

In particular the design of this improvement interacts was is currently being discussed in #18894 about how to specify categorical variables in a pipeline with an OrdinalEncoder in charge of converting category string labels into integer identifiers.

There will also be a related need to specify interacting constraints #21020.

Anirudhsekar96 and others added 2 commits January 20, 2022 11:51
Formatting changes to line spaces in the function

Co-authored-by: Jona Sassenhagen <[email protected]>
@jeremiedbb

Copy link
Copy Markdown
Member

Done in #24855. I'm closing this one.

@jeremiedbb jeremiedbb closed this Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:ensemble Needs Decision - Include Feature Requires decision regarding including feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QoL improvement: Add monotonicity constraints specification using dict of feature names in HistGradientBoostingClassifier/Regressor

5 participants