
    -iߴ                     "   S r SSKrSSKJrJr  SSKJr  SSKJr  SSK	r
SSKJr  SSKJr  SSKJr  S	S
KJrJrJr  S	SKJr  S	SKJrJr  S	SKJrJr  S	SKJr  S	SKJ r J!r!J"r"J#r#J$r$  SSK%J&r&J'r'J%r%  SS/r(SS jr) " S S\\5      r* " S S\\5      r+g)z>
This file contains preprocessing tools based on polynomials.
    N)chaincombinations)combinations_with_replacement)Integral)sparse)BSpline)comb   )BaseEstimatorTransformerMixin_fit_context)check_array)Interval
StrOptions)parse_version
sp_version)_weighted_percentile)FLOAT_DTYPES_check_feature_names_in_check_sample_weightcheck_is_fittedvalidate_data   )_calc_expanded_nnz_calc_total_nnz_csr_polynomial_expansionPolynomialFeaturesSplineTransformerc                    [        U R                  X5      n[        X1U5      nUS:X  a  gUS-
  nUn[        R                  " [        R
                  5      R                  n	[        Xx5      U	:  n
U
(       a  [        R                  O[        R
                  n[        R                  " XPR                  R                  S9n[        R                  " X[S9n[        R                  " U R                  R                  S   US9n[        U R                  U R                  U R                  U R                  S   UUUUU5	        [        R                  " XU4U R                  R                  S   S-
  U4U R                  S9$ )zDHelper function for creating and appending sparse expansion matricesr   Nr   shapedtype)r   indptrr   npiinfoint32maxint64emptydatar"   r!   r   indicesr   
csr_matrix)Xinteraction_onlydeg
n_featurescumulative_size	total_nnzexpanded_colmax_indices
max_indptr	max_int32needs_int64index_dtypeexpanded_dataexpanded_indicesexpanded_indptrs                  T/var/www/html/venv/lib/python3.13/site-packages/sklearn/preprocessing/_polynomial.py_create_expansionr=   *   s.     *:@I%jCHLq "KJ"&&Ik.:K)"((rxxK HH9FFLLAMxxiChhQXX^^A%6kJO						

 	/:xx~~a 1$l3gg     c                      ^  \ rS rSr% Sr\" \SSSS9S/S/S/\" S	S
15      /S.r\	\
S'    SSSS	S.S jjr\S 5       r\S 5       r\S 5       rSS jr\" SS9SS j5       rS rU 4S jrSrU =r$ )r   U   a  Generate polynomial and interaction features.

Generate a new feature matrix consisting of all polynomial combinations
of the features with degree less than or equal to the specified degree.
For example, if an input sample is two dimensional and of the form
[a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].

Read more in the :ref:`User Guide <polynomial_features>`.

Parameters
----------
degree : int or tuple (min_degree, max_degree), default=2
    If a single int is given, it specifies the maximal degree of the
    polynomial features. If a tuple `(min_degree, max_degree)` is passed,
    then `min_degree` is the minimum and `max_degree` is the maximum
    polynomial degree of the generated features. Note that `min_degree=0`
    and `min_degree=1` are equivalent as outputting the degree zero term is
    determined by `include_bias`.

interaction_only : bool, default=False
    If `True`, only interaction features are produced: features that are
    products of at most `degree` *distinct* input features, i.e. terms with
    power of 2 or higher of the same input feature are excluded:

    - included: `x[0]`, `x[1]`, `x[0] * x[1]`, etc.
    - excluded: `x[0] ** 2`, `x[0] ** 2 * x[1]`, etc.

include_bias : bool, default=True
    If `True` (default), then include a bias column, the feature in which
    all polynomial powers are zero (i.e. a column of ones - acts as an
    intercept term in a linear model).

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.

    .. versionadded:: 0.21

Attributes
----------
powers_ : ndarray of shape (`n_output_features_`, `n_features_in_`)
    `powers_[i, j]` is the exponent of the jth input in the ith output.

n_features_in_ : int
    Number of features seen during :term:`fit`.

    .. versionadded:: 0.24

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_output_features_ : int
    The total number of polynomial output features. The number of output
    features is computed by iterating over all suitably sized combinations
    of input features.

See Also
--------
SplineTransformer : Transformer that generates univariate B-spline bases
    for features.

Notes
-----
Be aware that the number of features in the output array scales
polynomially in the number of features of the input array, and
exponentially in the degree. High degrees 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 PolynomialFeatures
>>> X = np.arange(6).reshape(3, 2)
>>> X
array([[0, 1],
       [2, 3],
       [4, 5]])
>>> poly = PolynomialFeatures(2)
>>> poly.fit_transform(X)
array([[ 1.,  0.,  1.,  0.,  0.,  1.],
       [ 1.,  2.,  3.,  4.,  6.,  9.],
       [ 1.,  4.,  5., 16., 20., 25.]])
>>> poly = PolynomialFeatures(interaction_only=True)
>>> poly.fit_transform(X)
array([[ 1.,  0.,  1.,  0.],
       [ 1.,  2.,  3.,  6.],
       [ 1.,  4.,  5., 20.]])
r   Nleftclosed
array-likebooleanCFdegreer.   include_biasorder_parameter_constraintsFT)r.   rJ   rK   c                4    Xl         X l        X0l        X@l        g NrH   )selfrI   r.   rJ   rK   s        r<   __init__PolynomialFeatures.__init__   s      0(
r>   c                    ^ ^ U(       a  [         O[        m[        SU5      n[        R                  " UU 4S j[        XRS-   5       5       5      nU(       a  [        T" [        T 5      S5      U5      nU$ )Nr   c              3   H   >#    U  H  nT" [        T5      U5      v   M     g 7frN   )range).0ir	   r0   s     r<   	<genexpr>3PolynomialFeatures._combinations.<locals>.<genexpr>   s$      #
0L1Dz"A&&0Ls   "r   )r   combinations_w_rr'   r   from_iterablerT   )r0   
min_degree
max_degreer.   rJ   startiterr	   s   `      @r<   _combinations PolynomialFeatures._combinations   sc      0|5EAz""" #
05e!^0L#
 
 eJ/3T:Dr>   c                    U(       aE  [        [        [        SU5      [        X 5      S-   5       Vs/ s H  n[	        XSS9PM     sn5      nO.[	        X-   USS9S-
  nUS:  a  US-
  nU[	        X-   USS9S-
  -  nU(       a  US-  nU$ s  snf )zCalculate number of terms in polynomial expansion

This should be equivalent to counting the number of terms returned by
_combinations(...) but much faster.
r   T)exactr   )sumrT   r'   minr	   )r0   r[   r\   r.   rJ   rV   r   ds           r<   _num_combinations$PolynomialFeatures._num_combinations   s      #3q*#5s:7RUV7VWW d3WL  
 74PSTTLA~NZ^Qd Ca GGALs   B	c           
      2   [        U 5        U R                  U R                  U R                  U R                  U R
                  U R                  S9n[        R                  " U Vs/ s H!  n[        R                  " X R                  S9PM#     sn5      $ s  snf )z.Exponent for each of the inputs in the output.r0   r[   r\   r.   rJ   )	minlength)
r   r_   n_features_in__min_degree_max_degreer.   rJ   r$   vstackbincount)rO   r   cs      r<   powers_PolynomialFeatures.powers_   s     	))**''''!22** * 
 yyDPQLqR[[&9&9:LQ
 	
Qs   %(Bc           	      D  ^ U R                   n[        U T5      m/ nU Hg  n[        R                  " U5      S   n[	        U5      (       a(  SR                  U4S j[        XTU   5       5       5      nOSnUR                  U5        Mi     [        R                  " U[        S9$ )am  Get output feature names for transformation.

Parameters
----------
input_features : array-like of str or None, default=None
    Input features.

    - If `input_features is None`, then `feature_names_in_` is
      used as feature names in. If `feature_names_in_` is not defined,
      then the following input feature names are generated:
      `["x0", "x1", ..., "x(n_features_in_ - 1)"]`.
    - If `input_features` is an array-like, then `input_features` must
      match `feature_names_in_` if `feature_names_in_` is defined.

Returns
-------
feature_names_out : ndarray of str objects
    Transformed feature names.
r    c              3   R   >#    U  H  u  pUS :w  a
  STU   U4-  OTU   v   M     g7f)r   z%s^%dN )rU   indexpinput_featuress      r<   rW   ;PolynomialFeatures.get_feature_names_out.<locals>.<genexpr>  sC        %9 !8  >##6"<<+C01 %9s   $'1r"   )
rq   r   r$   wherelenjoinzipappendasarrayobject)rO   ry   powersfeature_namesrowindsnames    `     r<   get_feature_names_out(PolynomialFeatures.get_feature_names_out   s    ( 0~FC88C=#D4yyxx   %($i$8     &  zz-v66r>   prefer_skip_nested_validationc                 x   [        XSS9R                  u  p4[        U R                  [        5      (       aF  U R                  S:X  a  U R
                  (       d  [        S5      eSU l        U R                  U l        GO,[        U R                  [        R                  R                  5      (       a  [        U R                  5      S:X  a  U R                  u  U l        U l        [        U R                  [        5      (       aI  [        U R                  [        5      (       a*  U R                  S:  a  U R                  U R                  ::  d  [        SU R                   S35      eU R                  S:X  a  U R
                  (       d  [        S5      eO[        S	U R                   S35      eU R                  UU R                  U R                  U R                  U R
                  S
9U l        U R                  [         R"                  " [         R$                  5      R&                  :  a  SU R                   S[         R$                  " 5       R(                  R*                   SU< SU R                   SU R                   SU R                   SU R
                   S3n[         R$                  [         R,                  :X  aA  U R                  [         R"                  " [         R.                  5      R&                  ::  a  US-  n[        U5      eU R                  USU R                  U R                  U R
                  S
9U l        U $ )a  
Compute number of output features.

Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
    The data.

y : Ignored
    Not used, present here for API consistency by convention.

Returns
-------
self : object
    Fitted transformer.
T)accept_sparser   zWSetting degree to zero and include_bias to False would result in an empty output array.r
   zhdegree=(min_degree, max_degree) must be non-negative integers that fulfil min_degree <= max_degree, got .zoSetting both min_degree and max_degree to zero and include_bias to False would result in an empty output array.zIdegree must be a non-negative int or tuple (min_degree, max_degree), got ri   zGThe output that would result from the current configuration would have z. features which is too large to be indexed by zj. Please change some or all of the following:
- The number of features in the input, currently n_features=z1
- The range of degrees to calculate, currently [z, z9]
- Whether to include only interaction terms, currently z-
- Whether to include a bias term, currently z
Note that the current Python runtime has a limited 32 bit address space and that this configuration would have been admissible if run on a 64 bit Python runtime.)r   r!   
isinstancerI   r   rJ   
ValueErrorrl   rm   collectionsabcIterabler~   rf   r.   n_output_features_r$   r%   intpr'   r"   r   r&   r(   _n_out_full)rO   r-   y_r0   msgs         r<   fitPolynomialFeatures.fit#  s   $ &dTBHHdkk8,,{{a(9(9 . 
  !D#{{Dt{{KOO$<$<==#dkkBRVWBW15.Dd.4++X66t//::$$)$$(8(88 5 {{m1&  !!Q&t/@/@ D 
 1;;-q"  #'"8"8!''''!22** #9 #
 ""RXXbgg%6%:%::001 2!wwy334 5 = !%%&b)9)9(: ;1151F1F0G H3373D3D2EQH  288#++rxx/A/E/EED
 S/!  11!''!22** 2 
 r>   c           
         [        U 5        [        U US[        SSS9nUR                  u  p#[        R
                  " [        R                  5      R                  n[        R                  " U5      (       Ga  UR                  S:X  Ga  U R                  S:  a-  U R                  UR                  5       5      R                  5       $ / nU R                  (       aD  UR!                  [        R"                  " [        R$                  " US4UR&                  S95      5        U R(                  S::  a!  U R                  S	:  a  UR!                  U5        [+        S
 U 5       5      n[-        [        SU R(                  5      U R                  S-   5       HA  n[/        UU R0                  UUUS9nUc  M  UR!                  U5        XhR                  S   -  nMC     [3        U5      S	:X  a#  [        R"                  " US	4UR&                  S9n	U	$ [5        S U 5       5      n
[6        [9        S5      :  a"  U R:                  U:  a  U
(       a  [=        S5      e[        R>                  " XQR&                  SS9n	 U	$ [        R                  " U5      (       aM  UR                  S:X  a=  U R                  S:  a-  U R                  UR                  5       5      R                  5       $ [        R                  " U5      (       a  U RA                  UU R(                  U R                  U R0                  U R                  S9n/ nU H  nU(       a7  SnU H  nUSS2U/4   RC                  U5      nM     UR!                  U5        MA  [        RD                  " [        R$                  " UR                  S	   S45      5      nUR!                  U5        M     [        R>                  " XR&                  S9R                  5       n	U	$ [        RF                  " X RH                  4UR&                  U RJ                  S9n	U R                  (       a  SU	SS2S	4'   SnOS	nU R                  S	:X  a  U	$ XSS2UUU-   24'   [M        [-        UUU-   5      5      nUU-  nUR!                  U5        [-        SU R                  S-   5       H  n/ nUS   n[-        U5       H  nUU   nUR!                  U5        U R0                  (       a  UUUS-      UU   -
  -  nUU-   U-
  nUU::  a    O;[        RB                  " U	SS2UU24   USS2UUS-   24   U	SS2UU24   SS9  UnM     UR!                  U5        UnM     U R(                  S:  a  U RH                  U R:                  nnU R                  (       aP  [        RF                  " UU4U	R&                  U RJ                  S9nSUSS2S	4'   U	SS2UU-
  S-   S24   USS2SS24'   OU	SS2UU-
  S24   RO                  5       nUn	U	$ )a  Transform data to polynomial features.

Parameters
----------
X : {array-like, sparse matrix} of shape (n_samples, n_features)
    The data to transform, row by row.

    Prefer CSR over CSC for sparse input (for speed), but CSC is
    required if the degree is 4 or higher. If the degree is less than
    4 and the input format is CSC, it will be converted to CSR, have
    its polynomial features generated, then converted back to CSC.

    If the degree is 2 or 3, the method described in "Leveraging
    Sparsity to Speed Up Polynomial Feature Expansions of CSR Matrices
    Using K-Simplex Numbers" by Andrew Nystrom and John Hughes is
    used, which is much faster than the method used on CSC input. For
    this reason, a CSC input will be converted to CSR, and the output
    will be converted back to CSC prior to being returned, hence the
    preference of CSR.

Returns
-------
XP : {ndarray, sparse matrix} of shape (n_samples, NP)
    The matrix of features, where `NP` is the number of polynomial
    features generated from the combination of inputs. If a sparse
    matrix is provided, it will be converted into a sparse
    `csr_matrix`.
rG   F)csrcsc)rK   r"   resetr   r      r   r    r   c              3   >   #    U  H  oR                   S    v   M     g7f)r   N)r!   rU   mats     r<   rW   /PolynomialFeatures.transform.<locals>.<genexpr>  s     !C(3))A,(s   r
   )r-   r.   r/   r0   r1   Nr|   c              3   n   #    U  H+  oR                   R                  [        R                  :H  v   M-     g 7frN   )r+   r"   r$   r&   r   s     r<   rW   r     s!     R# 1 1RXX =s   351.9.2a  In scipy versions `<1.9.2`, the function `scipy.sparse.hstack` produces negative columns when:
1. The output shape contains `n_cols` too large to be represented by a 32bit signed integer.
2. All sub-matrices to be stacked have indices of dtype `np.int32`.
To avoid this error, either use a version of scipy `>=1.9.2` or alter the `PolynomialFeatures` transformer to produce fewer than 2^31 output features)r"   formatr      ri   )r!   r"   rK   no)outcasting)(r   r   r   r!   r$   r%   r&   r'   r   issparser   rm   	transformtocsctocsrrJ   r   r,   onesr"   rl   rc   rT   r=   r.   r~   allr   r   r   r   hstackr_   multiply
csc_matrixr)   r   rK   listcopy)rO   r-   	n_samplesr0   r6   to_stackr1   r/   expandedXP	all_int32r   columnscombiout_colcol_idxbiascurrent_colindexr   	new_indexendfeature_idxr]   next_coln_XPn_XoutXouts                               r<   r   PolynomialFeatures.transform  s   : 	(
 !"	HHRXX&**	??1!((e"3!#~~aggi06688H  %%bggYN!''&RS 1$)9)9A)="!!C(!CCOSD$4$45t7G7G!7KL,%)%:%:)$3 'OOH-#~~a'88O M 8}!&&	1~QWWEb 	[  RRR	w!77//);!$R  ]]8775I| 	{ __QAHH$5$:J:JQ:N>>!''),2244__Q--%++++!%!6!6!.. . L G%G#("#AyL/":":7"C $)NN7+!,,RWWaggaj!_-EFDNN4( & wgg6<<>BR 	K  "2"23177$**B$   1a41$	 =>q+j 8889{K*,DEFE:%KLL% 1d..23	Bi#(#4K!+.E$$[1,,{Q!7%:L!LL*S058H;. KK1eCi<(![;?::;q+h"667 $	 #+K! $5$   -!- 40 !##//1H1Hf$$88(&1D "#DAJ"$Qv(9(;%;"<DABKa01668D	r>   c                 F   > [         TU ]  5       nSUR                  l        U$ )NT)super__sklearn_tags__
input_tagsr   )rO   tags	__class__s     r<   r   #PolynomialFeatures.__sklearn_tags__:  s!    w')!%r>   )rm   rl   r   rI   rJ   r.   r   rK   )r
   rN   )__name__
__module____qualname____firstlineno____doc__r   r   r   rL   dict__annotations__rP   staticmethodr_   rf   propertyrq   r   r   r   r   r   __static_attributes____classcell__)r   s   @r<   r   r   U   s    \~ Haf=|L&K"c3Z()	$D  ,1C 
 
  6 
 
%7N 5^ 6^@tl r>   c            	           \ rS rSr% Sr\" \SSSS9/\" \SSSS9/\" SS	15      S
/\" 1 Sk5      /S/\" SS15      /S/S.r\	\
S'     SSSSSSS.S jjr\SS j5       rSS jr\" SS9SS j5       rS rSrg) r   i@  a  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.

    .. 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 ]])
r
   NrA   rB   r   uniformquantilerD   >   errorlinearconstantcontinueperiodicrE   rF   rG   n_knotsrI   knotsextrapolationrJ   rK   sparse_outputrL   r   TF)r   r   rJ   rK   r   c                X    Xl         X l        X0l        X@l        XPl        X`l        Xpl        g rN   r   )rO   r   rI   r   r   rJ   rK   r   s           r<   rP   SplineTransformer.__init__  s*     
*(
*r>   c           
         US:X  av  S[         R                  " SSU[         R                  S9-  nUc  [         R                  " XSS9nU$ [         R                  " U Vs/ s H  n[        XU5      PM     sn5      n U$ Uc  [        SSS5      OUS:  n[         R                  " X   SS9n[         R                  " X   SS9n[         R                  " UUUS[         R                  S	9nU$ s  snf )
aJ  Calculate base knot positions.

Base knots such that first knot <= feature <= last knot. For the
B-spline construction with scipy.interpolate.BSpline, 2*degree knots
beyond the base interval are added.

Returns
-------
knots : ndarray of shape (n_knots, n_features), dtype=np.float64
    Knot positions (points) of base interval.
r   d   r   r   )r]   stopnumr"   NaxisT)r]   r   r   endpointr"   )	r$   linspacefloat64
percentilearrayr   sliceaminamax)	r-   r   r   sample_weightpercentile_rankspercentile_rankmaskx_minx_maxs	            r<   _get_base_knot_positions*SplineTransformer._get_base_knot_positions  s     J"R[[aWBJJ&   $aB4 1  0@/?O -QO/?0  ,9+@5tQ'mVWFWDGGAG!,EGGAG!,EKKjjE /s   C(c                 ^   [        U S5        U R                  S   R                  R                  S   n[	        X5      n/ n[        U R                  5       H=  n[        US-
  U R                  -   5       H  nUR                  X    SU 35        M     M?     [        R                  " U[        S9$ )ao  Get output feature names for transformation.

Parameters
----------
input_features : array-like of str or None, default=None
    Input features.

    - If `input_features` is `None`, then `feature_names_in_` is
      used as feature names in. If `feature_names_in_` is not defined,
      then the following input feature names are generated:
      `["x0", "x1", ..., "x(n_features_in_ - 1)"]`.
    - If `input_features` is an array-like, then `input_features` must
      match `feature_names_in_` if `feature_names_in_` is defined.

Returns
-------
feature_names_out : ndarray of str objects
    Transformed feature names.
rk   r   r   _sp_r|   )r   	bsplines_rp   r!   r   rT   rk   rJ   r   r$   r   r   )rO   ry   	n_splinesr   rV   js         r<   r   'SplineTransformer.get_feature_names_out  s    ( 	./NN1%''--a0	0Ft**+A9q=4+<+<<=$$(9':$qc%BC > , zz-v66r>   r   c           
      "   [        U USSSSS9nUb  [        X1UR                  S9nUR                  u  pE[	        U R
                  [        5      (       a&  U R                  XR                  U R
                  US9nO[        U R
                  [        R                  S9nUR                  S   S:  a  [        S	5      eUR                  S
   U:w  a  [        S5      e[        R                  " [        R                  " USS9S:  5      (       d  [        S5      eUR                  S   nU R                  S:X  a+  XpR                   ::  a  [        SU SU R                    S35      eU R                  S:w  a  XpR                   -   S
-
  nOUS
-
  nU R                   n	XX-  n
U R                  S:X  a4  US   US   -
  n[        R"                  XiS
-   * S U-
  UUS
U	S
-    U-   4   nOpUS
   US   -
  nUS   US   -
  n[        R"                  [        R$                  " US   X-  -
  US   U-
  U	S9U[        R$                  " US   U-   US   X-  -   U	S94   n[        R&                  " U[        R                  S9nU R                  S:X  a   [        R(                  " XSU	2SS24   45      nU R                  S;   n[+        U5       Vs/ s H*  n[,        R.                  " USS2U4   XR                   US9PM,     nnUU l        XS
U R2                  -
  -  -
  U l        U $ s  snf )a  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.
TFr
   )r   r   ensure_min_samples	ensure_2dNr|   )r   r   r   r   z.Number of knots, knots.shape[0], must be >= 2.r   z)knots.shape[1] == n_features is violated.r   z(knots must be sorted without duplicates.r   z7Periodic splines require degree < n_knots. Got n_knots=z and degree=r   r   )r   )r   r   )extrapolate)r   r   r"   r!   r   r   strr  r   r   r$   r   r   r   diffr   rI   r_r   eyeconcatenaterT   r   construct_fastr  rJ   n_features_out_)rO   r-   r   r   r   r0   
base_knotsr   r  rI   n_outperiodr   dist_mindist_maxcoefr  rV   bspliness                      r<   r   SplineTransformer.fit&  s?   ,  
 $0QMdjj#&&66<<tzz 7 J %TZZrzzBJ"Q& !QRR!!!$
2 !LMMVVBGGJQ7!;<< !KLL ""1%+;;0FI)<}A7  +++-1I  !I& +  ^jm3FEEaZ=2.71
,v57E& "!}z!}4H!"~
26HEEqMF$55qMH,
 rNX-rNV%66
E" vvirzz2+>>4gvgqj)9":;D((,DD :&	
 ' ""adT;;K '	 	 
 "$Q9J9J5J'KK
s   71Lc           
         [        U 5        [        XSSSS9nUR                  u  p#U R                  S   R                  R                  S   nU R
                  n[        [        S5      :  nU(       a(  U R                  nSU R                  S   R                  0nO;U R                  =(       a    U R                  S   R                  (       + n[        5       nU R                  USU R                  -
  -  -   n	UR                  [        ;   a  UR                  n
O[        R                   n
U(       a  / nO [        R"                  " X)4XR$                  S9n['        U5       GH6  nU R                  U   nU R(                  S	;   GaA  U R(                  S
:X  a  UR*                  R,                  UR.                  -
  S-
  nUR*                  UR.                     USS2U4   UR*                  UR.                     -
  UR*                  U   UR*                  UR.                     -
  -  -   nO	USS2U4   nU(       ax  [0        R2                  " UUR*                  UR.                  40 UD6nU R(                  S
:X  a9  UR5                  5       nUSS2SU24==   USS2U* S24   -  ss'   USS2SU* 24   nGO U" U5      WSS2X-  US-   U-  24'   GOUR*                  U   UR*                  U* S-
     nnU" U5      U" U5      nnUUSS2U4   :*  USS2U4   U:*  -  nU(       a  U) nUSS2U4   R7                  5       nUR*                  U R
                     UU'   [0        R2                  " UUR*                  UR.                  5      n[        R8                  " U5      (       a  UR5                  5       nSUUSS24'   OU" UUU4   5      WUX-  US-   U-  24'   U R(                  S:X  a  U(       a9  [        R8                  " [        R:                  " WR<                  5      5      (       dG  U(       dK  [        R8                  " [        R:                  " WSS2X-  US-   U-  24   5      5      (       a  [?        S5      eGOU R(                  S:X  a  USS2U4   W:  n[        R8                  " U5      (       a7  U(       a  WR5                  5       nWSU UUSU24'   OWSU WUX-  X-  U-   24'   USS2U4   W:  n[        R8                  " U5      (       aC  U(       a   WR5                  5       nWU* S UUU* S24'   GOAWU* S WUUS-   U-  U-
  US-   U-  24'   GO#U R(                  S:X  Ga  U" WSS9U" WSS9nnUS::  a  US-  n['        U5       H  nUSS2U4   U:  n[        R8                  " U5      (       aA  WU   UUU4   U-
  UU   -  -   nU(       a  WR5                  5       nUUUU4'   OUWUX-  U-   4'   USS2U4   U:  n[        R8                  " U5      (       d  M  US-
  U-
  nWU   UUU4   U-
  UU   -  -   nU(       a%  WR5                  5       nUSS2S4   UUUUS-   24'   M  UWUX-  U-   4'   M     U(       d  GM  WRA                  5       nWRC                  U5        GM9     U(       a  [        RD                  " [        RF                  5      RH                  nSnW H-  nUURJ                  R                  [        RF                  :H  -  nM/     [        [        S5      :  a"  U R                  U:  a  U(       a  [?        S5      e[L        RN                  " USS9nO'U R                  (       a  [L        RP                  " W5      nU R                  (       a  W$ ['        WR                  S   5       Vs/ s H  nUS-   U-  S:w  d  M  UPM     n nUSS2U 4   $ s  snf )aa  Transform each feature data to B-splines.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    The data to transform.

Returns
-------
XBS : {ndarray, sparse matrix} of shape (n_samples, n_features * n_splines)
    The matrix of features, where n_splines is the number of bases
    elements of the B-splines, n_knots + degree - 1.
FT)r   r   r  r   r   z1.10.0r  )r"   rK   )r   r   r   r   Nr   z1X contains values beyond the limits of the knots.r   r   )nur   a  In scipy versions `<1.9.2`, the function `scipy.sparse.hstack` produces negative columns when:
1. The output shape contains `n_cols` too large to be represented by a 32bit signed integer.
. All sub-matrices to be stacked have indices of dtype `np.int32`.
To avoid this error, either use a version of scipy `>=1.9.2` or alter the `SplineTransformer` transformer to produce fewer than 2^31 output featuresr   )r   ))r   r   r!   r  rp   rI   r   r   r   r  r   r  rJ   r"   r   r$   r   zerosrK   rT   r   tsizekr   design_matrixtolilr   anyisnanr*   r   r   r   r%   r&   r'   r+   r   r   r,   )!rO   r-   r   r0   r  rI   
scipy_1_10
use_sparsekwargs_extrapolater  r"   output_listXBSrV   splnx
XBS_sparsexminxmaxf_minf_maxr   mask_invfp_minfp_maxr  linear_extrr#  r6   r   r   r+   s!                                    r<   r   SplineTransformer.transform  sx    	$etT !	NN1%''--a0	
  =#::
 ++J"/1B1N1N!O++QDNN14E4Q4Q0QJ!% $$zQ9J9J5J'KK77l"GGEJJEK((I-U**MCz"A..#C!!%FF%%3
 

SUU*Q.Acee!Q$#%%,(>a355</( A !Q$A!(!6!6355#%%"+="J ))Z7
 &0%5%5%7
"1gvg:.*Q[2II.%/8VG8%<
FI!fCAMq1u	.ABBC UU6]CEE6'A+,>d"4y#d)u!Q$AadGtO< $uH!Q$A #&%%"4AhK!(!6!6q#%%!GJ
 vvh''%/%5%5%7
23
8Q;/ILQtUVwZCq}!a%91DEEF !!W, 266"((:??*C#D#D"QAEY;N(O%O!PQ  %K  ##z1 Aw~66$<<!%/%5%5%7
49'6N
4&=1 QV#VQD1=Q]V5K"LLM Aw~66$<<!%/%5%5%7
5:F78_
4&>2
 "6'(O  !ey069q1u	>QRT
 ##x/ "%Ta#dq/Q; aKFvAQT7T>Dvvd||&+Ah!D!G*t2Cvay1P&P%)3)9)9);J2=JtQw/;FCama&7 78QT7T>Dvvd||%MA-&+Ah!D!G*t2Cvay1P&P%)3)9)9);J:Eag:NJtQQY7;FCama&7 78) ', z'--/
"":.O #R 
 *..II"S[[.."((::	 # ]733((94 N  --E:C##C(CJ #(		!"5R"5Q!a%99LPQ9Qq"5GRq'z?" Ss   _1_)	r  rI   r   rJ   r   r  r   rK   r   )   r   )
   r   NrN   )NN)r   r   r   r   r   r   r   r   rL   r   r   rP   r   r  r   r   r   r   r   rv   r>   r<   r   r   @  s    wt Xq$v>?Haf=>i45|DNO
 #c3Z()#
$D 
 +
  +& , ,\7< 5~ 6~@Z#r>   )r   ),r   r   	itertoolsr   r   r   rY   numbersr   numpyr$   scipyr   scipy.interpolater   scipy.specialr	   baser   r   r   utilsr   utils._param_validationr   r   utils.fixesr   r   utils.statsr   utils.validationr   r   r   r   r   r   r   r   __all__r=   r   r   rv   r>   r<   <module>rI     s     ) G    %  @ @  : 3 .   (Vh)= hVA	#(- A	#r>   