
     h              
          d Z ddlmZmZ ddlZddlmZmZ ddlZ	ddl
mZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ddlmZmZ ddl m!Z! g dZ"e ed          k    rddl
m#Z$ nddl
m$Z$ d Z%	 d*dZ&d Z'd+dZ(d Z) G d d eeeeee!          Z* G d" d#e*          Z+ G d$ d%e*          Z, G d& d'e*          Z- G d( d)eee          Z.dS ),zG
The :mod:`sklearn.pls` module implements Partial Least Squares (PLS).
    )IntegralRealN)ABCMetaabstractmethod)svd   )BaseEstimatorRegressorMixinTransformerMixin)MultiOutputMixin)ClassNamePrefixFeaturesOutMixin)check_arraycheck_consistent_length)
sp_version)parse_version)svd_flip)check_is_fittedFLOAT_DTYPES)Interval
StrOptions)ConvergenceWarning)PLSCanonicalPLSRegressionPLSSVDz1.7)pinv)pinv2c           
         t          | dd          \  }}}|j        j                                        }ddd}t	          j        |          ||         z  t	          j        |          j        z  }t	          j        ||k              }|d d d |f         }||d |         z  }t	          j	        t	          j
        t	          j        ||d |                                       S )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           \/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/sklearn/cross_decomposition/_pls.py
_pinv2_oldr6   &   s     1E>>>HAq"	AS!!F6!99vay 28A;;?2D6!d(D	!!!UdU(A5D5MA<RVAr%4%y%9%9::;;;    A  ư>Fc                 n   t          j        | j                  j        	 t	          fd|j        D                       }n"# t          $ r}t          d          |d}~ww xY wd}|dk    rt          |           t          |          }
}	t          |          D ]r}|dk    rt          j	        |	|          }n0t          j	        | j        |          t          j	        ||          z  }|t          j
        t          j	        ||                    z   z  }t          j	        | |          }|dk    rt          j	        |
|          }n5t          j	        |j        |          t          j	        |j        |          z  }|r-|t          j
        t          j	        ||                    z   z  }t          j	        ||          t          j	        ||          z   z  }||z
  }t          j	        ||          |k     s|j        d         dk    r n|}t|dz   }||k    rt          j        dt                     |||fS )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   p   K   | ]0}t          j        t          j        |          k              ,|V  1d S N)r%   anyabs).0colr(   s     r5   	<genexpr>z;_get_first_singular_vectors_power_method.<locals>.<genexpr>E   s?      GGsRVBF3KK#4E-F-FGsGGGGGGr7   Y residual is constantNd   B   z$Maximum number of iterations reached)r%   r'   r"   r(   nextTStopIterationr6   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                    @r5   (_get_first_singular_vectors_power_methodr`   8   s-    (17


C=GGGGacGGGGG = = =4551<= Ms{{ $A
18__ " "3;;vw//IIqsG,,rvgw/G/GGIRWRVIy99::S@@	&I&&3;;vw//IIqsG,,rvgi/I/III 	E	9!=!=>>DDI&I&&"&I*F*F*LM"]26..11C77171:??E!UF<>PQQQi''s    A 
A!AA!c                     t          j        | j        |          }t          |d          \  }}}|dddf         |dddf         fS )zbReturn the first left and right singular vectors of X'Y.

    Here the whole SVD is computed.
    Fr   Nr   )r%   r,   rH   r   )rO   rP   CU_Vts         r5   _get_first_singular_vectors_svdrg   s   sP    
 	qsAA1E***HAq"QQQT7Bq!!!tHr7   Tc                    |                      d          }| |z  } |                     d          }||z  }|rK|                     dd          }d||dk    <   | |z  } |                    dd          }d||dk    <   ||z  }n>t          j        | j        d                   }t          j        |j        d                   }| |||||fS )z{Center X, Y and scale if the scale parameter==True

    Returns
    -------
        X, Y, x_mean, y_mean, x_std, y_std
    r   axisrF   )rj   ddofg      ?        )meanstdr%   onesrL   )rO   rP   scalex_meany_meanx_stdy_stds          r5   _center_scale_xyru   }   s     VVV^^FKAVVV^^FKA 	$11%%!esl	U
11%%!esl	U

##
##a--r7   c                     t          j        t          j        |                     }t          j        | |                   }| |z  } ||z  }dS )z7Same as svd_flip but works on 1d arrays, and is inplaceN)r%   argmaxr?   sign)r.   vbiggest_abs_val_idxrx   s       r5   _svd_flip_1dr{      sG     )BF1II..71()**DIAIAAAr7   c                   B   e Zd ZU dZ eeddd          gdg eddh          g ed	d
h          g eddh          g eeddd          g eeddd          gdgdZe	e
d<   e	 dddd	dddddd            Zd ZddZddZd dZddZed             Zd ZdS )!_PLSa  Partial 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
    rF   Nleftclosedboolean
