Skip to content
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

Check monotonic_cst Before Fit #82

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions quantile_forest/_quantile_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ def fit(self, X, y, sample_weight=None, sparse_pickle=False):
"max_samples_leaf must be of integer, float, or None type, got "
f"{self.max_samples_leaf}."
)
if self.monotonic_cst is not None:
if (
not isinstance(self.max_samples_leaf, (Integral, np.integer))
or self.max_samples_leaf != 1
):
raise ValueError(
"Monotonicity constraints are not supported with multiple values per leaf. "
"To apply monotonicity constraints, set `max_samples_leaf=1`."
)

super(BaseForestQuantileRegressor, self).fit(X, y, sample_weight=sample_weight)
X, y = self._validate_data(
X, y, multi_output=True, accept_sparse="csc", dtype=DTYPE, force_all_finite=False
Expand Down Expand Up @@ -343,13 +353,6 @@ def _get_y_train_leaves(self, X, y, sorter=None, sample_weight=None):
f"got {type(self.max_samples_leaf)}."
)

if self.monotonic_cst is not None:
if max_samples_leaf != 1:
raise ValueError(
"Monotonicity constraints are not supported with multiple values per leaf. "
"To apply monotonicity constraints, set `max_samples_leaf=1`."
)

with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
X_leaves = self.apply(X)
Expand Down
Loading