
    \!h                     6    S SK Jr  S SKrS SKrS rS rSS jrg)    )combinationsNc                    XU4 H'  n[        UR                  5      S:w  d  M  [        S5      e   U R                  S   UR                  S   :w  a  [        S5      eU R                  S   UR                  S   :w  a  [        S5      eX:H  R                  [        5      nX:H  R                  [        5      nXE-   nXE-
  n[
        R                  " S[        S9n[
        R                  " US:H  5      US	'   [
        R                  " US:H  5      US
'   [
        R                  " US:H  5      US'   [
        R                  " US:H  5      US'   U$ )a_  
Compute a 2x2 contigency table for McNemar's test.

Parameters
-----------
y_target : array-like, shape=[n_samples]
    True class labels as 1D NumPy array.
y_model1 : array-like, shape=[n_samples]
    Predicted class labels from model as 1D NumPy array.
y_model2 : array-like, shape=[n_samples]
    Predicted class labels from model 2 as 1D NumPy array.

Returns
----------
tb : array-like, shape=[2, 2]
   2x2 contingency table with the following contents:
   a: tb[0, 0]: # of samples that both models predicted correctly
   b: tb[0, 1]: # of samples that model 1 got right and model 2 got wrong
   c: tb[1, 0]: # of samples that model 2 got right and model 1 got wrong
   d: tb[1, 1]: # of samples that both models predicted incorrectly

Examples
-----------
For usage examples, please see
https://rasbt.github.io/mlxtend/user_guide/evaluate/mcnemar_table/

   /One or more input arrays are not 1-dimensional.r   z=y_target and y_model1 contain a different number of elements.z=y_target and y_model2 contain a different number of elements.   r   )dtyper   r   r   r   r   r   r   r   r   )lenshape
ValueErrorastypeintnpzerossum)	y_targety_model1y_model2ary
m1_vs_true
m2_vs_true	plus_true
minus_truetbs	            kC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\mlxtend/evaluate/mcnemar.pymcnemar_tabler!      s-   8 H-syy>QNOO . ~~aHNN1--N
 	
 ~~aHNN1--N
 	
 &..s3J&..s3J'I(J	&	$Bvvi1n%BtHvvjAo&BtHvvjB&'BtHvvi1n%BtHI    c                 .   [        5       n[        U5      nU /U-    HE  n[        UR                  5      S:w  a  [	        S5      eUR                  UR                  S   5        MG     [        U5      S:  a  [	        S5      e[        U5      nUS:  a  [	        S5      e0 n[        [        U5      S5       H  n[        R                  " S5      nXUS      :H  R                  [        5      nXUS      :H  R                  [        5      n	X-   n
X-
  n[        R                  " U
S:H  5      US'   [        R                  " US:H  5      US	'   [        R                  " US
:H  5      US'   [        R                  " U
S:H  5      US'   SUS   < SUS   < 3nXuU'   M     U$ )a  
Compute multiple 2x2 contigency tables for McNemar's
test or Cochran's Q test.

Parameters
-----------
y_target : array-like, shape=[n_samples]
    True class labels as 1D NumPy array.

y_model_predictions : array-like, shape=[n_samples]
    Predicted class labels for a model.

Returns
----------

tables : dict
    Dictionary of NumPy arrays with shape=[2, 2]. Each dictionary
    key names the two models to be compared based on the order the
    models were passed as `*y_model_predictions`. The number of
    dictionary entries is equal to the number of pairwise combinations
    between the m models, i.e., "m choose 2."

    For example the following target array (containing the true labels)
    and 3 models

    - y_true = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1])
    - y_mod0 = np.array([0, 1, 0, 0, 0, 1, 1, 0, 0, 0])
    - y_mod1 = np.array([0, 0, 1, 1, 0, 1, 1, 0, 0, 0])
    - y_mod2 = np.array([0, 1, 1, 1, 0, 1, 0, 0, 0, 0])

    would result in the following dictionary:


    {'model_0 vs model_1': array([[ 4.,  1.],
                                  [ 2.,  3.]]),
     'model_0 vs model_2': array([[ 3.,  0.],
                                  [ 3.,  4.]]),
     'model_1 vs model_2': array([[ 3.,  0.],
                                  [ 2.,  5.]])}

    Each array is structured in the following way:

    - tb[0, 0]: # of samples that both models predicted correctly
    - tb[0, 1]: # of samples that model a got right and model b got wrong
    - tb[1, 0]: # of samples that model b got right and model a got wrong
    - tb[1, 1]: # of samples that both models predicted incorrectly

Examples
-----------

For usage examples, please see
https://rasbt.github.io/mlxtend/user_guide/evaluate/mcnemar_tables/

r   r   r   z;Each prediction array must have the same number of samples.r   z+Provide at least 2 model prediction arrays.r   r
   r   r   r   r   model_z
 vs model_)setlistr   r   r   addr   ranger   r   r   r   r   )r   y_model_predictions
model_lensr   
num_modelstablescombr   model1_vs_truemodel2_vs_truer   r   name_strs                r    mcnemar_tablesr1   H   s   n J23z//syy>QNOOsyy|$ 0
 :L
 	
 ()JA~FGGFU:.2XXf"$q'&BBJJ3O"$q'&BBJJ3O"3	#4
66)q.)466*/*466**+466)q.)4-1!Wd1g>x 3 Mr"   c                    U R                   S:X  d  [        S5      eU S   nU S   nX4-   nU(       d  U(       a'  [        U S   U S   -
  5      S-
  S-  [        U5      -  nOU S   U S   -
  S-  [        U5      -  n[        R
                  R                  R                  R                  US5      nXg4$ Sn[        [        R
                  R                  R                  [        X45      X4-   S	5      S
-  S5      nXg4$ )a  
McNemar test for paired nominal data

Parameters
-----------
ary : array-like, shape=[2, 2]
    2 x 2 contigency table (as returned by evaluate.mcnemar_table),
    where
    a: ary[0, 0]: # of samples that both models predicted correctly
    b: ary[0, 1]: # of samples that model 1 got right and model 2 got wrong
    c: ary[1, 0]: # of samples that model 2 got right and model 1 got wrong
    d: aryCell [1, 1]: # of samples that both models predicted incorrectly
corrected : array-like, shape=[n_samples] (default: True)
    Uses Edward's continuity correction for chi-squared if `True`
exact : bool, (default: False)
    If `True`, uses an exact binomial test comparing b to
    a binomial distribution with n = b + c and p = 0.5.
    It is highly recommended to use `exact=True` for sample sizes < 25
    since chi-squared is not well-approximated
    by the chi-squared distribution!

Returns
-----------
chi2, p : float or None, float
    Returns the chi-squared value and the p-value;
    if `exact=True` (default: `False`), `chi2` is `None`

Examples
-----------

For usage examples, please see
https://rasbt.github.io/mlxtend/user_guide/evaluate/mcnemar/

r   z Input array must be a 2x2 array.r   r   g      ?r   r   Ng      ?g       @)r   r   absfloatscipystatsdistributionschi2sfminbinomcdf)r   	correctedexactbcnr8   ps           r    mcnemarrC      s    H 99;<<D	AD	A	AD	CI-.4:U1XEDID	)a/%(:DKK%%**--dA6 7N !!%%c!i<sBCH 7Nr"   )TF)		itertoolsr   numpyr   scipy.statsr5   r!   r1   rC    r"   r    <module>rH      s"    #  7tYx=r"   