regression	canonicalr8   rE   r   nipalsr   n_componentsrp   deflation_moderQ   	algorithmrR   rS   copy_parameter_constraintsr   Tr9   r:   )rp   r   rQ   r   rR   rS   r   c                v    || _         || _        || _        || _        || _        || _        || _        || _        d S r=   )r   r   rQ   rp   r   rR   rS   r   )	selfr   rp   r   rQ   r   rR   rS   r   s	            r5   __init__z_PLS.__init__   sB     ),	
" 			r7   c           	      .   |                                   t          ||           |                     |t          j        | j        d          }t          |dt          j        | j        d          }|j        dk    r|                    dd          }|j	        d         }|j	        d         }|j	        d         }| j
        }| j        d	k    r|nt          |||          }||k    rt          d
| d| d          | j        dk    | _        | j        }t          ||| j                  \  }	}
| _        | _        | _        | _        t          j        ||f          | _        t          j        ||f          | _        t          j        ||f          | _        t          j        ||f          | _        t          j        ||f          | _        t          j        ||f          | _        g | _        t          j        |
j                  j        }tA          |          D ]w}| j!        dk    rt          j"        t          j#        |
          d|z  k     d          }d|
dd|f<   	 tI          |	|
| j%        | j&        | j'        |          \  }}}nD# tP          $ r7}tS          |          dk    r tU          j+        d|            Y d}~ nd}~ww xY w| j        ,                    |           n| j!        dk    rt[          |	|
          \  }}t]          ||           t          j/        |	|          }|rd}nt          j/        ||          }t          j/        |
|          |z  }t          j/        ||	          t          j/        ||          z  }|	t          j0        ||          z  }	| j        dk    rCt          j/        ||
          t          j/        ||          z  }|
t          j0        ||          z  }
| j        d	k    rCt          j/        ||
          t          j/        ||          z  }|
t          j0        ||          z  }
|| j        dd|f<   || j        dd|f<   || j        dd|f<   || j        dd|f<   || j        dd|f<   || j        dd|f<   yt          j/        | j        tc          t          j/        | j        j2        | j                  d                    | _3        t          j/        | j        tc          t          j/        | j        j2        | j                  d                    | _4        t          j/        | j3        | j        j2                  | _5        | j5        | j        z  j2        | _5        | j        | _6        | j3        j	        d         | _7        | S )  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.
        r   r"   r   ensure_min_samplesrP   F
input_namer"   r   	ensure_2drF   r   r   `n_components` upper bound is . Got   instead. Reduce `n_components`.r   r   
   ri   rl   N)rQ   rR   rS   rT   rC   z$Y residual is constant at iteration r   )r   )8_validate_paramsr   _validate_datar%   float64r   r   ndimreshaperL   r   r   min
