§
    qŠtj)6  ã                   óâ  — d Z ddlZddlZddlZddlmZ ddlmZmZ ddl	m
Z
mZ ddlZddlZddlmZ ddlmZmZ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  eddd¬¦  «        Z eddd¬¦  «        Z  ej!        e"¦  «        Z# e eh d£¦  «        dge$ej%        dgdgdgdgdgdgdg eeddd¬¦  «        g eeddd¬¦  «        gdœ
d¬¦  «        dddddddddddœ
d „¦   «         Z&	 d#d!„Z'd"„ Z(dS )$zÙKDDCUP 99 dataset.

A classic dataset for anomaly detection.

The dataset page is available from UCI Machine Learning Repository

https://archive.ics.uci.edu/ml/machine-learning-databases/kddcup99-mld/kddcup.data.gz

é    N)ÚGzipFile)ÚIntegralÚReal)ÚexistsÚjoin)Úget_data_home)ÚRemoteFileMetadataÚ_convert_data_dataframeÚ_fetch_remoteÚ
load_descr)ÚBunchÚcheck_random_state)Úshuffle)ÚIntervalÚ
StrOptionsÚvalidate_paramsÚkddcup99_dataz.https://ndownloader.figshare.com/files/5976045Ú@3b6c942aa0356c0ca35b7b595a26c89d343652c9db428893e7494f837b274292)ÚfilenameÚurlÚchecksumÚkddcup99_10_dataz.https://ndownloader.figshare.com/files/5976042Ú@8045aca0d84e70e622d1148d7df782496f6333bf6eb979a1b0837c42a9fd9561>   ÚSAÚSFÚhttpÚsmtpÚbooleanÚrandom_stateé   Úleft)Úclosedg        Úneither)
ÚsubsetÚ	data_homer   r   Ú	percent10Údownload_if_missingÚ
return_X_yÚas_frameÚ	n_retriesÚdelayT)Úprefer_skip_nested_validationFé   ç      ð?c        
         ó€  — t          |¬¦  «        }t          |||||	¬¦  «        }
|
j        }|
j        }|
j        }|
j        }| dk    r­|dk    }t          j        |¦  «        }||dd…f         }||         }||dd…f         }||         }|j        d         }t          |¦  «        }| 
                    d|d¦  «        }||         }||         }t          j        ||f         }t          j        ||f         }| dk    s| d	k    s| d
