ó
    ¦ñ:iEA  ã                   óF  • S r SSKrSSKrSSKJr  SSKrSSKJr  SSK	J
r
  SSKJrJr  SSKJrJrJrJr  SS	KJrJr  SS
KJrJrJr  SSKJrJr  / SQr\" S/S/S.SS9S 5       r\" S/SS/\" \SSSS9S/\" \SSSS9S/S/S.SS9SSSSS.S j5       r " S S\\\5      r g)z8Isotonic regression for obtaining monotonic fit to data.é    N)ÚReal)Úinterpolate)Ú	spearmanré   )Ú'_inplace_contiguous_isotonic_regressionÚ_make_unique)ÚBaseEstimatorÚRegressorMixinÚTransformerMixinÚ_fit_context)Úcheck_arrayÚcheck_consistent_length)ÚIntervalÚ
StrOptionsÚvalidate_params)Ú_check_sample_weightÚcheck_is_fitted)Úcheck_increasingÚisotonic_regressionÚIsotonicRegressionz
array-like©ÚxÚyT©Úprefer_skip_nested_validationc                 óÚ  • [        X5      u  p#US:¬  nUS;  aÒ  [        U 5      S:”  aÃ  S[        R                  " SU-   SU-
  -  5      -  nS[        R                  " [        U 5      S-
  5      -  n[        R
                  " USU-  -
  5      n[        R
                  " USU-  -   5      n[        R                  " U5      [        R                  " U5      :w  a  [        R                  " S5        U$ )	a¿  Determine whether y is monotonically correlated with x.

y is found increasing or decreasing with respect to x based on a Spearman
correlation test.

Parameters
----------
x : array-like of shape (n_samples,)
        Training data.

y : array-like of shape (n_samples,)
    Training target.

Returns
-------
increasing_bool : boolean
    Whether the relationship is increasing or decreasing.

Notes
-----
The Spearman correlation coefficient is estimated from the data, and the
sign of the resulting estimate is used as the result.

In the event that the 95% confidence interval based on Fisher transform
spans zero, a warning is raised.

References
----------
Fisher transformation. Wikipedia.
https://en.wikipedia.org/wiki/Fisher_transformation

Examples
--------
>>> from sklearn.isotonic import check_increasing
>>> x, y = [1, 2, 3, 4, 5], [2, 4, 6, 8, 10]
>>> check_increasing(x, y)
np.True_
>>> y = [10, 8, 6, 4, 2]
>>> check_increasing(x, y)
np.False_
r   )g      ð¿ç      ð?é   g      à?r   r   g\�Âõ(\ÿ?zwConfidence interval of the Spearman correlation coefficient spans zero. Determination of ``increasing`` may be suspect.)
r   ÚlenÚmathÚlogÚsqrtÚtanhÚnpÚsignÚwarningsÚwarn)	r   r   ÚrhoÚ_Úincreasing_boolÚFÚF_seÚrho_0Úrho_1s	            ÚS/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/sklearn/isotonic.pyr   r      sÉ   € ôf �q‹_�F€CØ˜Q‘h€Oð �+Ó¤# a£&¨1£*Ø”$—(’(˜C #™I¨#°©)Ñ4Ó5Ñ5ˆØ”4—9’9œS ›V a™ZÓ(Ñ(ˆô —	’	˜!˜d T™k™/Ó*ˆÜ—	’	˜!˜d T™k™/Ó*ˆô �7Š7�5‹>œRŸWšW U›^Ó+Ü�MŠMðôð Ðó    Úboth©ÚclosedÚboolean)r   Úsample_weightÚy_minÚy_maxÚ
increasing©r5   r6   r7   r8   c                óø  • U(       a  [         R                  SS O[         R                  SSS2   n[        U SS[         R                  [         R                  /S9n [         R
                  " X   U R                  S9n [        XU R                  SS9n[         R                  " X   5      n[        X5        Uc  Ub>  Uc  [         R                  * nUc  [         R                  n[         R                  " XX05        X   $ )	a°  Solve the isotonic regression model.

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

Parameters
----------
y : array-like of shape (n_samples,)
    The data.

sample_weight : array-like of shape (n_samples,), default=None
    Weights on each point of the regression.
    If None, weight is set to 1 (equal weights).

y_min : float, default=None
    Lower bound on the lowest predicted value (the minimum value may
    still be higher). If not set, defaults to -inf.

y_max : float, default=None
    Upper bound on the highest predicted value (the maximum may still be
    lower). If not set, defaults to +inf.

increasing : bool, default=True
    Whether to compute ``y_`` is increasing (if set to True) or decreasing
    (if set to False).

Returns
-------
y_ : ndarray of shape (n_samples,)
    Isotonic fit of y.

References
----------
"Active set algorithms for isotonic regression; A unifying framework"
by Michael J. Best and Nilotpal Chakravarti, section 3.

Examples
--------
>>> from sklearn.isotonic import isotonic_regression
>>> isotonic_regression([5, 3, 1, 2, 8, 10, 7, 9, 6, 4])
array([2.75   , 2.75   , 2.75   , 2.75   , 7.33...,
       7.33..., 7.33..., 7.33..., 7.33..., 7.33...])
NéÿÿÿÿFr   )Ú	ensure_2dÚ
input_nameÚdtype©r>   T)r>   Úcopy)r$   Ús_r   Úfloat64Úfloat32Úarrayr>   r   Úascontiguousarrayr   ÚinfÚclip)r   r5   r6   r7   r8   Úorders         r/   r   r   e   sÀ   € ön #ŒB�E‰E‘!‰H¬¯©©d°¨d©€EÜ�A °3¼r¿z¹zÌ2Ï:É:Ð>VÑW€AÜ
�Š�‘ §¡Ñ)€AÜ(¨ÀÇÁÈtÑT€MÜ×(Ò(¨Ñ)=Ó>€Mä+¨AÔ=ØÑ˜EÑ-à‰=Ü—V‘V�GˆEØ‰=Ü—F‘FˆEÜ
�Š�˜%Ô#Ø‰8€Or0   c                   ó  ^ • \ rS rSr% Sr\" \SSSS9S/\" \SSSS9S/S\" S15      /\" 1 Sk5      /S	.r\	\
S
'   SSSSS	.S jrS rS rSS jr\" SS9SS j5       rS rS rS rSS jrU 4S jrU 4S jrS rSrU =r$ )r   é­   a³
  Isotonic regression model.

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

.. versionadded:: 0.13

Parameters
----------
y_min : float, default=None
    Lower bound on the lowest predicted value (the minimum value may
    still be higher). If not set, defaults to -inf.

y_max : float, default=None
    Upper bound on the highest predicted value (the maximum may still be
    lower). If not set, defaults to +inf.

increasing : bool or 'auto', default=True
    Determines whether the predictions should be constrained to increase
    or decrease with `X`. 'auto' will decide based on the Spearman
    correlation estimate's sign.

out_of_bounds : {'nan', 'clip', 'raise'}, default='nan'
    Handles how `X` values outside of the training domain are handled
    during prediction.

    - 'nan', predictions will be NaN.
    - 'clip', predictions will be set to the value corresponding to
      the nearest train interval endpoint.
    - 'raise', a `ValueError` is raised.

Attributes
----------
X_min_ : float
    Minimum value of input array `X_` for left bound.

X_max_ : float
    Maximum value of input array `X_` for right bound.

X_thresholds_ : ndarray of shape (n_thresholds,)
    Unique ascending `X` values used to interpolate
    the y = f(X) monotonic function.

    .. versionadded:: 0.24

y_thresholds_ : ndarray of shape (n_thresholds,)
    De-duplicated `y` values suitable to interpolate the y = f(X)
    monotonic function.

    .. versionadded:: 0.24

f_ : function
    The stepwise interpolating function that covers the input domain ``X``.

increasing_ : bool
    Inferred value for ``increasing``.

See Also
--------
sklearn.linear_model.LinearRegression : Ordinary least squares Linear
    Regression.
sklearn.ensemble.HistGradientBoostingRegressor : Gradient boosting that
    is a non-parametric model accepting monotonicity constraints.
isotonic_regression : Function to solve the isotonic regression model.

Notes
-----
Ties are broken using the secondary method from de Leeuw, 1977.

References
----------
Isotonic Median Regression: A Linear Programming Approach
Nilotpal Chakravarti
Mathematics of Operations Research
Vol. 14, No. 2 (May, 1989), pp. 303-308

Isotone Optimization in R : Pool-Adjacent-Violators
Algorithm (PAVA) and Active Set Methods
de Leeuw, Hornik, Mair
Journal of Statistical Software 2009

Correctness of Kruskal's algorithms for monotone regression with ties
de Leeuw, Psychometrica, 1977

Examples
--------
>>> from sklearn.datasets import make_regression
>>> from sklearn.isotonic import IsotonicRegression
>>> X, y = make_regression(n_samples=10, n_features=1, random_state=41)
>>> iso_reg = IsotonicRegression().fit(X, y)
>>> iso_reg.predict([.1, .2])
array([1.8628..., 3.7256...])
Nr1   r2   r4   Úauto>   ÚnanrG   Úraise©r6   r7   r8   Úout_of_boundsÚ_parameter_constraintsTrL   c                ó4   • Xl         X l        X0l        X@l        g ©NrN   )Úselfr6   r7   r8   rO   s        r/   Ú__init__ÚIsotonicRegression.__init__  s   € ØŒ
ØŒ
Ø$ŒØ*Õr0   c                 ó†   • UR                   S:X  d1  UR                   S:X  a  UR                  S   S:X  d  Sn[        U5      eg g )Nr   é   zKIsotonic regression input X should be a 1d array or 2d array with 1 feature)ÚndimÚshapeÚ
ValueError)rS   ÚXÚmsgs      r/   Ú_check_input_data_shapeÚ*IsotonicRegression._check_input_data_shape  sC   € Ø—‘˜!“ §¡¨!£°·±¸±
¸a³ð*ð ô ˜S“/Ð!ð 1@�r0   c                 ó’   ^• U R                   S:H  n[        T5      S:X  a  U4S jU l        g[        R                  " UTSUS9U l        g)zBuild the f_ interp1d function.rM   r   c                 ó:   >• TR                  U R                  5      $ rR   )ÚrepeatrY   r   s    €r/   Ú<lambda>Ú-IsotonicRegression._build_f.<locals>.<lambda>&  s   ø€  §¡¨¯©Ô 1r0   Úlinear)ÚkindÚbounds_errorN)rO   r   Úf_r   Úinterp1d)rS   r[   r   rf   s     ` r/   Ú_build_fÚIsotonicRegression._build_f   sB   ø€ ð ×)Ñ)¨WÑ4ˆÜˆq‹6�Q‹;ä1ˆD�Gä!×*Ò*Ø�1˜8°,ñˆD�Gr0   c           	      óN  • U R                  U5        UR                  S5      nU R                  S:X  a  [        X5      U l        OU R                  U l        [        X1UR                  S9nUS:„  nX   X%   X5   p2n[        R                  " X!45      nXU4 Vs/ s H  owU   PM	     snu  pn[        XU5      u  p‰n
Un[        U	U
U R                  U R                  U R                  S9n[        R                  " U5      [        R                  " U5      sU l        U l        U(       a{  [        R"                  " [%        U5      4[&        S9n[        R(                  " [        R*                  " USS USS 5      [        R*                  " USS US	S 5      5      USS& X   X+   4$ X4$ s  snf )
z Build the y_ IsotonicRegression.r;   rK   r?   r   r9   r   NéþÿÿÿrW   )r]   Úreshaper8   r   Úincreasing_r   r>   r$   Úlexsortr   r   r6   r7   ÚminÚmaxÚX_min_ÚX_max_Úonesr   ÚboolÚ
logical_orÚ	not_equal)rS   r[   r   r5   Útrim_duplicatesÚmaskrH   rD   Úunique_XÚunique_yÚunique_sample_weightÚ	keep_datas               r/   Ú_build_yÚIsotonicRegression._build_y,  s†  € à×$Ñ$ QÔ'Ø�I‰I�b‹Mˆð �?‰?˜fÓ$Ü/°Ó5ˆDÕà#Ÿ™ˆDÔô -¨]ÀQÇWÁWÑMˆØ˜qÑ ˆØ™g q¡w°Ñ0Cˆmˆä—
’
˜A˜6Ó"ˆØ:;ÀÑ9NÓOÒ9N° Uœ|Ñ9NÑOÑˆˆmÜ3?ÀÀmÓ3TÑ0ˆÐ0àˆÜØØ.Ø—*‘*Ø—*‘*Ø×'Ñ'ñ
ˆô $&§6¢6¨!£9¬b¯fªf°Q«iÐ ˆŒ�T”[æäŸš¤ Q£ 	´Ñ6ˆIô !ŸmšmÜ—’˜Q˜q ˜W a¨¨ fÓ-¬r¯|ª|¸A¸aÀ¸GÀQÀqÀrÀUÓ/KóˆI�a˜ˆOð ‘< ¡Ð-Ð-ð �4ˆKùò; Ps   ÂF"r   c                 ó$  • [        SSS9n[        U4S[        R                  [        R                  /S.UD6n[        U4SUR
                  S.UD6n[        XU5        U R                  XU5      u  pXsU l        U l	        U R                  X5        U $ )aF  Fit the model using X, y as training data.

Parameters
----------
X : array-like of shape (n_samples,) or (n_samples, 1)
    Training data.

    .. versionchanged:: 0.24
       Also accepts 2d array with 1 feature.

y : array-like of shape (n_samples,)
    Training target.

sample_weight : array-like of shape (n_samples,), default=None
    Weights. If set to None, all weights will be set to 1 (equal
    weights).

Returns
-------
self : object
    Returns an instance of self.

Notes
-----
X is stored for future use, as :meth:`transform` needs X to interpolate
new input data.
F)Úaccept_sparser<   r[   )r=   r>   r   )Údictr   r$   rB   rC   r>   r   r~   ÚX_thresholds_Úy_thresholds_ri   )rS   r[   r   r5   Úcheck_paramss        r/   ÚfitÚIsotonicRegression.fit]  s›   € ô: ¨%¸5ÑAˆÜØð
Ø¤b§j¡j´"·*±*Ð%=ñ
ØAMñ
ˆô ˜ÐI c°·±ÑI¸LÑIˆÜ  mÔ4ð �}‰}˜Q =Ó1‰ˆð 23Ð.ˆÔ˜DÔ.ð 	�‰�aÔØˆr0   c                 óœ  • [        U S5      (       a  U R                  R                  nO[        R                  n[        XSS9nU R                  U5        UR                  S5      nU R                  S:X  a+  [        R                  " XR                  U R                  5      nU R                  U5      nUR                  UR                  5      nU$ )aW  `_transform` is called by both `transform` and `predict` methods.

Since `transform` is wrapped to output arrays of specific types (e.g.
NumPy arrays, pandas DataFrame), we cannot make `predict` call `transform`
directly.

The above behaviour could be changed in the future, if we decide to output
other type of arrays when calling `predict`.
rƒ   F)r>   r<   r;   rG   )Úhasattrrƒ   r>   r$   rB   r   r]   rm   rO   rG   rr   rs   rg   Úastype)rS   ÚTr>   Úress       r/   Ú
_transformÚIsotonicRegression._transform�  sž   € ô �4˜×)Ñ)Ø×&Ñ&×,Ñ,‰Eä—J‘JˆEä˜°%Ñ8ˆà×$Ñ$ QÔ'Ø�I‰I�b‹Mˆà×Ñ Ó'Ü—’˜Ÿ;™;¨¯©Ó4ˆAà�g‰g�a‹jˆð �j‰j˜Ÿ™Ó!ˆàˆ
r0   c                 ó$   • U R                  U5      $ )a.  Transform new data by linear interpolation.

Parameters
----------
T : array-like of shape (n_samples,) or (n_samples, 1)
    Data to transform.

    .. versionchanged:: 0.24
       Also accepts 2d array with 1 feature.

Returns
-------
y_pred : ndarray of shape (n_samples,)
    The transformed data.
©r�   ©rS   r‹   s     r/   Ú	transformÚIsotonicRegression.transform­  s   € ð  �‰˜qÓ!Ð!r0   c                 ó$   • U R                  U5      $ )zÝPredict new data by linear interpolation.

Parameters
----------
T : array-like of shape (n_samples,) or (n_samples, 1)
    Data to transform.

Returns
-------
y_pred : ndarray of shape (n_samples,)
    Transformed data.
r�   r‘   s     r/   ÚpredictÚIsotonicRegression.predict¿  s   € ð �‰˜qÓ!Ð!r0   c                 óœ   • [        U S5        U R                  R                  R                  5       n[        R
                  " U S3/[        S9$ )a  Get output feature names for transformation.

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

Returns
-------
feature_names_out : ndarray of str objects
    An ndarray with one string i.e. ["isotonicregression0"].
rg   Ú0r?   )r   Ú	__class__Ú__name__Úlowerr$   ÚasarrayÚobject)rS   Úinput_featuresÚ
class_names      r/   Úget_feature_names_outÚ(IsotonicRegression.get_feature_names_outÒ  sA   € ô 	˜˜dÔ#Ø—^‘^×,Ñ,×2Ñ2Ó4ˆ
Ü�zŠz˜j˜\¨Ð+Ð,´FÑ;Ð;r0   c                 óH   >• [         TU ]  5       nUR                  SS5        U$ )z0Pickle-protocol - return state of the estimator.rg   N)ÚsuperÚ__getstate__Úpop©rS   Ústater™   s     €r/   r¤   ÚIsotonicRegression.__getstate__ã  s#   ø€ ä‘Ñ$Ó&ˆà�	‰	�$˜ÔØˆr0   c                 ó¸   >• [         TU ]  U5        [        U S5      (       a9  [        U S5      (       a'  U R                  U R                  U R
                  5        ggg)z^Pickle-protocol - set state of the estimator.

We need to rebuild the interpolation function.
rƒ   r„   N)r£   Ú__setstate__r‰   ri   rƒ   r„   r¦   s     €r/   rª   ÚIsotonicRegression.__setstate__ê  sN   ø€ ô
 	‰Ñ˜UÔ#Ü�4˜×)Ñ)¬g°d¸O×.LÑ.LØ�M‰M˜$×,Ñ,¨d×.@Ñ.@ÕAð /MÐ)r0   c                 ó   • SS/0$ )NÚX_typesÚ1darray© )rS   s    r/   Ú
_more_tagsÚIsotonicRegression._more_tagsó  s   € Ø˜I˜;Ð'Ð'r0   )
rs   rr   rƒ   rg   r8   rn   rO   r7   r6   r„   )TrR   )rš   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   rP   r‚   Ú__annotations__rT   r]   ri   r~   r   r†   r�   r’   r•   r    r¤   rª   r°   Ú__static_attributes__Ú__classcell__)r™   s   @r/   r   r   ­   sÀ   ø‡ ñ[ñ| ˜4  t°FÑ;¸TÐBÙ˜4  t°FÑ;¸TÐBØ ¡*¨f¨XÓ"6Ð7Ù$Ò%=Ó>Ð?ñ	$Ð˜Dó ð !%¨D¸TÐQVõ +ò"ò
ô/ñb °Ñ5ó/ó 6ð/òbò<"ò$"ô&<õ"õB÷(ð (r0   r   )!rµ   r    r&   Únumbersr   Únumpyr$   Úscipyr   Úscipy.statsr   Ú	_isotonicr   r   Úbaser	   r
   r   r   Úutilsr   r   Úutils._param_validationr   r   r   Úutils.validationr   r   Ú__all__r   r   r   r¯   r0   r/   Ú<module>rÃ      sà   ðÙ >ó Û Ý ã Ý Ý !ç Lß OÓ Oß 7ß JÑ Jß Câ
K€ñ àˆ^Øˆ^ñð #'ññBóðBñJ àˆ^Ø&¨Ð-Ù˜4  t°FÑ;¸TÐBÙ˜4  t°FÑ;¸TÐBØ �kñð #'ñ	ð  D°Àô;ó	ð;ô|G(˜Ð)9¸=õ G(r0   