MAINT add parameters validation for SplineTransformer#24057
Merged
thomasjpfan merged 5 commits intoscikit-learn:mainfrom Aug 26, 2022
Merged
MAINT add parameters validation for SplineTransformer#24057thomasjpfan merged 5 commits intoscikit-learn:mainfrom
thomasjpfan merged 5 commits intoscikit-learn:mainfrom
Conversation
…nto validate_spline_transformer
This was referenced Aug 5, 2022
glemaitre
reviewed
Aug 24, 2022
Member
glemaitre
left a comment
There was a problem hiding this comment.
Otherwise, the rest of the PR seems fine.
| self : object | ||
| Fitted transformer. | ||
| """ | ||
| self._validate_params() |
Member
There was a problem hiding this comment.
Now some parameters will be validated and you need to remove some extra unnecessary checks. I check and you should have the following diff in fit:
diff --git a/sklearn/preprocessing/_polynomial.py b/sklearn/preprocessing/_polynomial.py
index 585c21eb2d..0b651e1f2f 100644
--- a/sklearn/preprocessing/_polynomial.py
+++ b/sklearn/preprocessing/_polynomial.py
@@ -794,20 +794,8 @@ class SplineTransformer(TransformerMixin, BaseEstimator):
_, n_features = X.shape
- if not (isinstance(self.degree, numbers.Integral) and self.degree >= 0):
- raise ValueError(
- f"degree must be a non-negative integer, got {self.degree}."
- )
-
- if isinstance(self.knots, str) and self.knots in [
- "uniform",
- "quantile",
- ]:
- if not (isinstance(self.n_knots, numbers.Integral) and self.n_knots >= 2):
- raise ValueError(
- f"n_knots must be a positive integer >= 2, got: {self.n_knots}"
- )
+ if isinstance(self.knots, str):
base_knots = self._get_base_knot_positions(
X, n_knots=self.n_knots, knots=self.knots, sample_weight=sample_weight
)
@@ -820,20 +808,6 @@ class SplineTransformer(TransformerMixin, BaseEstimator):
elif not np.all(np.diff(base_knots, axis=0) > 0):
raise ValueError("knots must be sorted without duplicates.")
- if self.extrapolation not in (
- "error",
- "constant",
- "linear",
- "continue",
- "periodic",
- ):
- raise ValueError(
- "extrapolation must be one of 'error', "
- "'constant', 'linear', 'continue' or 'periodic'."
- )
-
- if not isinstance(self.include_bias, (bool, np.bool_)):
- raise ValueError("include_bias must be bool.")
# number of knots for base interval
n_knots = base_knots.shape[0]
glemaitre
pushed a commit
to glemaitre/scikit-learn
that referenced
this pull request
Sep 12, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
References #23462 as well #22722
What does this implement/fix? Explain your changes.
Adds
_parameter_constraintstosklearn/preprocessing/_polynomial.py/SplineTransformerand removesSplineTransformerfromPARAM_VALIDATION_ESTIMATORS_TO_IGNOREinsklearn/tests/test_common.pyAny other comments?
#23462 mentions that spotting and removing existing validation/tests is easier with codecov since it becomes unreachable code. Can this be down locally or do I need to submit a pull request?