ValueError_norm_y_weightsru   rp   _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(   rJ   r   allr?   r`   rQ   rR   rS   rI   strrM   rN   appendrg   r{   r,   outerr   rH   x_rotations_y_rotations__coef_
intercept__n_features_out)r   rO   rP   npqr   rank_upper_boundrT   XkYkY_epskYk_maskr[   r]   r   rV   x_scoresy_ssy_scores
x_loadings
y_loadingss                          r5   fitz_PLS.fit   s   $ 	1%%%RZdiA   
 
 #RZdi5
 
 
 6Q;;		"a  AGAJGAJGAJ( !% 3| C C11QPQST***F1A F F#F F F  
  $2kA- HXq$*H
 H
DBdlDK (A|#455(A|#4551l"3441l"3448Q$5668Q$566
 ""&|$$ =	0 =	0A ~))&b5j!8qAAA!$111g:
 A!Y!% H'5  	!! %   1vv!999M"L"L"LMMMEEEEE	 ##G,,,,5(('Fr2'N'N$	9 I... vb),,H 4vi33vb),,t3H "--x0J0JJJ"(8Z000B"k11VHb11BF8X4N4NN
bhx444"l22VHb11BF8X4N4NN
bhx444$-DOAAAqD!$-DOAAAqD!#+DN111a4 #+DN111a4 %/DQQQT"%/DQQQT"" FO"&)+T_==ERRR
 
 FO"&)+T_==ERRR
 

 fT.0@0BCC{T[03,#06q9s   (J
K+KKc                    t          |            |                     ||t          d          }|| j        z  }|| j        z  }t          j        || j                  }|lt          |dd|t                    }|j	        dk    r|
                    dd          }|| j        z  }|| j        z  }t          j        || j                  }||fS |S )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"   resetNrP   )r   r   r   r"   rF   r   )r   r   r   r   r   r%   r,   r   r   r   r   r   r   r   )r   rO   rP   r   r   r   s         r5   	transformz_PLS.transformi  s    & 	LNN	T\	T[6!T.//=cU\  A v{{IIb!$$AAva!233HX%%r7   c                 X   t          |            t          |dt                    }t          j        || j        j                  }|| j        z  }|| j        z  }|Nt          |dt                    }t          j        || j	        j                  }|| j
        z  }|| j        z  }||fS |S )ae  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, n_components)
            New target, where `n_samples` is the number of samples
            and `n_components` is the number of pls components.

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

        Y_reconstructed : 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`.
        rO   )r   r"   NrP   )r   r   r   r%   matmulr   rH   r   r   r   r   r   )r   rO   rP   X_reconstructedY_reconstructeds        r5   inverse_transformz_PLS.inverse_transform  s    2 	c>>>)At'7'9::4;&4<'=A#\BBBA i4+;+=>>Ot{*Ot|+O"O33r7   c                     t          |            |                     ||t          d          }|| j        z  }|| j        z  }|| j        j        z  }|| j        z   S )aU  Predict targets of given samples.

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

        copy : bool, default=True
            Whether to copy `X` and `Y`, 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   r   rH   r   )r   rO   r   Ypreds       r5   predictz_PLS.predict  sa    , 	LNN	T\	T[DKM!t&&r7   c                 V    |                      ||                              ||          S )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   rO   ys      r5   fit_transformz_PLS.fit_transform  &    $ xx1~~''1---r7   c                     t          | d          r2t          | dd          r!t          j        dt                     d| _        | j        j        S )z%The coefficients of the linear model.r   _coef_warningTzThe attribute `coef_` will be transposed in version 1.3 to be consistent with other linear models in scikit-learn. Currently, `coef_` has a shape of (n_features, n_targets) and in the future it will have a shape of (n_targets, n_features).F)hasattrgetattrrM   rN   FutureWarningr   r   rH   r   s    r5   coef_z
_PLS.coef_  s\     4"" 		'wt_d'K'K 		'M@    "'D{}r7   c                     dddS )NTF)
poor_score
requires_y r   s    r5   
_more_tagsz_PLS._more_tags  s    "%888r7   r   )NTr=   T)__name__
__module____qualname____doc__r   r   r   r   r   dict__annotations__r   r   r   r   r   r   r   propertyr   r   r   r7   r5   r}   r}      s          "(AtFCCCD%:|[&ABBCS#J''( j%!2334Xh4???@q$v6667	$ 	$D 	 	 	   #    ^*T T Tl% % % %N* * * *X' ' ' '>. . . .(   X&9 9 9 9 9r7   r}   )	metaclassc                        e Zd ZU dZi ej        Zeed<   dD ]Ze	                    e           	 dddddd fd	Z
 fd
Z xZS )r   a  PLS regression.

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

    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`.

    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_features, n_components)
        The projection matrix used to transform `Y`.

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

    intercept_ : ndarray of shape (n_targets,)
        The intercepts of the linear model such that `Y` is approximated as
        `Y = X @ coef_ + 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)
    r   r   rQ   r   r   Tr9   r:   rp   rR   rS   r   c          
      Z    t                                          ||ddd|||           d S )Nr   r8   r   r   superr   r   r   rp   rR   rS   r   	__class__s         r5   r   zPLSRegression.__init__t  sH     	%' 	 		
 		
 		
 		
 		
r7   c                 |    t                                          ||           | j        | _        | j        | _        | S )r   )r   r   r   	x_scores_r   	y_scores_)r   rO   rP   r   s      r5   r   zPLSRegression.fit  s4    $ 	Aqr7   r   )r   r   r   r   r}   r   r   r   parampopr   r   __classcell__r   s   @r5   r   r     s         ` `D $Cd&A#BDBBB8 * *""5)))) 
'+cu4
 
 
 
 
 
 
        r7   r   c                        e Zd ZU dZi ej        Zeed<   dD ]Ze	                    e           	 ddddddd	 fd
