Ë
    êÿæi‘�  ã            
       ó^  — d Z ddlZddlmZmZ ddlmZmZ ddlZ	ddl
mZmZ ddlmZmZmZmZmZ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 ddlmZm Z m!Z! g d¢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,y)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           
      óÂ  — t        | dd¬«      \  }}}|j                  j                  j                  «       }dddœ}t	        j
                  |«      ||   z  t	        j                  |«      j                  z  }t	        j                  ||kD  «      }|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           úu/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/sklearn/cross_decomposition/_pls.pyÚ
_pinv2_oldr4       sº   € ô �1 E¸Ô>�H€A€qˆ"à	�‰�‰×ÑÓ€AØ˜SÑ!€FÜ�6‰6�!‹9�v˜a‘yÑ ¤2§8¡8¨A£;§?¡?Ñ2€DÜ�6‰6�!�d‘(Ó€Dà	Š!ˆUˆdˆUˆ(‰€AØˆˆ5ˆDˆ�M€AÜ�<‰<œŸ™¤R§V¡V¨A¨r°%°4¨yÓ%9Ó:Ó;Ð;ó    c                 ó’  ‡— t        j                  | j                  «      j                  Š	 t	        ˆfd„|j
                  D «       «      }d}|dk(  rt        | «      t        |«      }
}	t        |«      D �]�  }|dk(  rt        j                  	|«      }n7t        j                  | j
                  |«      t        j                  ||«      z  }|t        j                  t        j                  ||«      «      ‰z   z  }t        j                  | |«      }|dk(  rt        j                  
|«      }nAt        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|}�Œ� dz   }||k(  rt        j                  dt        «       |fS # t        $ r}t        d«      |‚d}~ww xY w)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   óz   •K  — | ]2  }t        j                  t        j                  |«      ‰kD  «      sŒ/|–— Œ4 y ­w©N)r#   ÚanyÚabs)Ú.0Úcolr&   s     €r3   Ú	<genexpr>z;_get_first_singular_vectors_power_method.<locals>.<genexpr>?   s*   øè ø€ ÐG¡c˜s¬R¯V©V´B·F±F¸3³KÀ#Ñ4EÕ-F”s¡cùs   ƒ0;´;úy residual is constantNéd   ÚBé   z$Maximum number of iterations reached)r#   r%   r    r&   ÚnextÚTÚStopIterationr4   Ú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                    @r3   Ú(_get_first_singular_vectors_power_methodr[   2   sá  ø€ ô �(‰(�1—7‘7Ó
×
Ñ
€Cð=ÜÓG a§c¢cÓGÓGˆð €Màˆs‚{ô $ A›¬
°1«�ˆä�8�_ˆØ�3Š;ÜŸ™˜v wÓ/‰IäŸ™˜qŸs™s GÓ,¬r¯v©v°g¸wÓ/GÑGˆIà”R—W‘WœRŸV™V I¨yÓ9Ó:¸SÑ@Ñ@ˆ	Ü—&‘&˜˜IÓ&ˆà�3Š;ÜŸ™˜v wÓ/‰IäŸ™˜qŸs™s GÓ,¬r¯v©v°g·i±iÀÓ/IÑIˆIáØœŸ™¤§¡¨	°9Ó!=Ó>ÀÑDÑDˆIä—&‘&˜˜IÓ&¬"¯&©&°¸IÓ*FÈÑ*LÑMˆà" ]Ñ2ˆÜ�6‰6�. .Ó1°CÒ7¸1¿7¹7À1¹:Èº?ÙØ!Šð- ð0 �‰U€FØ�ÒÜ�‰Ð<Ô>PÔQà�i Ð'Ð'øôU ò =ÜÐ4Ó5¸1Ð<ûð=ús   ¬H, È,	IÈ5IÉI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*   rC   r   )rJ   rK   ÚCÚUÚ_ÚVts         r3   Ú_get_first_singular_vectors_svdrb   m   sD   € ô
 	�‰ˆq�s‰s�A‹€AÜ�1 EÔ*�H€A€qˆ"ØŠQ�ˆT‰7�B�qš!�t‘HÐÐr5   c                 ó|  — | j                  d¬«      }| |z  } |j                  d¬«      }||z  }|rA| j                  dd¬«      }d||dk(  <   | |z  } |j                  dd¬«      }d||dk(  <   ||z  }nDt        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   ©ÚaxisrA   )re   Úddofg      ð?ç        )ÚmeanÚstdr#   ÚonesrG   )rJ   rK   ÚscaleÚx_meanÚy_meanÚx_stdÚy_stds          r3   Ú_center_scale_xyrp   w   sÈ   € ð �V‰V˜ˆV‹^€FØˆ�K€AØ�V‰V˜ˆV‹^€FØˆ�K€AáØ—‘˜1 1�Ó%ˆØ!ˆˆe�s‰lÑØ	ˆU‰
