class_docstr: Generate univariate B-spline bases for features.
  
  Generate a new feature matrix consisting of
  `n_splines=n_knots + degree - 1` (`n_knots - 1` for
  `extrapolation="periodic"`) spline basis functions
  (B-splines) of polynomial order=`degree` for each feature.
  
  In order to learn more about the SplineTransformer class go to:
  :ref:`sphx_glr_auto_examples_applications_plot_cyclical_feature_engineering.py`
  
  Read more in the :ref:`User Guide <spline_transformer>`.
  
  .. versionadded:: 1.0
  
  Parameters
  ----------
  n_knots : int, default=5
      Number of knots of the splines if `knots` equals one of
      {'uniform', 'quantile'}. Must be larger or equal 2. Ignored if `knots`
      is array-like.
  
  degree : int, default=3
      The polynomial degree of the spline basis. Must be a non-negative
      integer.
  
  knots : {'uniform', 'quantile'} or array-like of shape         (n_knots, n_features), default='uniform'
      Set knot positions such that first knot <= features <= last knot.
  
      - If 'uniform', `n_knots` number of knots are distributed uniformly
        from min to max values of the features.
      - If 'quantile', they are distributed uniformly along the quantiles of
        the features.
      - If an array-like is given, it directly specifies the sorted knot
        positions including the boundary knots. Note that, internally,
        `degree` number of knots are added before the first knot, the same
        after the last knot.
  
  extrapolation : {'error', 'constant', 'linear', 'continue', 'periodic'},         default='constant'
      If 'error', values outside the min and max values of the training
      features raises a `ValueError`. If 'constant', the value of the
      splines at minimum and maximum value of the features is used as
      constant extrapolation. If 'linear', a linear extrapolation is used.
      If 'continue', the splines are extrapolated as is, i.e. option
      `extrapolate=True` in :class:`scipy.interpolate.BSpline`. If
      'periodic', periodic splines with a periodicity equal to the distance
      between the first and last knot are used. Periodic splines enforce
      equal function values and derivatives at the first and last knot.
      For example, this makes it possible to avoid introducing an arbitrary
      jump between Dec 31st and Jan 1st in spline features derived from a
      naturally periodic "day-of-year" input feature. In this case it is
      recommended to manually set the knot values to control the period.
  
  include_bias : bool, default=True
      If False, then the last spline element inside the data range
      of a feature is dropped. As B-splines sum to one over the spline basis
      functions for each data point, they implicitly include a bias term,
      i.e. a column of ones. It acts as an intercept term in a linear models.
  
  order : {'C', 'F'}, default='C'
      Order of output array in the dense case. `'F'` order is faster to compute, but
      may slow down subsequent estimators.
  
  sparse_output : bool, default=False
      Will return sparse CSR matrix if set True else will return an array. This
      option is only available with `scipy>=1.8`.
  
      .. versionadded:: 1.2
  
  Attributes
  ----------
  bsplines_ : list of shape (n_features,)
      List of BSplines objects, one for each feature.
  
  n_features_in_ : int
      The total number of input features.
  
  feature_names_in_ : ndarray of shape (`n_features_in_`,)
      Names of features seen during :term:`fit`. Defined only when `X`
      has feature names that are all strings.
  
      .. versionadded:: 1.0
  
  n_features_out_ : int
      The total number of output features, which is computed as
      `n_features * n_splines`, where `n_splines` is
      the number of bases elements of the B-splines,
      `n_knots + degree - 1` for non-periodic splines and
      `n_knots - 1` for periodic ones.
      If `include_bias=False`, then it is only
      `n_features * (n_splines - 1)`.
  
  See Also
  --------
  KBinsDiscretizer : Transformer that bins continuous data into intervals.
  
  PolynomialFeatures : Transformer that generates polynomial and interaction
      features.
  
  Notes
  -----
  High degrees and a high number of knots can cause overfitting.
  
  See :ref:`examples/linear_model/plot_polynomial_interpolation.py
  <sphx_glr_auto_examples_linear_model_plot_polynomial_interpolation.py>`.
  
  Examples
  --------
  >>> import numpy as np
  >>> from sklearn.preprocessing import SplineTransformer
  >>> X = np.arange(6).reshape(6, 1)
  >>> spline = SplineTransformer(degree=2, n_knots=3)
  >>> spline.fit_transform(X)
  array([[0.5 , 0.5 , 0.  , 0.  ],
         [0.18, 0.74, 0.08, 0.  ],
         [0.02, 0.66, 0.32, 0.  ],
         [0.  , 0.32, 0.66, 0.02],
         [0.  , 0.08, 0.74, 0.18],
         [0.  , 0.  , 0.5 , 0.5 ]])