k    �r]|dd…df         dk    }t          j        ||dd…f         ||dd…f         f         }|dd…         |dd…         z   }||         }t          j        |dd…df         dz                        t          d¬¦  «        ¦  «        |dd…df<   t          j        |dd…df         dz                        t          d¬¦  «        ¦  «        |dd…df<   t          j        |dd…df         dz                        t          d¬¦  «        ¦  «        |dd…df<   | d	k    rj|dd…df         dk    }||         }||         }t          j        |dd…df         |dd…df         |dd…df         f         }|d         |d         |d         g}| d
k    rj|dd…df         dk    }||         }||         }t          j        |dd…df         |dd…df         |dd…df         f         }|d         |d         |d         g}| dk    r\t          j        |dd…df         |dd…df         |dd…df         |dd…df         f         }|d         |d         |d         |d         g}|rt!          |||¬¦  «        \  }}t#          d¦  «        }d}|rt%          d||||¦  «        \  }}}|r||fS t'          ||||||¬¦  «        S )a»  Load the kddcup99 dataset (classification).

    Download it if necessary.

    =================   ====================================
    Classes                                               23
    Samples total                                    4898431
    Dimensionality                                        41
    Features            discrete (int) or continuous (float)
    =================   ====================================

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

    .. versionadded:: 0.18

    Parameters
    ----------
    subset : {'SA', 'SF', 'http', 'smtp'}, default=None
        To return the corresponding classical subsets of kddcup 99.
        If None, return the entire kddcup 99 dataset.

    data_home : str or path-like, default=None
        Specify another download and cache folder for the datasets. By default
        all scikit-learn data is stored in '~/scikit_learn_data' subfolders.

        .. versionadded:: 0.19

    shuffle : bool, default=False
        Whether to shuffle dataset.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation for dataset shuffling and for
        selection of abnormal samples if `subset='SA'`. Pass an int for
        reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    percent10 : bool, default=True
        Whether to load only 10 percent of the data.

    download_if_missing : bool, default=True
        If False, raise an OSError if the data is not locally available
        instead of trying to download the data from the source site.

    return_X_y : bool, default=False
        If True, returns ``(data, target)`` instead of a Bunch object. See
        below for more information about the `data` and `target` objects.

        .. versionadded:: 0.20

    as_frame : bool, default=False
        If `True`, returns a pandas Dataframe for the ``data`` and ``target``
        objects in the `Bunch` returned object; `Bunch` return object will also
        have a ``frame`` member.

        .. versionadded:: 0.24

    n_retries : int, default=3
        Number of retries when HTTP errors are encountered.

        .. versionadded:: 1.5

    delay : float, default=1.0
        Number of seconds between retries.

        .. versionadded:: 1.5

    Returns
    -------
    data : :class:`~sklearn.utils.Bunch`
        Dictionary-like object, with the following attributes.

        data : {ndarray, dataframe} of shape (494021, 41)
            The data matrix to learn. If `as_frame=True`, `data` will be a
            pandas DataFrame.
        target : {ndarray, series} of shape (494021,)
            The regression target for each sample. If `as_frame=True`, `target`
            will be a pandas Series.
        frame : dataframe of shape (494021, 42)
            Only present when `as_frame=True`. Contains `data` and `target`.
        DESCR : str
            The full description of the dataset.
        feature_names : list
            The names of the dataset columns
        target_names: list
            The names of the target columns

    (data, target) : tuple if ``return_X_y`` is True
        A tuple of two ndarray. The first containing a 2D array of
        shape (n_samples, n_features) with each row representing one
        sample and each column representing the features. The second
        ndarray of shape (n_samples,) containing the target samples.

        .. versionadded:: 0.20
    ©r%   )r%   r&   r'   r*   r+   r   s   normal.Nr   i1  r   r   r   é   r    é   gš™™™™™¹?F)Úcopyé   é   é   s   https   smtp)r   zkddcup99.rstÚfetch_kddcup99)ÚdataÚtargetÚframeÚtarget_namesÚfeature_namesÚDESCR)r   Ú_fetch_brute_kddcup99r8   r9   r<   r;   ÚnpÚlogical_notÚshaper   ÚrandintÚr_Úc_ÚlogÚastypeÚfloatÚshuffle_methodr   r
   r   )r$   r%   r   r   r&   r'   r(   r)   r*   r+   Úkddcup99r8   r9   r<   r;   ÚsÚtÚnormal_samplesÚnormal_targetsÚabnormal_samplesÚabnormal_targetsÚn_samples_abnormalÚrÚfdescrr:   s                            úX/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/datasets/_kddcup99.pyr7   r7   6   su  € õt ¨	Ð2Ñ2Ô2€IÝ$ØØØ/ØØðñ ô €Hð Œ=€DØŒ_€FØÔ*€MØÔ(€Là�‚~€~Ø�jÒ ˆÝŒN˜1ÑÔˆØ˜a   ˜dœˆØ œˆØ  1 1 1 œ:ÐØ! !œ9Ðà-Ô3°AÔ6Ðå)¨,Ñ7Ô7ˆØ× Ò  Ð$6¸Ñ=Ô=ˆØ+¨AÔ.ÐØ+¨AÔ.ÐåŒu�^Ð%5Ð5Ô6ˆÝ”�~Ð'7Ð7Ô8ˆà�‚~€~˜ 6Ò)Ð)¨V°vÒ-=Ñ-=à����B�ŒK˜1ÒˆÝŒu�T˜!˜S˜b˜S˜&”\ 4¨¨2¨3¨3¨¤<Ð/Ô0ˆØ% c r cÔ*¨]¸2¸3¸3Ô-?Ñ?ˆØ˜”ˆå”V˜T ! ! ! Q $œZ¨#Ñ-×5Ò5µeÀ%Ð5ÑHÔHÑIÔIˆˆQˆQˆQ�ˆT‰
