
    -i_                         S r SSKrSSKJrJr  SSKrSSKJr	  SSK
JrJrJrJrJr  SSKJr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJrJrJrJrJ r J!r!   " S S\\\5      r" " S S\\\5      r#g)z6Dummy estimators that implement simple rules of thumb.    N)IntegralReal   )BaseEstimatorClassifierMixinMultiOutputMixinRegressorMixin_fit_context)check_random_state)Interval
StrOptions)class_distribution)_random_choice_csc)_weighted_percentile)_check_sample_weight_num_samplescheck_arraycheck_consistent_lengthcheck_is_fittedvalidate_datac                      ^  \ rS rSr% Sr\" 1 Sk5      /S/\\SS/S.r\	\
S'   S	SSS.S
 jr\" SS9SS j5       rS rS rS rU 4S jrSU 4S jjrSrU =r$ )DummyClassifier"   a  DummyClassifier makes predictions that ignore the input features.

This classifier serves as a simple baseline to compare against other more
complex classifiers.

The specific behavior of the baseline is selected with the `strategy`
parameter.

All strategies make predictions that ignore the input feature values passed
as the `X` argument to `fit` and `predict`. The predictions, however,
typically depend on values observed in the `y` parameter passed to `fit`.

Note that the "stratified" and "uniform" strategies lead to
non-deterministic predictions that can be rendered deterministic by setting
the `random_state` parameter if needed. The other strategies are naturally
deterministic and, once fit, always return the same constant prediction
for any value of `X`.

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

.. versionadded:: 0.13

Parameters
----------
strategy : {"most_frequent", "prior", "stratified", "uniform",             "constant"}, default="prior"
    Strategy to use to generate predictions.

    * "most_frequent": the `predict` method always returns the most
      frequent class label in the observed `y` argument passed to `fit`.
      The `predict_proba` method returns the matching one-hot encoded
      vector.
    * "prior": the `predict` method always returns the most frequent
      class label in the observed `y` argument passed to `fit` (like
      "most_frequent"). ``predict_proba`` always returns the empirical
      class distribution of `y` also known as the empirical class prior
      distribution.
    * "stratified": the `predict_proba` method randomly samples one-hot
      vectors from a multinomial distribution parametrized by the empirical
      class prior probabilities.
      The `predict` method returns the class label which got probability
      one in the one-hot vector of `predict_proba`.
      Each sampled row of both methods is therefore independent and
      identically distributed.
    * "uniform": generates predictions uniformly at random from the list
      of unique classes observed in `y`, i.e. each class has equal
      probability.
    * "constant": always predicts a constant label that is provided by
      the user. This is useful for metrics that evaluate a non-majority
      class.

      .. versionchanged:: 0.24
         The default value of `strategy` has changed to "prior" in version
         0.24.

random_state : int, RandomState instance or None, default=None
    Controls the randomness to generate the predictions when
    ``strategy='stratified'`` or ``strategy='uniform'``.
    Pass an int for reproducible output across multiple function calls.
    See :term:`Glossary <random_state>`.

constant : int or str or array-like of shape (n_outputs,), default=None
    The explicit constant as predicted by the "constant" strategy. This
    parameter is useful only for the "constant" strategy.

Attributes
----------
classes_ : ndarray of shape (n_classes,) or list of such arrays
    Unique class labels observed in `y`. For multi-output classification
    problems, this attribute is a list of arrays as each output has an
    independent set of possible classes.

n_classes_ : int or list of int
    Number of label for each output.

class_prior_ : ndarray of shape (n_classes,) or list of such arrays
    Frequency of each class observed in `y`. For multioutput classification
    problems, this is computed independently for each output.

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.

n_outputs_ : int
    Number of outputs.

sparse_output_ : bool
    True if the array returned from predict is to be in sparse CSC format.
    Is automatically set to True if the input `y` is passed in sparse
    format.

See Also
--------
DummyRegressor : Regressor that makes predictions using simple rules.

