SplineTransformer raises when passing knots explicity for n_knots=None
See original GitHub issueOn master,
import numpy as np
from sklearn.preprocessing import SplineTransformer
X = np.linspace(0, 1, 10)[:, None]
splt = SplineTransformer(
knots=[[0], [1], [2], [3], [4]],
n_knots=None,
degree=3
)
splt.fit(X)
currently raises
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-86bffa93d84e> in <module>
10 )
11
---> 12 splt.fit(X)
~/code/scikit-learn/sklearn/preprocessing/_polynomial.py in fit(self, X, y)
226 isinstance(self.n_knots, numbers.Integral) and self.n_knots >= 2
227 ):
--> 228 raise ValueError("n_knots must be a positive integer >= 2.")
229
230 if isinstance(self.knots, str) and self.knots in [
ValueError: n_knots must be a positive integer >= 2.
IMO the n_knots
argument should be allowed to be None
(or any other value) if the knots
are passed explicity.
cc: @lorentzenchr @ogrisel xref #18368 and #19483
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
sklearn.preprocessing.SplineTransformer
Number of knots of the splines if knots equals one of {'uniform', 'quantile'}. Must be larger or equal 2. Ignored if knots is...
Read more >ENH Add periodic extrapolation to SplineTransformer #19483
Maybe, one should more clearly state, that the periodicity is given either by the manually specified knots or by the range of the...
Read more >Basis Expansions and Smoothing Splines - Branch Energy
The points at which one cubic polynomial hands over to the next are called knots. For this work, we're going to use symfit,...
Read more >Proper terminology for what happens at knots in a cubic spline ...
This answer on math.stackexchange.com suggests one way to proceed. In particular: The typical mathematical definition of "smooth" says ...
Read more >Time-related feature engineering with scikit-learn - Neuraxle
SplineTransformer class and its extrapolation=”periodic” option. ... we pass the list of categorical values explicitly to use a logical order when encoding ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If
knots in ["uniform", "quantile"]
, thenn_knots
specifies the number if knots. Ifknots=2d array
specifying the knot positions manually, thenn_knots
is ignored. So they can’t be collapsed, but that would have been nice!Currently
works. IMO this is “more incorrect” than
n_knots=None
.Raising an error that
n_knots
needs to be in integer whenknots
is passed explicitly is confusing. This suggests that the value inn_knots
get’s used somewhere. I would generally passn_knots=None
explicitly to make sure that the argument does not get used.