ˆØ—‘˜1 1�Ó%ˆØ!ˆˆe�s‰lÑØ	ˆU‰
‰ä—‘˜Ÿ™ ™
Ó#ˆÜ—‘˜Ÿ™ ™
Ó#ˆØˆa�˜ ¨Ð-Ð-r5   c                 ó˜   — t        j                  t        j                  | «      «      }t        j                  | |   «      }| |z  } ||z  }y)z7Same as svd_flip but works on 1d arrays, and is inplaceN)r#   Úargmaxr:   Úsign)r,   ÚvÚbiggest_abs_val_idxrs   s       r3   Ú_svd_flip_1drv   ‘   sA   € ô Ÿ)™)¤B§F¡F¨1£IÓ.ÐÜ�7‰7�1Ð(Ñ)Ó*€DØˆ�I€AØˆ�I�Ar5   c                   ó$  ‡ — 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 ed¬«      d„ «       Zdd„Zdd„Zdd„Zdd„Zˆ fd„Zˆ xZ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
    rA   NÚleft©ÚclosedÚbooleanÚ
regressionÚ	canonicalÚAr@   r   Únipalsr   ©Ún_componentsrk   Údeflation_moderL   Ú	algorithmrM   rN   ÚcopyÚ_parameter_constraintsTéô  ç�íµ ÷Æ°>)rk   rƒ   rL   r„   rM   rN   r…   c                ót   — || _         || _        || _        || _        || _        || _        || _        || _        y r8   )r‚   rƒ   rL   rk   r„   rM   rN   r…   )	Úselfr‚   rk   rƒ   rL   r„   rM   rN   r…   s	            r3   Ú__init__z_PLS.__init__·   s>   € ð )ˆÔØ,ˆÔØˆŒ	ØˆŒ
Ø"ˆŒØ ˆŒØˆŒØˆ�	r5   ©Úprefer_skip_nested_validationc           	      ó¦  — t        ||«       t        | |t        j                  d| j                  d¬«      }t        |dt        j                  d| j                  d¬«      }|j                  dk(  rd| _        |j                  dd«      }nd| _        |j                  d	   }|j                  d   }|j                  d   }| j                  }| j                  d
k(  rt        ||«      nt        |||«      }||kD  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 �]q  }| jB                  dk(  r‰t        jD                  t        jF                  |
«      d|z  k  d	¬«      }d|
dd…|f<   	 tI        |	|
| jJ                  | jL                  | jN                  |¬«      \  }}}| j8                  jY                  |«       n| jB                  dk(  rt[        |	|
«      \  }}t]        «       t        j^                  |	|«      }|rd}nt        j^                  ||«      }t        j^                  |
|«      |z  }t        j^                  ||	«      t        j^                  ||«      z  }|	t        j`                  ||«      z  }	| j                  dk(  rFt        j^                  ||
«      t        j^                  ||«      z  }|
t        j`                  ||«      z  }
| j                  d
k(  rFt        j^                  ||
«      t        j^                  ||«      z  }|
t        j`                  ||«      z  }
|| j,                  dd…|f<   || j.                  dd…|f<   || j0                  dd…|f<   || j2                  dd…|f<   || j4                  dd…|f<   | j6                  dd…|f<   �Œt t        j^                  | j,                  tc        t        j^                  | j4                  jd                  | j,                  «      d¬«      «      | _3        t        j^                  | j.                  tc        t        j^                  | j6                  jd                  | j.                  «      d¬«      «      | _4        t        j^                  | jf                  | j6                  jd                  «      | _5        | jj                  | j(                  z  jd                  | j&                  z  | _5        | j$                  | _6        | jf                  j                  d   | _7        | S # tP        $ r3}tS        |«      dk7  r‚ tU        jV                  d|› �«       Y d}~ �Œšd}~ww xY w)á  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.
        Té   ©r    Úforce_writeabler…   Úensure_min_samplesrK   F©Ú
input_namer    r’   r…   Ú	ensure_2drA   éÿÿÿÿr   r}   ú`n_components` upper bound is ú. Got ú  instead. Reduce `n_components`.r~   r€   é
   rd   rg   N)rL   rM   rN   rO   r>   z$y residual is constant at iteration r   )r   )8r   r   r#   Úfloat64r…   r   ÚndimÚ_predict_1dÚreshaperG   r‚   rƒ   ÚminÚ
ValueErrorÚ_norm_y_weightsrp   rk   Ú_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&   rE   r„   Úallr:   r[   rL   rM   rN   rD   ÚstrrH   rI   Úappendrb   rv   r*   Úouterr   rC   Úx_rotations_Úy_rotations_Úcoef_Ú
intercept_Ú_n_features_out)rŠ   rJ   rK   ÚnÚpÚqr‚   Úrank_upper_boundrO   ÚXkÚykÚy_epsÚkÚyk_maskrV   rX   r®   rQ   Úx_scoresÚy_ssÚy_scoresÚ
x_loadingsÚ
y_loadingss                          r3   Úfitz_PLS.fitÍ   sa  € ô& 	   1Ô%ÜØØÜ—*‘*Ø Ø—‘Ø ô
ˆô ØØÜ—*‘*Ø Ø—‘Øô
ˆð �6‰6�QŠ;Ø#ˆDÔØ—	‘	˜"˜aÓ ‰Aà$ˆDÔà�G‰G�A‰JˆØ�G‰G�A‰JˆØ�G‰G�A‰Jˆà×(Ñ(ˆð
 ×,Ñ,°Ò<ŒC��1ŒIÄ#ÀaÈÈAÃ,ð 	ð Ð*Ò*ÜØ0Ð1AÐ0Bð CØ#�nÐ$DðFóð ð
  $×2Ñ2°kÑAˆÔØ×-Ñ-ˆô HXØˆq�$—*‘*óH
ÑDˆˆB�”˜dœl¨D¬K¸¼ô Ÿ(™( A |Ð#4Ó5ˆŒÜŸ(™( A |Ð#4Ó5ˆŒÜŸ™ 1 lÐ"3Ó4ˆŒÜŸ™ 1 lÐ"3Ó4ˆŒÜŸ8™8 Q¨Ð$5Ó6ˆÔÜŸ8™8 Q¨Ð$5Ó6ˆÔØˆŒô
 —‘˜Ÿ™Ó"×&Ñ&ˆÜ�|×$ˆAð �~‰~ Ò)äŸ&™&¤§¡¨£¨b°5©jÑ!8¸qÔA�Ø!$�’1�g�:‘ðô
 AØØØ!ŸY™YØ!%§¡Ø ŸH™HØ'5ôñ	Ø!Ø!Øð —‘×#Ñ# GÕ,à—‘ 5Ò(Ü'FÀrÈ2Ó'NÑ$�	˜9ô ˜ IÔ.ô —v‘v˜b )Ó,ˆHÙØ‘ä—v‘v˜i¨Ó3�Ü—v‘v˜b )Ó,¨tÑ3ˆHô Ÿ™ ¨"Ó-´·±°xÀÓ0JÑJˆJØ”"—(‘(˜8 ZÓ0Ñ0ˆBà×"Ñ" kÒ1äŸV™V H¨bÓ1´B·F±F¸8ÀXÓ4NÑN�
Ø”b—h‘h˜x¨Ó4Ñ4�Ø×"Ñ" lÒ2äŸV™V H¨bÓ1´B·F±F¸8ÀXÓ4NÑN�
Ø”b—h‘h˜x¨Ó4Ñ4�à$-ˆD�O‰OšA˜q˜DÑ!Ø$-ˆD�O‰OšA˜q˜DÑ!Ø#+ˆD�N‰Nš1˜a˜4Ñ Ø#+ˆD�N‰Nš1˜a˜4Ñ Ø%/ˆD×ÑšQ ˜TÑ"Ø%/ˆD×ÑšQ ˜TÓ"ð{ %ôL ŸF™FØ�O‰OÜ”—‘˜×(Ñ(×*Ñ*¨D¯O©OÓ<È5ÔQó
ˆÔô ŸF™FØ�O‰OÜ”—‘˜×(Ñ(×*Ñ*¨D¯O©OÓ<È5ÔQó
ˆÔô —V‘V˜D×-Ñ-¨t×/?Ñ/?×/AÑ/AÓBˆŒ
Ø—j‘j 4§;¡;Ñ.×1Ñ1°D·K±KÑ?ˆŒ
ØŸ,™,ˆŒØ#×0Ñ0×6Ñ6°qÑ9ˆÔØˆøô{ %ò Ü˜1“vÐ!9Ò9ØÜ—M‘MÐ$HÈÈÐ"LÔMÞûð	ús   Ê	3XØ	YØ'YÙYc                 ó²  — t        | «       t        | ||t        d¬«      }|| j                  z  }|| j                  z  }t        j                  || j                  «      }|�wt        |dd|t        ¬«      }|j                  dk(  r|j                  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    ÚresetrK   )r•   r–   r…   r    rA   r—   )r   r   r   r£   r¥   r#   r*   r³   r   r�   rŸ   r¤   r¦   r´   )rŠ   rJ   rK   r…   rÁ   rÃ   s         r3   Ú	transformz_PLS.transformp  sÉ   € ô& 	˜ÔÜ˜$ ¨´LÈÔNˆà	ˆT�\‰\ÑˆØ	ˆT�[‰[Ñˆä—6‘6˜!˜T×.Ñ.Ó/ˆØˆ=ÜØ˜c¨U¸Ä\ôˆAð �v‰v˜Š{Ø—I‘I˜b !Ó$�Ø�—‘ÑˆAØ�—‘ÑˆAÜ—v‘v˜a ×!2Ñ!2Ó3ˆHØ˜XÐ%Ð%àˆr5   c                 ó�  — t        | «       t        |dt        ¬«      }t        j                  || j
                  j                  «      }|| j                  z  }|| j                  z  }|�^t        |dt        ¬«      }t        j                  || j                  j                  «      }|| j                  z  }|| j                  z  }||fS |S )ak  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`.
        rJ   )r•   r    rK   )r   r   r   r#   Úmatmulr¬   rC   r¥   r£   r­   r¦   r¤   )rŠ   rJ   rK   ÚX_reconstructedÚy_reconstructeds        r3   Úinverse_transformz_PLS.inverse_transform—  s®   € ô2 	˜ÔÜ˜ c´Ô>ˆäŸ)™) A t×'7Ñ'7×'9Ñ'9Ó:ˆà˜4Ÿ;™;Ñ&ˆØ˜4Ÿ<™<Ñ'ˆàˆ=Ü˜A¨#´\ÔBˆAä Ÿi™i¨¨4×+;Ñ+;×+=Ñ+=Ó>ˆOà˜tŸ{™{Ñ*ˆOØ˜tŸ|™|Ñ+ˆOØ" OÐ3Ð3àÐr5   c                 óæ   — t        | «       t        | ||t        d¬«      }|| j                  z  }|| j                  j
                  z  | j                  z   }| j                  r|j                  «       S |S )aL  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µ   rC   r¶   rž   Úravel)rŠ   rJ   r…   Úy_preds       r3   Úpredictz_PLS.predictÃ  s`   € ô, 	˜ÔÜ˜$ ¨´LÈÔNˆà	ˆT�\‰\ÑˆØ�T—Z‘Z—\‘\Ñ! D§O¡OÑ3ˆØ!%×!1Ò!1ˆv�|‰|‹~Ð=°vÐ=r5   c                 óF   — | j                  ||«      j                  ||«      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Š   rJ   rK   s      r3   Úfit_transformz_PLS.fit_transformà  ó!   € ð$ �x‰x˜˜1‹~×'Ñ'¨¨1Ó-Ð-r5   c                 óh   •— t         ‰| �  «       }d|j                  _        d|j                  _        |S )NTF)ÚsuperÚ__sklearn_tags__Úregressor_tagsÚ
poor_scoreÚtarget_tagsÚrequired)rŠ   ÚtagsÚ	__class__s     €r3   rÛ   z_PLS.__sklearn_tags__ô  s1   ø€ Ü‰wÑ'Ó)ˆØ)-ˆ×ÑÔ&Ø$)ˆ×ÑÔ!Øˆr5   ©r�   )NTr8   ©T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r†   ÚdictÚ__annotations__r   r‹   r   rÆ   rÊ   rÏ   rÓ   r×   rÛ   Ú__classcell__©rá   s   @r3   rx   rx   ›   sö   ø… ññ " (¨A¨t¸FÔCÐDØ�Ù% |°[Ð&AÓBÐCÙ˜S #˜JÓ'Ð(Ù  %¨Ð!2Ó3Ð4Ù˜h¨¨4¸Ô?Ð@Ù˜˜q $¨vÔ6Ð7Ø�ñ	$Ð˜Dó 	ð ð ðð Ø#ØØØØØóó ðñ* °Ô5ñ`ó 6ð`óD%óN*óX>ó:.÷(ð r5   rx   )Ú	metaclassc                   ó”   ‡ — e Zd ZU dZi ej
                  ¥Zeed<   dD ]  Zej                  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.

    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ƒ   rL   r„   Tr‡   rˆ   ©rk   rM   rN   r…   c          
      ó4   •— t         ‰| �  ||ddd|||¬«       y )Nr}   r   r€   r�   ©rÚ   r‹   ©rŠ   r‚   rk   rM   rN   r…   rá   s         €r3   r‹   zPLSRegression.__init__m  s/   ø€ ô 	‰ÑØ%ØØ'ØØØØØð 	õ 		
r5   c                 ól   •— t         ‰| �  ||«       | j                  | _        | j                  | _        | S )r�   )rÚ   rÆ   rª   Ú	x_scores_r«   Ú	y_scores_)rŠ   rJ   rK   rá   s      €r3   rÆ   zPLSRegression.fit{  s.   ø€ ô$ 	‰‰�A�qÔàŸ™ˆŒØŸ™ˆŒØˆr5   râ   )rä   rå   ræ   rç   rx   r†   rè   ré   ÚparamÚpopr‹   rÆ   rê   rë   s   @r3   r   r   û  s]   ø… ñeðN $C d×&AÑ&AÐ#BÐ˜DÓBÛ8ˆØ×"Ñ" 5Õ)ð 9ð ð
Ø'+°c¸uÈ4ö
÷ð r5   r   c                   óŒ   ‡ — e Zd ZU dZi ej
                  ¥Zeed<   dD ]  Zej                  e«       Œ 	 d
ddddddœˆ fd	„Z
ˆ xZS )r   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ƒ   rL   Tr€   r‡   rˆ   )rk   r„   rM   rN   r…   c          
      ó4   •— t         ‰| �  ||dd||||¬«       y )Nr~   r   r�   rñ   )rŠ   r‚   rk   r„   rM   rN   r…   rá   s          €r3   r‹   zPLSCanonical.__init__  s/   ø€ ô 	‰ÑØ%ØØ&ØØØØØð 	õ 		
r5   râ   ©rä   rå   ræ   rç   rx   r†   rè   ré   rö   r÷   r‹   rê   rë   s   @r3   r   r   ”  s`   ø… ñ`ðD $C d×&AÑ&AÐ#BÐ˜DÓBÛ+ˆØ×"Ñ" 5Õ)ð ,ð ð
ð ØØØØ÷
ò 
r5   r   c                   óŠ   ‡ — e Zd ZU dZi ej
                  ¥Zeed<   dD ]  Zej                  e«       Œ 	 d	dddddœˆ fd„Z
ˆ xZS )
ÚCCAa  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          
      ó4   •— t         ‰| �  ||ddd|||¬«       y )Nr~   r@   r€   r�   rñ   rò   s         €r3   r‹   zCCA.__init__x  s/   ø€ ô 	‰ÑØ%ØØ&ØØØØØð 	õ 		
r5   râ   rú   rë   s   @r3   rü   rü     sX   ø… ñXðt $C d×&AÑ&AÐ#BÐ˜DÓBÛ8ˆØ×"Ñ" 5Õ)ð 9ð ð
Ø'+°c¸uÈ4÷
ò 
r5   rü   c                   ó€   — 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	 e
d	¬«      d„ «       Zdd„Zdd„Zy)r   aº  Partial Least Square SVD.

    This transformer simply performs an 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))
    rA   Nry   rz   r|   ©r‚   rk   r…   r†   T)rk   r…   c                ó.   — || _         || _        || _        y r8   rÿ   )rŠ   r‚   rk   r…   s       r3   r‹   zPLSSVD.__init__Ñ  s   € Ø(ˆÔØˆŒ
Øˆ�	r5   rŒ   c                 ó&  — t        ||«       t        | |t        j                  d| j                  d¬«      }t        |dt        j                  d| j                  d¬«      }|j                  dk(  r|j                  dd«      }| j                  }t        |j                  d	   |j                  d   |j                  d   «      }||kD  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.
        Tr�   r‘   rK   Fr”   rA   r—   r   r˜   r™   rš   r]   N)r   r   r#   rœ   r…   r   r�   rŸ   r‚   r    rG   r¡   rp   rk   r£   r¤   r¥   r¦   r*   rC   r   r   r¨   r©   r·   )
rŠ   rJ   rK   r‚   r»   r^   r_   r-   ra   ÚVs
             r3   rÆ   z
PLSSVD.fitÖ  s“  € ô" 	   1Ô%ÜØØÜ—*‘*Ø Ø—‘Ø ô
ˆô ØØÜ—*‘*Ø Ø—‘Øô
ˆð �6‰6�QŠ;Ø—	‘	˜"˜aÓ ˆAð
 ×(Ñ(ˆÜ˜qŸw™w q™z¨1¯7©7°1©:°q·w±w¸q±zÓBÐØÐ*Ò*ÜØ0Ð1AÐ0Bð CØ#�nÐ$DðFóð ô
 FVØˆq�$—*‘*óF
ÑBˆˆ1ˆdŒl˜DœL¨$¬+°t´{ô
 �F‰F�1—3‘3˜‹NˆÜ�q¨Ô.‰ˆˆ1ˆbØŠa��,�ÐÑˆØ��ÐˆÜ˜˜B“‰ˆˆ2Ø�D‰DˆàˆŒØˆŒØ#Ÿ™×4Ñ4°QÑ7ˆÔØˆr5   c                 óÎ  — t        | «       t        | |t        j                  d¬«      }|| j                  z
  | j
                  z  }t        j                  || j                  «      }|�~t        |ddt        j                  ¬«      }|j                  dk(  r|j                  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É   rK   )r•   r–   r    rA   r—   )r   r   r#   rœ   r£   r¥   r*   r¨   r   r�   rŸ   r¤   r¦   r©   )rŠ   rJ   rK   ÚXrrÁ   ÚyrrÃ   s          r3   rÊ   zPLSSVD.transform  sº   € ô& 	˜ÔÜ˜$ ¬¯©¸5ÔAˆØ�$—,‘,Ñ $§+¡+Ñ-ˆÜ—6‘6˜"˜dŸo™oÓ.ˆØˆ=Ü˜A¨#¸ÄbÇjÁjÔQˆAØ�v‰v˜Š{Ø—I‘I˜b !Ó$�Ø�d—l‘lÑ" d§k¡kÑ1ˆBÜ—v‘v˜b $§/¡/Ó2ˆHØ˜XÐ%Ð%Øˆr5   c                 óF   — | j                  ||«      j                  ||«      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      r3   r×   zPLSSVD.fit_transform7  rØ   r5   râ   r8   )rä   rå   ræ   rç   r   r   r†   rè   ré   r‹   r   rÆ   rÊ   r×   © r5   r3   r   r   ‡  sh   … ñAñH " (¨A¨t¸FÔCÐDØ�Ø�ñ$Ð˜Dó ð°¸4ô ñ
 °Ô5ñ>ó 6ð>ó@ô@.r5   r   )r   r‡   rˆ   Frã   )-rç   rH   Úabcr   r   Únumbersr   r   Únumpyr#   Úscipy.linalgr   r   Úsklearn.baser	   r
   r   r   r   r   Úsklearn.exceptionsr   Úsklearn.utilsr   r   Úsklearn.utils._param_validationr   r   Úsklearn.utils.extmathr   Úsklearn.utils.validationr   r   r   Ú__all__r4   r[   rb   rp   rv   rx   r   r   rü   r   r  r5   r3   Ú<module>r     s¾   ðñó ß 'ß "ã ß "÷÷ õ 2ß >ß @Ý *ß QÑ Qâ
5€ò<ð& =Bó8(òvó.ò4ô]Ø#ØØØØØõ]ô@V�Dô VôrB
�4ô B
ôJk
ˆ$ô k
ô\B.Ð,Ð.>Àõ B.r5   