Examples
--------
>>> import numpy as np
>>> from sklearn.dummy import DummyClassifier
>>> X = np.array([-1, 1, 1, 1])
>>> y = np.array([0, 1, 1, 1])
>>> dummy_clf = DummyClassifier(strategy="most_frequent")
>>> dummy_clf.fit(X, y)
DummyClassifier(strategy='most_frequent')
>>> dummy_clf.predict(X)
array([1, 1, 1, 1])
>>> dummy_clf.score(X, y)
0.75
>   prioruniformconstant
stratifiedmost_frequentrandom_state
array-likeNstrategyr   r   _parameter_constraintsr   c                (    Xl         X l        X0l        g Nr!   )selfr"   r   r   s       @/var/www/html/venv/lib/python3.13/site-packages/sklearn/dummy.py__init__DummyClassifier.__init__   s     (     Tprefer_skip_nested_validationc                 h  ^^ [        XSS9  U R                  U l        U R                  S:X  aF  [        R                  " U5      (       a+  UR                  5       n[        R                  " S[        5        [        R                  " U5      U l	        U R                  (       d,  [        R                  " U5      n[        R                  " U5      nUR                  S:X  a  [        R                  " US5      nUR                  S   U l        [#        X5        Ub  [%        X15      nU R                  S:X  a  U R&                  c  [)        S5      e[        R                  " [        R                  " U R&                  5      S5      mTR                  S	   U R                   :w  a  [)        S
U R                   -  5      e[+        X#5      u  U l        U l        U l        U R                  S:X  a  [3        U R                   5       Hm  m[5        UU4S jU R,                  T    5       5      (       a  M-  SR7                  U R&                  U R,                  T   R9                  5       5      n[)        U5      e   U R                   S:X  a<  U R.                  S	   U l        U R,                  S	   U l        U R0                  S	   U l        U $ )a^  Fit the baseline classifier.

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

y : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Target values.

sample_weight : array-like of shape (n_samples,), default=None
    Sample weights.

Returns
-------
self : object
    Returns the instance itself.
Tskip_check_arrayr   zA local copy of the target data has been converted to a numpy array. Predicting on sparse target data with the uniform strategy would not save memory and would be slower.r   r   r   MConstant target value has to be specified when the constant strategy is used.r   0Constant target value should have shape (%d, 1).c              3   :   >#    U  H  nTT   S    U:H  v   M     g7f)r   N ).0cr   ks     r'   	<genexpr>&DummyClassifier.fit.<locals>.<genexpr>   s      I8H18A;q>Q.8Hs   zrThe constant target value must be present in the training data. You provided constant={}. Possible values are: {}.)r   r"   	_strategyspissparsetoarraywarningswarnUserWarningsparse_output_npasarray
atleast_1dndimreshapeshape
n_outputs_r   r   r   
ValueErrorr   classes_
n_classes_class_prior_rangeanyformattolist)r&   Xysample_weighterr_msgr   r8   s        @@r'   fitDummyClassifier.fit   s   ( 	d5>>Y&2;;q>>		AMM+
  !kk!n""

1Aa A66Q;

1g&A''!*%$0BM>>Z'}}$ : 
 ::bmmDMM&BGL>>!$7$J//* 
 ?Q?
;): >>Z'4??+Ia8HIII3396 MM4==+;+B+B+D4  %W-- , ??a"ooa0DO MM!,DM $ 1 1! 4Dr*   c           
      ^   [        U 5        [        U5      n[        U R                  5      nU R                  nU R
                  nU R                  nU R                  nU R                  S:X  a  U/nU/nU/nU/nU R                  S:X  a$  U R                  U5      nU R                  S:X  a  U/nU R                  (       a  Sn	U R                  S;   a6  U V
s/ s H(  n
[        R                  " U
R                  5       /5      PM*     nn
OeU R                  S:X  a  Un	ORU R                  S:X  a  [        S5      eU R                  S:X  a'  U Vs/ s H  n[        R                  " U/5      PM     nn[!        X%XR                  5      nU$ U R                  S;   aT  [        R"                  " [%        U R                  5       Vs/ s H  nX]   Xm   R                  5          PM     snUS/5      nGOU R                  S:X  aZ  [        R&                  " [%        U R                  5       Vs/ s H  nX]   WU   R                  SS9   PM     sn5      R(                  nOU R                  S:X  a[  [%        U R                  5       Vs/ s H  nX]   UR+                  XM   US	9   PM     nn[        R&                  " U5      R(                  nO3U R                  S:X  a#  [        R"                  " U R                  US45      nU R                  S:X  a  [        R,                  " W5      nW$ s  sn
f s  snf s  snf s  snf s  snf )
zPerform classification on test vectors X.

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

Returns
-------
y : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Predicted target values for X.
r   r   N)r   r   r   zCSparse target prediction is not supported with the uniform strategyr   axissize)r   r   r   r   rL   rK   rM   r   rI   r;   predict_probarB   rC   arrayargmaxrJ   r   tilerN   vstackTrandintravel)r&   rR   	n_samplesrsrL   rK   rM   r   proba
class_probcpr7   rS   r8   rets                  r'   predictDummyClassifier.predict   s    	 !O	 1 12__
==((==??a$J zH(>L zH>>\)&&q)E!#J~~!;;>JKlBHHbiik]3lK</)
9, : 
 :-3;<8aBHHaSM8<"9
DUDUVA@ = ~~!;;GG "'t!7!7A !LO$:$:$<=!7 N </II "'t!7!7A !E!HOOO$;<!7
 !  9, #4??33 K

:=y
 IJ3   IIcN$$:-GGDMMIq>:!#HHQK] L =s   /L!L9!L !L%7!L*c                 B   [        U 5        [        U5      n[        U R                  5      nU R                  nU R
                  nU R                  nU R                  nU R                  S:X  a  U/nU/nU/nU/n/ n[        U R                  5       GHv  n	U R                  S:X  aD  Xi   R                  5       n
[        R                  " X$U	   4[        R                  S9nSUSS2U
4'   GOU R                  S:X  a  [        R                  " US45      Xi   -  nOU R                  S:X  a3  UR!                  SXi   US9nUR#                  [        R                  5      nOU R                  S	:X  a/  [        R                  " X$U	   4[        R                  S9nXU	   -  nO]U R                  S
:X  aM  [        R$                  " XY   Xy   :H  5      n
[        R                  " X$U	   4[        R                  S9nSUSS2U
4'   UR'                  W5        GMy     U R                  S:X  a  US   nU$ )aj  
Return probability estimates for the test vectors X.

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

Returns
-------
P : ndarray of shape (n_samples, n_classes) or list of such arrays
    Returns the probability of the sample for each class in
    the model, where classes are ordered arithmetically, for each
    output.
r   r   dtype      ?Nr   r   r[   r   r   r   )r   r   r   r   rL   rK   rM   r   rI   rN   r;   r_   rC   zerosfloat64onesmultinomialastypewhereappend)r&   rR   re   rf   rL   rK   rM   r   Pr8   indouts               r'   r]   DummyClassifier.predict_probaS  s     	 !O	 1 12__
==((==??a$J zH(>L zHt'A~~0"o,,.hh	a=9L!AsF7*ggy!n-?</nnQinHjj,9,ggyQ-8

K!}$:-hhx{hk9:hh	a=9L!AsFHHSM+ (. ??a!Ar*   c                     U R                  U5      nU R                  S:X  a  [        R                  " U5      $ U Vs/ s H  n[        R                  " U5      PM     sn$ s  snf )az  
Return log probability estimates for the test vectors X.

Parameters
----------
X : {array-like, object with finite length or shape}
    Training data.

Returns
-------
P : ndarray of shape (n_samples, n_classes) or list of such arrays
    Returns the log probability of the sample for each class in
    the model, where classes are ordered arithmetically for each
    output.
r   )r]   rI   rC   log)r&   rR   rg   ps       r'   predict_log_proba!DummyClassifier.predict_log_proba  sN      ""1%??a66%= ',-u!BFF1Iu---s    Ac                 v   > [         TU ]  5       nSUR                  l        SUR                  l        SUl        U$ NT)super__sklearn_tags__
input_tagssparseclassifier_tags
poor_scoreno_validationr&   tags	__class__s     r'   r    DummyClassifier.__sklearn_tags__  s7    w')!%*.'!r*   c                 h   > Uc  [         R                  " [        U5      S4S9n[        TU ]  XU5      $ )a  Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy
which is a harsh metric since you require for each sample that
each label set be correctly predicted.

Parameters
----------
X : None or array-like of shape (n_samples, n_features)
    Test samples. Passing None as test samples gives the same result
    as passing real test samples, since DummyClassifier
    operates independently of the sampled observations.

y : array-like of shape (n_samples,) or (n_samples, n_outputs)
    True labels for X.

sample_weight : array-like of shape (n_samples,), default=None
    Sample weights.

Returns
-------
score : float
    Mean accuracy of self.predict(X) w.r.t. y.
r   rH   rC   rq   lenr   scorer&   rR   rS   rT   r   s       r'   r   DummyClassifier.score  s1    2 9A{+Aw}Q=11r*   )	r;   rM   rK   r   rL   rI   r   rB   r"   r%   )__name__
__module____qualname____firstlineno____doc__r   r   strr#   dict__annotations__r(   r
   rV   rk   r]   r   r   r   __static_attributes____classcell__r   s   @r'   r   r   "   s    of VW
 ((sL$7$D  $+ !
 5X 6XtUn=~.,2 2r*   r   c            	          ^  \ rS rSr% Sr\" 1 Sk5      /\" \SSSS9S/\" \SSS	S9S
S/S.r\	\
S'   SSSS.S jr\" SS9SS j5       rSS jrU 4S jrSU 4S jjrSrU =r$ )DummyRegressori  a  Regressor that makes predictions using simple rules.

This regressor is useful as a simple baseline to compare with other
(real) regressors. Do not use it for real problems.

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

.. versionadded:: 0.13

Parameters
----------
strategy : {"mean", "median", "quantile", "constant"}, default="mean"
    Strategy to use to generate predictions.

    * "mean": always predicts the mean of the training set
    * "median": always predicts the median of the training set
    * "quantile": always predicts a specified quantile of the training set,
      provided with the quantile parameter.
    * "constant": always predicts a constant value that is provided by
      the user.

constant : int or float or array-like of shape (n_outputs,), default=None
    The explicit constant as predicted by the "constant" strategy. This
    parameter is useful only for the "constant" strategy.

quantile : float in [0.0, 1.0], default=None
    The quantile to predict using the "quantile" strategy. A quantile of
    0.5 corresponds to the median, while 0.0 to the minimum and 1.0 to the
    maximum.

Attributes
----------
constant_ : ndarray of shape (1, n_outputs)
    Mean or median or quantile of the training targets or constant value
    given by the user.

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.

n_outputs_ : int
    Number of outputs.

See Also
--------
DummyClassifier: Classifier that makes predictions using simple rules.

Examples
--------
>>> import numpy as np
>>> from sklearn.dummy import DummyRegressor
>>> X = np.array([1.0, 2.0, 3.0, 4.0])
>>> y = np.array([2.0, 3.0, 5.0, 10.0])
>>> dummy_regr = DummyRegressor(strategy="mean")
>>> dummy_regr.fit(X, y)
DummyRegressor()
>>> dummy_regr.predict(X)
array([5., 5., 5., 5.])
>>> dummy_regr.score(X, y)
0.0
>   meanmedianr   quantileg        rp   both)closedNneitherr    )r"   r   r   r#   r   r"   r   r   c                (    Xl         X l        X0l        g r%   r   )r&   r"   r   r   s       r'   r(   DummyRegressor.__init__  s       r*   Tr+   c           	         [        XSS9  [        USSS9n[        U5      S:X  a  [        S5      eUR                  S:X  a  [
        R                  " US	5      nUR                  S   U l        [        XU5        Ub  [        X15      nU R                  S:X  a  [
        R                  " USUS9U l        GOU R                  S:X  a\  Uc  [
        R                  " USS9U l        GOh[        U R                  5       Vs/ s H  n[!        US
S
2U4   USS9PM     snU l        GO+U R                  S:X  a  U R"                  c  [        S5      eU R"                  S-  nUc  [
        R$                  " USUS9U l        O[        U R                  5       Vs/ s H  n[!        US
S
2U4   X5S9PM     snU l        OU R                  S:X  a  U R&                  c  [)        S5      e[        U R&                  / SQSSS9U l        U R                  S:w  aE  U R                  R                  S   UR                  S   :w  a  [        SUR                  S   -  5      e[
        R                  " U R                  S5      U l        U $ s  snf s  snf )aR  Fit the baseline regressor.

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

y : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Target values.

sample_weight : array-like of shape (n_samples,), default=None
    Sample weights.

Returns
-------
self : object
    Fitted estimator.
Tr.   FrS   )	ensure_2d
input_namer   zy must not be empty.r   r0   Nr   )rZ   weightsr   rY   g      I@)percentile_rankr   z^When using `strategy='quantile', you have to specify the desired quantile in the range [0, 1].g      Y@)rZ   qr   r2   )csrcsccoo)accept_sparser   ensure_min_samplesr3   )r   r1   )r   r   r   rJ   rF   rC   rG   rH   rI   r   r   r"   average	constant_r   rN   r   r   
percentiler   	TypeError)r&   rR   rS   rT   r8   r   s         r'   rV   DummyRegressor.fit  sE   ( 	d5Us;q6Q;34466Q;

1g&A''!*m4$0BM==F"ZZ=IDN]]h&$!#11!5 #4??3"3 )1a4-QUV3"
 ]]j(}}$ 4  #mme3O$!#qqO!L #4??3	" 4 )!Q$ 4	" ]]j(}}$: 
 )3#$	DN !#(<(<Q(?1771:(M FQRS  DNNG<U""s   8I1I6c                    [        U 5        [        U5      n[        R                  " X0R                  4U R
                  [        R                  " U R
                  5      R                  S9n[        R                  " X0R                  45      nU R                  S:X  a,  [        R                  " U5      n[        R                  " U5      nU(       a  XE4$ U$ )a  Perform classification on test vectors X.

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

return_std : bool, default=False
    Whether to return the standard deviation of posterior prediction.
    All zeros in this case.

    .. versionadded:: 0.20

Returns
-------
y : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Predicted target values for X.

y_std : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Standard deviation of predictive distribution of query points.
rn   r   )
r   r   rC   fullrI   r   r^   ro   rq   rd   )r&   rR   
return_stdre   rS   y_stds         r'   rk   DummyRegressor.predictt  s    , 	 O	GG(NN((4>>*00

 )__56??aAHHUOE'z.Q.r*   c                 v   > [         TU ]  5       nSUR                  l        SUR                  l        SUl        U$ r   )r   r   r   r   regressor_tagsr   r   r   s     r'   r   DummyRegressor.__sklearn_tags__  s7    w')!%)-&!r*   c                 h   > Uc  [         R                  " [        U5      S4S9n[        TU ]  XU5      $ )a  Return the coefficient of determination R^2 of the prediction.

The coefficient R^2 is defined as `(1 - u/v)`, where `u` is the
residual sum of squares `((y_true - y_pred) ** 2).sum()` and `v` is the
total sum of squares `((y_true - y_true.mean()) ** 2).sum()`. The best
possible score is 1.0 and it can be negative (because the model can be
arbitrarily worse). A constant model that always predicts the expected
value of y, disregarding the input features, would get a R^2 score of
0.0.

Parameters
----------
X : None or array-like of shape (n_samples, n_features)
    Test samples. Passing None as test samples gives the same result
    as passing real test samples, since `DummyRegressor`
    operates independently of the sampled observations.

y : array-like of shape (n_samples,) or (n_samples, n_outputs)
    True values for X.

sample_weight : array-like of shape (n_samples,), default=None
    Sample weights.

Returns
-------
score : float
    R^2 of `self.predict(X)` w.r.t. y.
r   r   r   r   s       r'   r   DummyRegressor.score  s1    : 9A{+Aw}Q=11r*   )r   r   rI   r   r"   r%   )F)r   r   r   r   r   r   r   r   r#   r   r   r(   r
   rV   rk   r   r   r   r   r   s   @r'   r   r     s    ?D   JKLdCV<dCT4i8
$D  $*D4 !
 5S 6Sj$/L2 2r*   r   )$r   r?   numbersr   r   numpyrC   scipy.sparser   r<   baser   r   r   r	   r
   utilsr   utils._param_validationr   r   utils.multiclassr   utils.randomr   utils.statsr   utils.validationr   r   r   r   r   r   r   r   r5   r*   r'   <module>r      sb    <
  "    & 9 0 , - h2& h2Vs2%~} s2r*   