Ý”V˜T ! ! ! Q $œZ¨#Ñ-×5Ò5µeÀ%Ð5ÑHÔHÑIÔIˆˆQˆQˆQ�ˆT‰
Ý”V˜T ! ! ! Q $œZ¨#Ñ-×5Ò5µeÀ%Ð5ÑHÔHÑIÔIˆˆQˆQˆQ�ˆT‰
à�VÒÐØ�Q�Q�Q˜�T”
˜gÒ%ˆAØ˜”7ˆDØ˜A”YˆFÝ”5˜˜a˜a˜a ˜dœ T¨!¨!¨!¨Q¨$¤Z°°a°a°a¸°d´Ð;Ô<ˆDØ*¨1Ô-¨}¸QÔ/?ÀÈqÔAQÐRˆMà�VÒÐØ�Q�Q�Q˜�T”
˜gÒ%ˆAØ˜”7ˆDØ˜A”YˆFÝ”5˜˜a˜a˜a ˜dœ T¨!¨!¨!¨Q¨$¤Z°°a°a°a¸°d´Ð;Ô<ˆDØ*¨1Ô-¨}¸QÔ/?ÀÈqÔAQÐRˆMà�TŠ>ˆ>Ý”5˜˜a˜a˜a ˜dœ T¨!¨!¨!¨Q¨$¤Z°°a°a°a¸°d´¸TÀ!À!À!ÀQÀ$¼ZÐGÔHˆDà˜aÔ Ø˜aÔ Ø˜aÔ Ø˜aÔ ð	ˆMð ð OÝ% d¨FÀÐNÑNÔN‰ˆˆfå˜Ñ'Ô'€Fà€EØð 
Ý5Ø˜d F¨M¸<ñ
ô 
Ñˆˆt�Vð ð Ø�Vˆ|ÐåØØØØ!Ø#Øðñ ô ð ó    c                 ó´  — t          | ¬¦  «        } d}|rt          | d|z   ¦  «        }t          }nt          | d|z   ¦  «        }t          }t          |d¦  «        }t          |d¦  «        }	t	          |¦  «        }
g dt
          f‘d‘d	‘d
‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt
          f‘dt          f‘d t          f‘d!t          f‘d"t          f‘d#t          f‘d$t          f‘d%t          f‘d&t
          f‘d't
          f‘d(t          f‘d)t          f‘d*t          f‘d+t          f‘d,t          f‘d-t          f‘d.t          f‘d/t          f‘d0‘}d1„ |D ¦   «         }|d2         }|d3d2…         }|
rQ	 t          j        |¦  «        }t          j        |	¦  «        }�n"# t          $ r}t          d4|› d5�¦  «        |‚d3}~ww xY w|�rêt          |¦  «         t                               d6|j        z  ¦  «         t          ||||¬7¦  «         t!          j        |¦  «        }t                               d8¦  «         t          ||j        ¦  «        }g }t)          |d9¬:¦  «        5 }|                     ¦   «         D ]R}|                     ¦   «         }|                     |                     d;d<¦  «                             d=¦  «        ¦  «         ŒS	 d3d3d3¦  «         n# 1 swxY w Y   t                               d>¦  «         t5          j        |¦  «         t!          j        |t:          ¬?¦  «        }t=          d@¦  «        D ].}|d3d3…|f                              ||         ¦  «        |d3d3…|f<   Œ/|d3d3…d3d2…f         }|d3d3…d2f         }t          j         ||dA¬B¦  «         t          j         ||	dA¬B¦  «         nt          dC¦  «        ‚tC          ||||g¬D¦  «        S )Ea5  Load the kddcup99 dataset, downloading it if necessary.

    Parameters
    ----------
    data_home : str, default=None
        Specify another download and cache folder for the datasets. By default
        all scikit-learn data is stored in '~/scikit_learn_data' subfolders.

    download_if_missing : bool, default=True
        If False, raise an OSError if the data is not locally available
        instead of trying to download the data from the source site.

    percent10 : bool, default=True
        Whether to load only 10 percent of the data.

    n_retries : int, default=3
        Number of retries when HTTP errors are encountered.

    delay : float, default=1.0
        Number of seconds between retries.

    Returns
    -------
    dataset : :class:`~sklearn.utils.Bunch`
        Dictionary-like object, with the following attributes.

        data : ndarray of shape (494021, 41)
            Each row corresponds to the 41 features in the dataset.
        target : ndarray of shape (494021,)
            Each value corresponds to one of the 21 attack types or to the
            label 'normal.'.
        feature_names : list
            The names of the dataset columns
        target_names: list
            The names of the target columns
        DESCR : str
            Description of the kddcup99 dataset.

    r0   z-py3Úkddcup99_10rI   ÚsamplesÚtargetsÚduration)Úprotocol_typeÚS4)ÚserviceÚS11)ÚflagÚS6Ú	src_bytesÚ	dst_bytesÚlandÚwrong_fragmentÚurgentÚhotÚnum_failed_loginsÚ	logged_inÚnum_compromisedÚ