class_docstr_tok: ["Generate","univariate","B-spline","bases","for","features",".","Generate","a","new","feature","matrix","consisting","of","`","n_splines=n_knots","+","degree","-","1","`","(","`","n_knots","-","1","`","for","`","extrapolation=","''","periodic","''","`",")","spline","basis","functions","(","B-splines",")","of","polynomial","order=","`","degree","`","for","each","feature",".","In","order","to","learn","more","about","the","SplineTransformer","class","go","to",":",":","ref",":","`","sphx_glr_auto_examples_applications_plot_cyclical_feature_engineering.py","`","Read","more","in","the",":","ref",":","`","User","Guide","<","spline_transformer",">","`",".","..","versionadded",":",":","1.0","Parameters","--","--","--","--","--","n_knots",":","int",",","default=5","Number","of","knots","of","the","splines","if","`","knots","`","equals","one","of","{","'uniform","'",",","'quantile","'","}",".","Must","be","larger","or","equal","2",".","Ignored","if","`","knots","`","is","array-like",".","degree",":","int",",","default=3","The","polynomial","degree","of","the","spline","basis",".","Must","be","a","non-negative","integer",".","knots",":","{","'uniform","'",",","'quantile","'","}","or","array-like","of","shape","(","n_knots",",","n_features",")",",","default='uniform'","Set","knot","positions","such","that","first","knot","<","=","features","<","=","last","knot",".","-","If","'uniform","'",",","`","n_knots","`","number","of","knots","are","distributed","uniformly","from","min","to","max","values","of","the","features",".","-","If","'quantile","'",",","they","are","distributed","uniformly","along","the","quantiles","of","the","features",".","-","If","an","array-like","is","given",",","it","directly","specifies","the","sorted","knot","positions","including","the","boundary","knots",".","Note","that",",","internally",",","`","degree","`","number","of","knots","are","added","before","the","first","knot",",","the","same","after","the","last","knot",".","extrapolation",":","{","'error","'",",","'constant","'",",","'linear","'",",","'continue","'",",","'periodic","'","}",",","default='constant'","If","'error","'",",","values","outside","the","min","and","max","values","of","the","training","features","raises","a","`","ValueError","`",".","If","'constant","'",",","the","value","of","the","splines","at","minimum","and","maximum","value","of","the","features","is","used","as","constant","extrapolation",".","If","'linear","'",",","a","linear","extrapolation","is","used",".","If","'continue","'",",","the","splines","are","extrapolated","as","is",",","i.e",".","option","`","extrapolate=True","`","in",":","class",":","`","scipy.interpolate.BSpline","`",".","If","'periodic","'",",","periodic","splines","with","a","periodicity","equal","to","the","distance","between","the","first","and","last","knot","are","used",".","Periodic","splines","enforce","equal","function","values","and","derivatives","at","the","first","and","last","knot",".","For","example",",","this","makes","it","possible","to","avoid","introducing","an","arbitrary","jump","between","Dec","31st","and","Jan","1st","in","spline","features","derived","from","a","naturally","periodic","``","day-of-year","''","input","feature",".","In","this","case","it","is","recommended","to","manually","set","the","knot","values","to","control","the","period",".","include_bias",":","bool",",","default=True","If","False",",","then","the","last","spline","element","inside","the","data","range","of","a","feature","is","dropped",".","As","B-splines","sum","to","one","over","the","spline","basis","functions","for","each","data","point",",","they","implicitly","include","a","bias","term",",","i.e",".","a","column","of","ones",".","It","acts","as","an","intercept","term","in","a","linear","models",".","order",":","{","'","C","'",",","'","F","'","}",",","default=","'","C'","Order","of","output","array","in","the","dense","case",".","`","'","F","'","`","order","is","faster","to","compute",",","but","may","slow","down","subsequent","estimators",".","sparse_output",":","bool",",","default=False","Will","return","sparse","CSR","matrix","if","set","True","else","will","return","an","array",".","This","option","is","only","available","with","`","scipy",">","=1.8","`",".","..","versionadded",":",":","1.2","Attributes","--","--","--","--","--","bsplines_",":","list","of","shape","(","n_features",",",")","List","of","BSplines","objects",",","one","for","each","feature",".","n_features_in_",":","int","The","total","number","of","input","features",".","feature_names_in_",":","ndarray","of","shape","(","`","n_features_in_","`",",",")","Names","of","features","seen","during",":","term",":","`","fit","`",".","Defined","only","when","`","X","`","has","feature","names","that","are","all","strings",".","..","versionadded",":",":","1.0","n_features_out_",":","int","The","total","number","of","output","features",",","which","is","computed","as","`","n_features","*","n_splines","`",",","where","`","n_splines","`","is","the","number","of","bases","elements","of","the","B-splines",",","`","n_knots","+","degree","-","1","`","for","non-periodic","splines","and","`","n_knots","-","1","`","for","periodic","ones",".","If","`","include_bias=False","`",",","then","it","is","only","`","n_features","*","(","n_splines","-","1",")","`",".","See","Also","--","--","--","--","KBinsDiscretizer",":","Transformer","that","bins","continuous","data","into","intervals",".","PolynomialFeatures",":","Transformer","that","generates","polynomial","and","interaction","features",".","Notes","--","--","-","High","degrees","and","a","high","number","of","knots","can","cause","overfitting",".","See",":","ref",":","`","examples\/linear_model\/plot_polynomial_interpolation.py","<","sphx_glr_auto_examples_linear_model_plot_polynomial_interpolation.py",">","`",".","Examples","--","--","--","--",">",">",">","import","numpy","as","np",">",">",">","from","sklearn.preprocessing","import","SplineTransformer",">",">",">","X","=","np.arange","(","6",")",".reshape","(","6",",","1",")",">",">",">","spline","=","SplineTransformer","(","degree=2",",","n_knots=3",")",">",">",">","spline.fit_transform","(","X",")","array","(","[","[","0.5",",","0.5",",","0.",",","0",".","]",",","[","0.18",",","0.74",",","0.08",",","0",".","]",",","[","0.02",",","0.66",",","0.32",",","0",".","]",",","[","0.",",","0.32",",","0.66",",","0.02","]",",","[","0.",",","0.08",",","0.74",",","0.18","]",",","[","0.",",","0.",",","0.5",",","0.5","]","]",")"]
docstr: Compute knot positions of splines.
  
  Parameters
  ----------
  X : array-like of shape (n_samples, n_features)
      The data.
  
  y : None
      Ignored.
  
  sample_weight : array-like of shape (n_samples,), default = None
      Individual weights for each sample. Used to calculate quantiles if
      `knots="quantile"`. For `knots="uniform"`, zero weighted
      observations are ignored for finding the min and max of `X`.
  
  Returns
  -------
  self : object
      Fitted transformer.
