
    -il                     \   S r SSKrSSKJrJr  SSKJrJr  SSKr	SSK
JrJr  SSKJrJrJr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!  / SQr"S r# SS jr$S r%SS jr&S r' " S S\\\\\\S9r( " S S\(5      r) " S S\(5      r* " S S\(5      r+ " S S\\\5      r,g) zG
The :mod:`sklearn.pls` module implements Partial Least Squares (PLS).
    N)ABCMetaabstractmethod)IntegralReal)pinvsvd   )BaseEstimatorClassNamePrefixFeaturesOutMixinMultiOutputMixinRegressorMixinTransformerMixin_fit_context)ConvergenceWarning)check_arraycheck_consistent_length)Interval
StrOptions)svd_flip)FLOAT_DTYPEScheck_is_fittedvalidate_data)PLSSVDPLSCanonicalPLSRegressionc           
         [        U SSS9u  pnUR                  R                  R                  5       nSSS.n[        R
                  " U5      XT   -  [        R                  " U5      R                  -  n[        R                  " X&:  5      nUS S 2S U24   nXS U -  n[        R                  " [        R                  " [        R                  " XS U 5      5      5      $ )NF)full_matricescheck_finiteg     @@g    .A)fd)r   dtypecharlowernpmaxfinfoepssum	transpose	conjugatedot)ausvhtfactorcondranks           S/var/www/html/venv/lib/python3.13/site-packages/sklearn/cross_decomposition/_pls.py