root_shellÚsu_attemptedÚnum_rootÚnum_file_creationsÚ
num_shellsÚnum_access_filesÚnum_outbound_cmdsÚis_host_loginÚis_guest_loginÚcountÚ	srv_countÚserror_rateÚsrv_serror_rateÚrerror_rateÚsrv_rerror_rateÚsame_srv_rateÚdiff_srv_rateÚsrv_diff_host_rateÚdst_host_countÚdst_host_srv_countÚdst_host_same_srv_rateÚdst_host_diff_srv_rateÚdst_host_same_src_port_rateÚdst_host_srv_diff_host_rateÚdst_host_serror_rateÚdst_host_srv_serror_rateÚdst_host_rerror_rateÚdst_host_srv_rerror_rate)ÚlabelsÚS16c                 ó   — g | ]
}|d          ‘ŒS )r   © )Ú.0Úcs     rS   ú
<listcomp>z)_fetch_brute_kddcup99.<locals>.<listcomp>p  s   € Ð%Ð%Ð%˜Q�A�a”DÐ%Ð%Ð%rT   éÿÿÿÿNz7The cache for fetch_kddcup99 is invalid, please delete z! and run the fetch_kddcup99 againzDownloading %s)Údirnamer*   r+   zextracting archiverQ   )r   Úmodeú
Ú ú,zextraction done)Údtypeé*   r-   )Úcompressz1Data not found and `download_if_missing` is False)r8   r9   r<   r;   )"r   r   ÚARCHIVE_10_PERCENTÚARCHIVEr   ÚintrG   ÚjoblibÚloadÚ	ExceptionÚOSErrorÚ_mkdirpÚloggerÚinfor   r   r?   r’   Údebugr   r   Ú	readlinesÚdecodeÚappendÚreplaceÚsplitÚosÚremoveÚasarrayÚobjectÚrangerF   Údumpr   )r%   r'   r&   r*   r+   Ú
dir_suffixÚ
kddcup_dirÚarchiveÚsamples_pathÚtargets_pathÚ	availableÚdtÚcolumn_namesr;   r<   ÚXÚyÚeÚDTÚarchive_pathÚXyÚfile_ÚlineÚjs                           rS   r>   r>   
  sï  € õV ¨	Ð2Ñ2Ô2€IØ€Jàð Ý˜) ]°ZÑ%?Ñ@Ô@ˆ
Ý$ˆˆå˜) Z°*Ñ%<Ñ=Ô=ˆ
Ýˆå˜
 IÑ.Ô.€LÝ˜
 IÑ.Ô.€LÝ�|Ñ$Ô$€Ið+
Ø	•SÐð+
àð+
ð 	ð+
ð 	ð	+
ð
 