docstr_tok: ["Compute","knot","positions","of","splines",".","Parameters","--","--","--","--","--","X",":","array-like","of","shape","(","n_samples",",","n_features",")","The","data",".","y",":","None","Ignored",".","sample_weight",":","array-like","of","shape","(","n_samples",",",")",",","default","=","None","Individual","weights","for","each","sample",".","Used","to","calculate","quantiles","if","`","knots=","''","quantile","''","`",".","For","`","knots=","''","uniform","''","`",",","zero","weighted","observations","are","ignored","for","finding","the","min","and","max","of","`","X","`",".","Returns","--","--","--","-","self",":","object","Fitted","transformer","."]
code: def fit(self, X, y=None, sample_weight=None):
      """Compute knot positions of splines.
  
      Parameters
      ----------
      X : array-like of shape (n_samples, n_features)
          The data.
  
      y : None
          Ignored.
  
      sample_weight : array-like of shape (n_samples,), default = None
          Individual weights for each sample. Used to calculate quantiles if
          `knots="quantile"`. For `knots="uniform"`, zero weighted
          observations are ignored for finding the min and max of `X`.
  
      Returns
      -------
      self : object
          Fitted transformer.
      """
      X = self._validate_data(
          X,
          reset=True,
          accept_sparse=False,
          ensure_min_samples=2,
          ensure_2d=True,
      )
      if sample_weight is not None:
          sample_weight = _check_sample_weight(
              sample_weight, X, dtype=X.dtype
          )
  
      _, n_features = X.shape
  
      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,
          )
      else:
          base_knots = check_array(self.knots, dtype=np.float64)
          if base_knots.shape[0] < 2:
              raise ValueError(
                  "Number of knots, knots.shape[0], must be >= 2."
              )
          elif base_knots.shape[1] != n_features:
              raise ValueError(
                  "knots.shape[1] == n_features is violated."
              )
          elif not np.all(np.diff(base_knots, axis=0) > 0):
              raise ValueError(
                  "knots must be sorted without duplicates."
              )
  
      if self.sparse_output and sp_version < parse_version("1.8.0"):
          raise ValueError(
              "Option sparse_output=True is only available with scipy>=1.8.0, "
              f"but here scipy=={sp_version} is used."
          )
  
      # number of knots for base interval
      n_knots = base_knots.shape[0]
  
      if self.extrapolation == "periodic" and n_knots <= self.degree:
          raise ValueError(
              "Periodic splines require degree < n_knots. Got n_knots="
              f"{n_knots} and degree={self.degree}."
          )
  
      # number of splines basis functions
      if self.extrapolation != "periodic":
          n_splines = n_knots + self.degree - 1
      else:
          # periodic splines have self.degree less degrees of freedom
          n_splines = n_knots - 1
  
      degree = self.degree
      n_out = n_features * n_splines
      # We have to add degree number of knots below, and degree number knots
      # above the base knots in order to make the spline basis complete.
      if self.extrapolation == "periodic":
          # For periodic splines the spacing of the first / last degree knots
          # needs to be a continuation of the spacing of the last / first
          # base knots.
          period = base_knots[-1] - base_knots[0]
          knots = np.r_[
              base_knots[-(degree + 1) : -1] - period,
              base_knots,
              base_knots[1 : (degree + 1)] + period,
          ]
  
      else:
          # Eilers & Marx in "Flexible smoothing with B-splines and
          # penalties" https://doi.org/10.1214/ss/1038425655 advice
          # against repeating first and last knot several times, which
          # would have inferior behaviour at boundaries if combined with
          # a penalty (hence P-Spline). We follow this advice even if our
          # splines are unpenalized. Meaning we do not:
          # knots = np.r_[
          #     np.tile(base_knots.min(axis=0), reps=[degree, 1]),
          #     base_knots,
          #     np.tile(base_knots.max(axis=0), reps=[degree, 1])
          # ]
          # Instead, we reuse the distance of the 2 fist/last knots.
          dist_min = base_knots[1] - base_knots[0]
          dist_max = base_knots[-1] - base_knots[-2]
  
          knots = np.r_[
              np.linspace(
                  base_knots[0] - degree * dist_min,
                  base_knots[0] - dist_min,
                  num=degree,
              ),
              base_knots,
              np.linspace(
                  base_knots[-1] + dist_max,
                  base_knots[-1] + degree * dist_max,
                  num=degree,
              ),
          ]
  
      # With a diagonal coefficient matrix, we get back the spline basis
      # elements, i.e. the design matrix of the spline.
      # Note, BSpline appreciates C-contiguous float64 arrays as c=coef.
      coef = np.eye(n_splines, dtype=np.float64)
      if self.extrapolation == "periodic":
          coef = np.concatenate((coef, coef[:degree, :]))
  
      extrapolate = self.extrapolation in ["periodic", "continue"]
  
      bsplines = [
          BSpline.construct_fast(
              knots[:, i], coef, self.degree, extrapolate=extrapolate
          )
          for i in range(n_features)
      ]
      self.bsplines_ = bsplines
  
      self.n_features_out_ = n_out - n_features * (
          1 - self.include_bias
      )
      return self
  
imports: import collections
  from itertools import chain, combinations
  from itertools import combinations_with_replacement
  from numbers import Integral
  import numpy
  from scipy import sparse
  from scipy.interpolate import BSpline
  from scipy.special import comb
  from ..base import BaseEstimator, TransformerMixin, _fit_context
  from ..utils import check_array
  from ..utils._param_validation import Interval, StrOptions
  from ..utils.fixes import parse_version, sp_version
  from ..utils.stats import _weighted_percentile
  from ..utils.validation import FLOAT_DTYPES, _check_feature_names_in, _check_sample_weight, check_is_fitted
  from ._csr_polynomial_expansion import _calc_expanded_nnz, _calc_total_nnz, _csr_polynomial_expansion
label_desc: Use image node_id 4 for calling the SplineTransformer obj's underlying member method code with example usage: obj.fit(X, y, sample_weight) and returns: self