_pinv2_oldr5       s     1E>HA"	AS!F66!9vy 288A;??2D66!(D	!UdU(A5DMA<<RVVA%4y%9:;;    c                   ^ [         R                  " U R                  5      R                  m [	        U4S jUR
                   5       5      nSnUS:X  a  [        U 5      [        U5      p[        U5       GH  nUS:X  a  [         R                  " W	U5      nO8[         R                  " U R
                  U5      [         R                  " Xf5      -  nU[         R                  " [         R                  " X5      5      T-   -  n[         R                  " X5      nUS:X  a  [         R                  " W
U5      nOC[         R                  " UR
                  U5      [         R                  " UR
                  U5      -  nU(       a0  U[         R                  " [         R                  " X5      5      T-   -  n[         R                  " X5      [         R                  " X5      T-   -  nX-
  n[         R                  " X5      U:  d  UR                  S   S:X  a    OUnGM     WS-   nUU:X  a  [        R                  " S[        5        WWU4$ ! [         a  n[        S5      UeSnAff = f)a+  Return the first left and right singular vectors of X'y.

Provides an alternative to the svd(X'y) and uses the power method instead.
With norm_y_weights to True and in mode A, this corresponds to the
algorithm section 11.3 of the Wegelin's review, except this starts at the
"update saliences" part.
c              3      >#    U  H;  n[         R                  " [         R                  " U5      T:  5      (       d  M7  Uv   M=     g 7fN)r$   anyabs).0colr'   s     r4   	<genexpr>;_get_first_singular_vectors_power_method.<locals>.<genexpr>?   s+     GcsRVVBFF3K#4E-Fsscs
   6A	Ay residual is constantNd   B   z$Maximum number of iterations reached)r$   r&   r!   r'   nextTStopIterationr5   ranger+   sqrtshapewarningswarnr   )Xymodemax_itertolnorm_y_weightsy_scoreex_weights_oldX_pinvy_pinvi	x_weightsx_score	y_weightsx_weights_diffn_iterr'   s                    @r4   (_get_first_singular_vectors_power_methodr]   2   s    ((177


C=GaccGG Ms{ $A
18_3;vw/IqssG,rvvg/GGIRWWRVVI9:S@@	&&&3;vw/IqssG,rvvgii/III	!=>DDI&&&"&&*F*LM"266.1C71771:?!- 0 UF<>PQi''U  =451<=s   I 
IIIc                     [         R                  " U R                  U5      n[        USS9u  p4nUSS2S4   USSS24   4$ )zZReturn the first left and right singular vectors of X'y.

Here the whole SVD is computed.
Fr   Nr   )r$   r+   rE   r   )rL   rM   CU_Vts         r4   _get_first_singular_vectors_svdrd   m   sB    
 	qssAA1E*HA"QT7Bq!tHr6   c                 `   U R                  SS9nX-  n UR                  SS9nX-  nU(       a7  U R                  SSS9nSXUS:H  '   X-  n UR                  SSS9nSXfS:H  '   X-  nOF[        R                  " U R                  S   5      n[        R                  " UR                  S   5      nXX4XV4$ )zkCenter X, y and scale if the scale parameter==True

Returns
-------
    X, y, x_mean, y_mean, x_std, y_std
r   axisrC   )rg   ddofg      ?        )meanstdr$   onesrI   )rL   rM   scalex_meany_meanx_stdy_stds          r4   _center_scale_xyrr   w   s     VVV^FKAVVV^FKA11%!sl	
11%!sl	

#
#--r6   c                     [         R                  " [         R                  " U 5      5      n[         R                  " X   5      nX-  n X-  ng)z7Same as svd_flip but works on 1d arrays, and is inplaceN)r$   argmaxr;   sign)r-   vbiggest_abs_val_idxru   s       r4   _svd_flip_1drx      s:     ))BFF1I.771)*DIAIAr6   c                   "  ^  \ rS rSr% Sr\" \SSSS9/S/\" SS	15      /\" S
S15      /\" SS15      /\" \SSSS9/\" \SSSS9/S/S.r	\
\S'   \ SSSS
SSSSS.S jj5       r\" SS9S 5       rSS jrS S jrS!S jrS S jrU 4S jrSrU =r$ )"_PLS   zPartial Least Squares (PLS)

This class implements the generic PLS algorithm.

Main ref: Wegelin, a survey of Partial Least Squares (PLS) methods,
with emphasis on the two-block case
https://stat.uw.edu/sites/default/files/files/reports/2000/tr371.pdf
rC   Nleftclosedboolean
regression	canonicalArB   r   nipalsr   n_componentsrm   deflation_moderN   	algorithmrO   rP   copy_parameter_constraintsT  ư>)rm   r   rN   r   rO   rP   r   c                d    Xl         X0l        X@l        X l        XPl        X`l        Xpl        Xl        g r9   )r   r   rN   rm   r   rO   rP   r   )	selfr   rm   r   rN   r   rO   rP   r   s	            r4   __init___PLS.__init__   s.     ),	
" 	r6   prefer_skip_nested_validationc           
         [        X5        [        U U[        R                  SU R                  SS9n[        US[        R                  SU R                  SS9nUR                  S:X  a  SU l        UR                  SS5      nOSU l        UR                  S	   nUR                  S   nUR                  S   nU R                  nU R                  S
:X  a  [        X45      O[        X4U5      nXg:  a  [        SU SU S35      eU R                  S:H  U l        U R                  n[        XU R                   5      u  pU l        U l        U l        U l        [        R*                  " XF45      U l        [        R*                  " XV45      U l        [        R*                  " X645      U l        [        R*                  " X645      U l        [        R*                  " XF45      U l        [        R*                  " XV45      U l        / U l        [        R:                  " U
R<                  5      R>                  n[A        U5       GH|  nU RB                  S:X  a  [        RD                  " [        RF                  " U
5      SU-  :  S	S9nSU
SS2U4'    [I        U	U
U RJ                  U RL                  U RN                  US9u  nnnU R8                  RY                  U5        OU RB                  S:X  a  [[        X5      u  p[]        WW5        [        R^                  " X5      nU(       a  SnO[        R^                  " X5      n[        R^                  " X5      U-  n[        R^                  " UU	5      [        R^                  " UU5      -  nU	[        R`                  " UU5      -  n	U R                  S:X  aI  [        R^                  " UU
5      [        R^                  " UU5      -  nU
[        R`                  " UU5      -  n
U R                  S
:X  aI  [        R^                  " UU
5      [        R^                  " UU5      -  nU
[        R`                  " UU5      -  n
XR,                  SS2U4'   XR.                  SS2U4'   UU R0                  SS2U4'   UU R2                  SS2U4'   UU R4                  SS2U4'   WU R6                  SS2U4'   GM     [        R^                  " U R,                  [c        [        R^                  " U R4                  Rd                  U R,                  5      SS95      U l3        [        R^                  " U R.                  [c        [        R^                  " U R6                  Rd                  U R.                  5      SS95      U l4        [        R^                  " U Rf                  U R6                  Rd                  5      U l5        U Rj                  U R(                  -  Rd                  U R&                  -  U l5        U R$                  U l6        U Rf                  R                  S   U l7        U $ ! [P         a6  n[S        U5      S:w  a  e [T        RV                  " SU 35         SnA  GM  SnAff = f)  Fit model to data.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    Training vectors, where `n_samples` is the number of samples and
    `n_features` is the number of predictors.

y : array-like of shape (n_samples,) or (n_samples, n_targets)
    Target vectors, where `n_samples` is the number of samples and
    `n_targets` is the number of response variables.

Returns
-------
self : object
    Fitted model.
Tr	   r!   force_writeabler   ensure_min_samplesrM   F
input_namer!   r   r   	ensure_2drC   r   r   `n_components` upper bound is . Got   instead. Reduce `n_components`.r   r   
   rf   ri   N)rN   rO   rP   rQ   r@   z$y residual is constant at iteration r   )r   )8r   r   r$   float64r   r   ndim_predict_1dreshaperI   r   r   min
ValueError_norm_y_weightsrr   rm   _x_mean_y_mean_x_std_y_stdzeros
x_weights_
y_weights_	_x_scores	_y_scoresx_loadings_y_loadings_n_iter_r&   r!   r'   rG   r   allr;   r]   rN   rO   rP   rF   strrJ   rK   appendrd   rx   r+   outerr   rE   x_rotations_y_rotations_coef_
intercept__n_features_out)r   rL   rM   npqr   rank_upper_boundrQ   Xkyky_epskyk_maskrX   rZ   r   rS   x_scoresy_ssy_scores
x_loadings
y_loadingss                          r4   fit_PLS.fit   s:   & 	 %**  
 ** 
 66Q;#D		"a A$DGGAJGGAJGGAJ((
 ,,<CI#aA, 	 *01A0B C#n$DF 
  $22kA-- HX$**H
DdlDK ((A#45((A#451"341"3488Q$5688Q$56
 "&&|$A ~~)&&b5j!8qA!$1g:
 A!YY!% HH'5	!! ##G,5('Fr'N$	 I. vvb,Hvvi3vvb,t3H "-x0JJJ"((8Z00B""k1VVHb1BFF8X4NN
bhhx44""l2VVHb1BFF8X4NN
bhhx44$-OOAqD!$-OOAqD!#+DNN1a4 #+DNN1a4 %/DQT"%/DQT"{ %L FFOO((**DOO<5Q
 FFOO((**DOO<5Q
 VVD--t/?/?/A/AB
jj4;;.11DKK?
,,#0066q9{ % 1v!99MM$H"LM	s   0X
Y!)YYc                    [        U 5        [        XU[        SS9nXR                  -  nXR                  -  n[
        R                  " XR                  5      nUbr  [        USSU[        S9nUR                  S:X  a  UR                  SS5      nX R                  -  nX R                  -  n[
        R                  " X R                  5      nXE4$ U$ )a  Apply the dimension reduction.

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

y : array-like of shape (n_samples, n_targets), default=None
    Target vectors.

copy : bool, default=True
    Whether to copy `X` and `y`, or perform in-place normalization.

Returns
-------
x_scores, y_scores : array-like or tuple of array-like
    Return `x_scores` if `y` is not given, `(x_scores, y_scores)` otherwise.
Fr   r!   resetrM   )r   r   r   r!   rC   r   )r   r   r   r   r   r$   r+   r   r   r   r   r   r   r   )r   rL   rM   r   r   r   s         r4   	transform_PLS.transformp  s    & 	$LN	\\	[[66!../=cU\A vv{IIb!$AAvva!2!23H%%r6   c                 |   [        U 5        [        US[        S9n[        R                  " XR
                  R                  5      nX0R                  -  nX0R                  -  nUbX  [        US[        S9n[        R                  " X R                  R                  5      nX@R                  -  nX@R                  -  nX44$ U$ )a  Transform data back to its original space.

Parameters
----------
X : array-like of shape (n_samples, n_components)
    New data, where `n_samples` is the number of samples
    and `n_components` is the number of pls components.

y : array-like of shape (n_samples,) or (n_samples, n_components)
    New target, where `n_samples` is the number of samples
    and `n_components` is the number of pls components.

Returns
-------
X_original : ndarray of shape (n_samples, n_features)
    Return the reconstructed `X` data.

y_original : ndarray of shape (n_samples, n_targets)
    Return the reconstructed `X` target. Only returned when `y` is given.

Notes
-----
This transformation will only be exact if `n_components=n_features`.
rL   )r   r!   rM   )r   r   r   r$   matmulr   rE   r   r   r   r   r   )r   rL   rM   X_reconstructedy_reconstructeds        r4   inverse_transform_PLS.inverse_transform  s    2 	c>))A'7'7'9'9:;;&<<'=A#\BA ii+;+;+=+=>O{{*O||+O"33r6   c                     [        U 5        [        XU[        SS9nXR                  -  nXR                  R
                  -  U R                  -   nU R                  (       a  UR                  5       $ U$ )a  Predict targets of given samples.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    Samples.

copy : bool, default=True
    Whether to copy `X` or perform in-place normalization.

Returns
-------
y_pred : ndarray of shape (n_samples,) or (n_samples, n_targets)
    Returns predicted values.

Notes
-----
This call requires the estimation of a matrix of shape
`(n_features, n_targets)`, which may be an issue in high dimensional
space.
Fr   )	r   r   r   r   r   rE   r   r   ravel)r   rL   r   y_preds       r4   predict_PLS.predict  sZ    , 	$LN	\\ZZ\\!DOO3!%!1!1v||~=v=r6   c                 B    U R                  X5      R                  X5      $ )a;  Learn and apply the dimension reduction on the train data.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    Training vectors, where `n_samples` is the number of samples and
    `n_features` is the number of predictors.

y : array-like of shape (n_samples, n_targets), default=None
    Target vectors, where `n_samples` is the number of samples and
    `n_targets` is the number of response variables.

Returns
-------
self : ndarray of shape (n_samples, n_components)
    Return `x_scores` if `y` is not given, `(x_scores, y_scores)` otherwise.
r   r   r   rL   rM   s      r4   fit_transform_PLS.fit_transform      $ xx~''--r6   c                 h   > [         TU ]  5       nSUR                  l        SUR                  l        U$ )NTF)super__sklearn_tags__regressor_tags
poor_scoretarget_tagsrequired)r   tags	__class__s     r4   r   _PLS.__sklearn_tags__  s1    w'))-&$)!r6   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   rO   rN   r   r   rm   rP   r   r   r   r   r   r   r	   )NTr9   T)__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   dict__annotations__r   r   r   r   r   r   r   r   r   __static_attributes____classcell__r   s   @r4   rz   rz      s     "(AtFCD%|[&ABCS#J'( %!234h4?@q$v67	$D 	   # * 5` 6`D%N*X>:.( r6   rz   )	metaclassc                      ^  \ rS rSr% Sr0 \R                  Er\\S'   S H  r	\R                  \	5        M      SSSSSS.U 4S	 jjjrU 4S
 jrSrU =r$ )r   i  a  PLS regression.

PLSRegression is also known as PLS2 or PLS1, depending on the number of
targets.

For a comparison between other cross decomposition algorithms, see
:ref:`sphx_glr_auto_examples_cross_decomposition_plot_compare_cross_decomposition.py`.

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

.. versionadded:: 0.8

Parameters
----------
n_components : int, default=2
    Number of components to keep. Should be in `[1, n_features]`.

scale : bool, default=True
    Whether to scale `X` and `y`.

max_iter : int, default=500
    The maximum number of iterations of the power method when
    `algorithm='nipals'`. Ignored otherwise.

tol : float, default=1e-06
    The tolerance used as convergence criteria in the power method: the
    algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less
    than `tol`, where `u` corresponds to the left singular vector.

copy : bool, default=True
    Whether to copy `X` and `y` in :term:`fit` before applying centering,
    and potentially scaling. If `False`, these operations will be done
    inplace, modifying both arrays.

Attributes
----------
x_weights_ : ndarray of shape (n_features, n_components)
    The left singular vectors of the cross-covariance matrices of each
    iteration.

y_weights_ : ndarray of shape (n_targets, n_components)
    The right singular vectors of the cross-covariance matrices of each
    iteration.

x_loadings_ : ndarray of shape (n_features, n_components)
    The loadings of `X`.

y_loadings_ : ndarray of shape (n_targets, n_components)
    The loadings of `y`.

x_scores_ : ndarray of shape (n_samples, n_components)
    The transformed training samples.

y_scores_ : ndarray of shape (n_samples, n_components)
    The transformed training targets.

x_rotations_ : ndarray of shape (n_features, n_components)
    The projection matrix used to transform `X`.

y_rotations_ : ndarray of shape (n_targets, n_components)
    The projection matrix used to transform `y`.

coef_ : ndarray of shape (n_target, n_features)
    The coefficients of the linear model such that `y` is approximated as
    `y = X @ coef_.T + intercept_`.

intercept_ : ndarray of shape (n_targets,)
    The intercepts of the linear model such that `y` is approximated as
    `y = X @ coef_.T + intercept_`.

    .. versionadded:: 1.1

n_iter_ : list of shape (n_components,)
    Number of iterations of the power method, for each
    component.

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

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

See Also
--------
PLSCanonical : Partial Least Squares transformer and regressor.

Examples
--------
>>> from sklearn.cross_decomposition import PLSRegression
>>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]
>>> y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]
>>> pls2 = PLSRegression(n_components=2)
>>> pls2.fit(X, y)
PLSRegression()
>>> y_pred = pls2.predict(X)

For a comparison between PLS Regression and :class:`~sklearn.decomposition.PCA`, see
:ref:`sphx_glr_auto_examples_cross_decomposition_plot_pcr_vs_pls.py`.
r   r   rN   r   Tr   r   rm   rO   rP   r   c                .   > [         TU ]  UUSSSUUUS9  g )Nr   r   r   r   r   r   r   r   rm   rO   rP   r   r   s         r4   r   PLSRegression.__init__m  s/     	%' 	 		
r6   c                 j   > [         TU ]  X5        U R                  U l        U R                  U l        U $ )r   )r   r   r   	x_scores_r   	y_scores_)r   rL   rM   r   s      r4   r   PLSRegression.fit{  s,    $ 	Ar6   )r   r  r   )r   r   r   r   r   rz   r   r   r   parampopr   r   r   r   r   s   @r4   r   r     sb    eN $Cd&A&A#BDB8""5) 9 
'+cu4
 
 r6   r   c                      ^  \ rS rSr% Sr0 \R                  Er\\S'   S H  r	\R                  \	5        M      SSSSSSS	.U 4S
 jjjrSrU =r$ )r   i  a>  Partial Least Squares transformer and regressor.

For a comparison between other cross decomposition algorithms, see
:ref:`sphx_glr_auto_examples_cross_decomposition_plot_compare_cross_decomposition.py`.

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

.. versionadded:: 0.8

Parameters
----------
n_components : int, default=2
    Number of components to keep. Should be in `[1, min(n_samples,
    n_features, n_targets)]`.

scale : bool, default=True
    Whether to scale `X` and `y`.

algorithm : {'nipals', 'svd'}, default='nipals'
    The algorithm used to estimate the first singular vectors of the
    cross-covariance matrix. 'nipals' uses the power method while 'svd'
    will compute the whole SVD.

max_iter : int, default=500
    The maximum number of iterations of the power method when
    `algorithm='nipals'`. Ignored otherwise.

tol : float, default=1e-06
    The tolerance used as convergence criteria in the power method: the
    algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less
    than `tol`, where `u` corresponds to the left singular vector.

copy : bool, default=True
    Whether to copy `X` and `y` in fit before applying centering, and
    potentially scaling. If False, these operations will be done inplace,
    modifying both arrays.

Attributes
----------
x_weights_ : ndarray of shape (n_features, n_components)
    The left singular vectors of the cross-covariance matrices of each
    iteration.

y_weights_ : ndarray of shape (n_targets, n_components)
    The right singular vectors of the cross-covariance matrices of each
    iteration.

x_loadings_ : ndarray of shape (n_features, n_components)
    The loadings of `X`.

y_loadings_ : ndarray of shape (n_targets, n_components)
    The loadings of `y`.

x_rotations_ : ndarray of shape (n_features, n_components)
    The projection matrix used to transform `X`.

y_rotations_ : ndarray of shape (n_targets, n_components)
    The projection matrix used to transform `y`.

coef_ : ndarray of shape (n_targets, n_features)
    The coefficients of the linear model such that `y` is approximated as
    `y = X @ coef_.T + intercept_`.

intercept_ : ndarray of shape (n_targets,)
    The intercepts of the linear model such that `y` is approximated as
    `y = X @ coef_.T + intercept_`.

    .. versionadded:: 1.1

n_iter_ : list of shape (n_components,)
    Number of iterations of the power method, for each
    component. Empty if `algorithm='svd'`.

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

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

See Also
--------
CCA : Canonical Correlation Analysis.
PLSSVD : Partial Least Square SVD.

Examples
--------
>>> from sklearn.cross_decomposition import PLSCanonical
>>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [2.,5.,4.]]
>>> y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]
>>> plsca = PLSCanonical(n_components=2)
>>> plsca.fit(X, y)
PLSCanonical()
>>> X_c, y_c = plsca.transform(X, y)
r   )r   rN   Tr   r   r   )rm   r   rO   rP   r   c                .   > [         TU ]  UUSSUUUUS9  g )Nr   r   r   r   )r   r   rm   r   rO   rP   r   r   s          r4   r   PLSCanonical.__init__  s/     	%& 	 		
r6    r   r   r   r   r   r   rz   r   r   r   r  r  r   r   r   r   s   @r4   r   r     s`    `D $Cd&A&A#BDB+""5) , 
 
 
r6   r   c                      ^  \ rS rSr% Sr0 \R                  Er\\S'   S H  r	\R                  \	5        M      SSSSSS.U 4S	 jjjrS
rU =r$ )CCAi  a  Canonical Correlation Analysis, also known as "Mode B" PLS.

For a comparison between other cross decomposition algorithms, see
:ref:`sphx_glr_auto_examples_cross_decomposition_plot_compare_cross_decomposition.py`.

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

Parameters
----------
n_components : int, default=2
    Number of components to keep. Should be in `[1, min(n_samples,
    n_features, n_targets)]`.

scale : bool, default=True
    Whether to scale `X` and `y`.

max_iter : int, default=500
    The maximum number of iterations of the power method.

tol : float, default=1e-06
    The tolerance used as convergence criteria in the power method: the
    algorithm stops whenever the squared norm of `u_i - u_{i-1}` is less
    than `tol`, where `u` corresponds to the left singular vector.

copy : bool, default=True
    Whether to copy `X` and `y` in fit before applying centering, and
    potentially scaling. If False, these operations will be done inplace,
    modifying both arrays.

Attributes
----------
x_weights_ : ndarray of shape (n_features, n_components)
    The left singular vectors of the cross-covariance matrices of each
    iteration.

y_weights_ : ndarray of shape (n_targets, n_components)
    The right singular vectors of the cross-covariance matrices of each
    iteration.

x_loadings_ : ndarray of shape (n_features, n_components)
    The loadings of `X`.

y_loadings_ : ndarray of shape (n_targets, n_components)
    The loadings of `y`.

x_rotations_ : ndarray of shape (n_features, n_components)
    The projection matrix used to transform `X`.

y_rotations_ : ndarray of shape (n_targets, n_components)
    The projection matrix used to transform `y`.

coef_ : ndarray of shape (n_targets, n_features)
    The coefficients of the linear model such that `y` is approximated as
    `y = X @ coef_.T + intercept_`.

intercept_ : ndarray of shape (n_targets,)
    The intercepts of the linear model such that `y` is approximated as
    `y = X @ coef_.T + intercept_`.

    .. versionadded:: 1.1

n_iter_ : list of shape (n_components,)
    Number of iterations of the power method, for each
    component.

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

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

See Also
--------
PLSCanonical : Partial Least Squares transformer and regressor.
PLSSVD : Partial Least Square SVD.

Examples
--------
>>> from sklearn.cross_decomposition import CCA
>>> X = [[0., 0., 1.], [1.,0.,0.], [2.,2.,2.], [3.,5.,4.]]
>>> y = [[0.1, -0.2], [0.9, 1.1], [6.2, 5.9], [11.9, 12.3]]
>>> cca = CCA(n_components=1)
>>> cca.fit(X, y)
CCA(n_components=1)
>>> X_c, y_c = cca.transform(X, y)
r   r   Tr   r   r   c                .   > [         TU ]  UUSSSUUUS9  g )Nr   rB   r   r   r   r   s         r4   r   CCA.__init__x  s/     	%& 	 		
r6   r  r   r	  r   s   @r4   r  r    sX    Xt $Cd&A&A#BDB8""5) 9 
'+cu4
 
r6   r  c                       \ rS rSr% Sr\" \SSSS9/S/S/S.r\\	S	'   SS
S
S.S jjr
\" S
S9S 5       rSS jrSS jrSrg)r   i  a  Partial Least Square SVD.

This transformer simply performs a SVD on the cross-covariance matrix
`X'y`. It is able to project both the training data `X` and the targets
`y`. The training data `X` is projected on the left singular vectors, while
the targets are projected on the right singular vectors.

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

.. versionadded:: 0.8

Parameters
----------
n_components : int, default=2
    The number of components to keep. Should be in `[1,
    min(n_samples, n_features, n_targets)]`.

scale : bool, default=True
    Whether to scale `X` and `y`.

copy : bool, default=True
    Whether to copy `X` and `y` in fit before applying centering, and
    potentially scaling. If `False`, these operations will be done inplace,
    modifying both arrays.

Attributes
----------
x_weights_ : ndarray of shape (n_features, n_components)
    The left singular vectors of the SVD of the cross-covariance matrix.
    Used to project `X` in :meth:`transform`.

y_weights_ : ndarray of (n_targets, n_components)
    The right singular vectors of the SVD of the cross-covariance matrix.
    Used to project `X` in :meth:`transform`.

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

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

See Also
--------
PLSCanonical : Partial Least Squares transformer and regressor.
CCA : Canonical Correlation Analysis.

Examples
--------
>>> import numpy as np
>>> from sklearn.cross_decomposition import PLSSVD
>>> X = np.array([[0., 0., 1.],
...               [1., 0., 0.],
...               [2., 2., 2.],
...               [2., 5., 4.]])
>>> y = np.array([[0.1, -0.2],
...               [0.9, 1.1],
...               [6.2, 5.9],
...               [11.9, 12.3]])
>>> pls = PLSSVD(n_components=2).fit(X, y)
>>> X_c, y_c = pls.transform(X, y)
>>> X_c.shape, y_c.shape
((4, 2), (4, 2))
rC   Nr|   r}   r   r   rm   r   r   T)rm   r   c                (    Xl         X l        X0l        g r9   r  )r   r   rm   r   s       r4   r   PLSSVD.__init__  s    (
	r6   r   c           	         [        X5        [        U U[        R                  SU R                  SS9n[        US[        R                  SU R                  SS9nUR                  S:X  a  UR                  SS5      nU R                  n[        UR                  S	   UR                  S   UR                  S   5      nX4:  a  [        S
U SU S35      e[        XU R                  5      u  pU l        U l        U l        U l        [        R$                  " UR&                  U5      n[)        USS9u  pgnUSS2SU24   nUSU n[+        Xh5      u  phUR&                  n	X`l        Xl        U R,                  R                  S   U l        U $ )zFit model to data.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    Training samples.

y : array-like of shape (n_samples,) or (n_samples, n_targets)
    Targets.

Returns
-------
self : object
    Fitted estimator.
Tr	   r   rM   Fr   rC   r   r   r   r   r   r_   N)r   r   r$   r   r   r   r   r   r   r   rI   r   rr   rm   r   r   r   r   r+   rE   r   r   r   r   r   )
r   rL   rM   r   r   r`   ra   r.   rc   Vs
             r4   r   
PLSSVD.fit  s   " 	 %**  
 ** 
 66Q;		"a A
 ((qwwqz1771:qwwqzB*01A0B C#n$DF 
 FV$**F
BdlDL$+t{
 FF133Nq.ba,DD#44Q7r6   c                    [        U 5        [        X[        R                  SS9nXR                  -
  U R
                  -  n[        R                  " X0R                  5      nUbz  [        USS[        R                  S9nUR                  S:X  a  UR                  SS5      nX R                  -
  U R                  -  n[        R                  " XPR                  5      nXF4$ U$ )a  
Apply the dimensionality reduction.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    Samples to be transformed.

y : array-like of shape (n_samples,) or (n_samples, n_targets),                 default=None
    Targets.

Returns
-------
x_scores : array-like or tuple of array-like
    The transformed data `X_transformed` if `y is not None`,
    `(X_transformed, y_transformed)` otherwise.
F)r!   r   rM   )r   r   r!   rC   r   )r   r   r$   r   r   r   r+   r   r   r   r   r   r   r   )r   rL   rM   Xrr   yrr   s          r4   r   PLSSVD.transform  s    & 	$5A,,$++-66"oo.=A#bjjQAvv{IIb!$ll"dkk1Bvvb//2H%%r6   c                 B    U R                  X5      R                  X5      $ )a  Learn and apply the dimensionality reduction.

Parameters
----------
X : array-like of shape (n_samples, n_features)
    Training samples.

y : array-like of shape (n_samples,) or (n_samples, n_targets),                 default=None
    Targets.

Returns
-------
out : array-like or tuple of array-like
    The transformed data `X_transformed` if `y is not None`,
    `(X_transformed, y_transformed)` otherwise.
r   r   s      r4   r   PLSSVD.fit_transform7  r   r6   )
r   r   r   r   r   r   r   rm   r   r   r   r9   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r6   r4   r   r     sh    AH "(AtFCD$D 4 
 5> 6>@@.r6   r   )r   r   r   Fr   )-r   rJ   abcr   r   numbersr   r   numpyr$   scipy.linalgr   r   baser
   r   r   r   r   r   
exceptionsr   utilsr   r   utils._param_validationr   r   utils.extmathr   utils.validationr   r   r   __all__r5   r]   rd   rr   rx   rz   r   r   r  r   r  r6   r4   <module>r&     s     ' "  "  , 8 : $ K K
5<& =B8(v.4]#]@VD VrB
4 B
Jk
$ k
\B.,.> B.r6   