•cÐð+
ð 
•cÐð+
ð 
•ˆð+
ð 
�3Ðð+
ð 
•3ˆð+
ð 
•ˆð+
ð 
�cÐ"ð+
ð 
•cÐð+
ð 
�CÐ ð+
ð 
•sÐð+
ð 
�Ðð+
ð  
•SÐð!+
ð" 
�sÐ#ð#+
ð$ 
•sÐð%+
ð& 
�SÐ!ð'+
ð( 
�cÐ"ð)+
ð* 
�#Ðð++
ð, 
�3Ðð-+
ð. 
•#ˆð/+
ð0 
•cÐð1+
ð2 
�Ðð3+
ð4 
�EÐ"ð5+
ð6 
�Ðð7+
ð8 
�EÐ"ð9+
ð: 
�%Ð ð;+
ð< 
�%Ð ð=+
ð> 
�uÐ%ð?+
ð@ 
�3ÐðA+
ðB 
�sÐ#ðC+
ðD 
"¥5Ð)ðE+
ðF 
"¥5Ð)ðG+
ðH 
'­Ð.ðI+
ðJ 
'­Ð.ðK+
ðL 
 ¥Ð'ðM+
ðN 
$¥UÐ+ðO+
ðP 
 ¥Ð'ðQ+
ðR 
$¥UÐ+ðS+
ðT 	ðU+
€BðZ &Ð% "Ð%Ñ%Ô%€LØ Ô#€LØ   " Ô%€Màð $Kð	Ý”˜LÑ)Ô)ˆAÝ”˜LÑ)Ô)ˆA‰AøÝð 	ð 	ð 	ÝðAØðAð Að Añô ð ðøøøøð	øøøð 
ñ KÝ�
ÑÔÐÝ�ŠÐ$ w¤{Ñ2Ñ3Ô3Ð3Ý�g z¸YÈeÐTÑTÔTÐTÝŒX�b‰\Œ\ˆÝ�ŠÐ)Ñ*Ô*Ð*Ý˜J¨Ô(8Ñ9Ô9ˆØˆå˜|°#Ð6Ñ6Ô6ð 	=¸%ØŸšÑ)Ô)ð =ð =�Ø—{’{‘}”}�Ø—	’	˜$Ÿ,š, t¨RÑ0Ô0×6Ò6°sÑ;Ô;Ñ<Ô<Ð<Ð<ð=ð	=ð 	=ð 	=ñ 	=ô 	=ð 	=ð 	=ð 	=ð 	=ð 	=ð 	=øøøð 	=ð 	=ð 	=ð 	=õ
 	�ŠÐ&Ñ'Ô'Ð'Ý
Œ	�,ÑÔÐåŒZ˜¥&Ð)Ñ)Ô)ˆÝ�r‘”ð 	.ð 	.ˆAØ˜!˜!˜!˜Q˜$”x—’ r¨!¤uÑ-Ô-ˆBˆqˆqˆq�!ˆt‰HˆHàˆqˆqˆq�#�2�#ˆvŒJˆØˆqˆqˆq�"ˆuŒIˆÝŒ�A�|¨aÐ0Ñ0Ô0Ð0ÝŒ�A�|¨aÐ0Ñ0Ô0Ð0Ð0åÐIÑJÔJÐJåØØØ#Ø"�^ð	ñ ô ð s+   Ç:(H$ È$
IÈ.IÉIË'A(MÍM Í#M c                 óŒ   — 	 t          j        | ¦  «         dS # t          $ r!}|j        t          j        k    r‚ Y d}~dS d}~ww xY w)zgEnsure directory d exists (like mkdir -p on Unix)
    No guarantee that the directory is writable.
    N)r¥   Úmakedirsr›   ÚerrnoÚEEXIST)Údrµ   s     rS   rœ   rœ   ¢  s]   € ðÝ
Œ�A‰ŒˆˆˆøÝð ð ð ØŒ7•e”lÒ"Ð"Øð #Ð"Ð"Ð"Ð"Ð"øøøøðøøøs   ‚ ˜
A¢>¾A)NTTr-   r.   ))Ú__doc__r¾   Úloggingr¥   Úgzipr   Únumbersr   r   Úos.pathr   r   r˜   Únumpyr?   Úsklearn.datasetsr   Úsklearn.datasets._baser	   r
   r   r   Úsklearn.utilsr   r   r   rH   Úsklearn.utils._param_validationr   r   r   r–   r•   Ú	getLoggerÚ__name__r�   ÚstrÚPathLiker7   r>   rœ   rˆ   rT   rS   ú<module>rÏ      s‘  ððð ð €€€Ø €€€Ø 	€	€	€	Ø Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à €€€Ø Ð Ð Ð à *Ð *Ð *Ð *Ð *Ð *ðð ð ð ð ð ð ð ð ð ð ð ð 4Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ QÐ Qð Ð
ØØ8ØOðñ ô €ð (Ð'ØØ8ØOðñ ô Ð ð 
ˆÔ	˜8Ñ	$Ô	$€ð €à�:Ð:Ð:Ð:Ñ;Ô;¸TÐBØ˜2œ;¨Ð-Ø�;Ø'Ð(Ø�[Ø )˜{Ø �kØ�KØ�h˜x¨¨D¸Ð@Ñ@Ô@ÐAØ�(˜4  d°9Ð=Ñ=Ô=Ð>ðð ð #'ðñ ô ð" ØØØØØØØØØ
ðBð Bð Bð Bñô ðBðL RUðUð Uð Uð Uðpð ð ð ð rT   