Z
 xZS )r   a  Partial Least Squares transformer and regressor.

    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_features, n_components)
        The projection matrix used to transform `Y`.

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

    intercept_ : ndarray of shape (n_targets,)
        The intercepts of the linear model such that `Y` is approximated as
        `Y = X @ coef_ + 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   rQ   r   Tr   r9   r:   )rp   r   rR   rS   r   c          
      Z    t                                          ||dd||||           d S )Nr   r8   r   r   )r   r   rp   r   rR   rS   r   r   s          r5   r   zPLSCanonical.__init__  sH     	%& 	 		
 		
 		
 		
 		
r7   r   r   r   r   r   r}   r   r   r   r   r   r   r   r   s   @r5   r   r     s         ] ]~ $Cd&A#BDBBB+ * *""5)))) 
 
 
 
 
 
 
 
 
 
 
 
r7   r   c                        e Zd ZU dZi ej        Zeed<   dD ]Ze	                    e           	 d
ddddd fd	Z
 xZS )CCAap  Canonical Correlation Analysis, also known as "Mode B" PLS.

    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_features, n_components)
        The projection matrix used to transform `Y`.

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

    intercept_ : ndarray of shape (n_targets,)
        The intercepts of the linear model such that `Y` is approximated as
        `Y = X @ coef_ + 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   r   Tr9   r:   r   c          
      Z    t                                          ||ddd|||           d S )Nr   rE   r   r   r   r   s         r5   r   zCCA.__init__y  sH     	%& 	 		
 		
 		
 		
 		
r7   r   r   r   s   @r5   r  r    s         U Un $Cd&A#BDBBB8 * *""5)))) 
'+cu4
 
 
 
 
 
 
 
 
 
 
r7   r  c                   p    e Zd ZU dZ eeddd          gdgdgdZeed<   dd
d
ddZ	d Z
ddZddZdS )r   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))
    rF   Nr~   r   r   r   rp   r   r   r   T)rp   r   c                0    || _         || _        || _        d S r=   r  )r   r   rp   r   s       r5   r   zPLSSVD.__init__  s    (
			r7   c                 >   |                                   t          ||           |                     |t          j        | j        d          }t          |dt          j        | j        d          }|j        dk    r|                    dd          }| j	        }t          |j        d         |j        d         |j        d                   }||k    rt          d	| d
| d          t          ||| j                  \  }}| _        | _        | _        | _        t          j        |j        |          }t+          |d          \  }}}|ddd|f         }|d|         }t-          ||          \  }}|j        }	|| _        |	| _        | j        j        d         | _        | S )aJ  Fit 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.
        r   r   rP   Fr   rF   r   r   r   r   r   rb   N)r   r   r   r%   r   r   r   r   r   r   r   rL   r   ru   rp   r   r   r   r   r,   rH   r   r   r   r   r   )
r   rO   rP   r   r   rc   rd   r/   rf   Vs
             r5   r   z
PLSSVD.fit  s     	1%%%RZdiA   
 
 #RZdi5
 
 
 6Q;;		"a  A
 (qwqz171:qwqzBB***F1A F F#F F F  
 FVq$*F
 F
B1dlDL$+t{
 F13NNq...1baaa,B2D#4Q7r7   c                    t          |            |                     |t          j        d          }|| j        z
  | j        z  }t          j        || j                  }|nt          |ddt          j                  }|j	        dk    r|
                    dd          }|| j        z
  | j        z  }t          j        || j                  }||fS |S )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   NrP   )r   r   r"   rF   r   )r   r   r%   r   r   r   r,   r   r   r   r   r   r   r   )r   rO   rP   Xrr   Yrr   s          r5   r   zPLSSVD.transform  s    & 	5AA$,$+-6"do..=A#bjQQQAv{{IIb!$$dl"dk1Bvb$/22HX%%r7   c                 V    |                      ||                              ||          S )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      r5   r   zPLSSVD.fit_transform/  r   r7   r   r=   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   r5   r   r     s         A AH "(AtFCCCD$ $D   4     
6 6 6p   @. . . . . .r7   r   )r8   r9   r:   Fr   )/r   numbersr   r   rM   abcr   r   numpyr%   scipy.linalgr   baser	   r
   r   r   r   utilsr   r   utils.fixesr   r   utils.extmathr   utils.validationr   r   utils._param_validationr   r   
exceptionsr   __all__r   r   r6   r`   rg   ru   r{   r}   r   r   r  r   r   r7   r5   <module>r     s    # " " " " " " "  ' ' ' ' ' ' ' '           B B B B B B B B B B # # # # # # 2 2 2 2 2 2 8 8 8 8 8 8 8 8 $ $ $ $ $ $ ' ' ' ' ' ' $ $ $ $ $ $ < < < < < < < < : : : : : : : : + + + + + +
5
5
5 u%%%% +******""""""< < <& =B8( 8( 8( 8(v  . . . .4  c9 c9 c9 c9 c9#c9 c9 c9 c9LQ Q Q Q QD Q Q Qh
 
 
 
 
4 
 
 
Dh
 h
 h
 h
 h
$ h
 h
 h
Vy. y. y. y. y.,.> y. y. y. y. y.r7   