Ë
    ÷Q(hŽ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mZ ddlmZ dd	lmZmZmZ d
dlmZ d
dlmZmZmZmZ  eddd¬«      Z eddd¬«      Z  ejB                  e"«      Z# e eh d£«      dge$ejJ                  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(y)%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é   )ÚBunchÚcheck_random_state)Úshuffle)ÚIntervalÚ
StrOptionsÚvalidate_paramsé   )Úget_data_home)ÚRemoteFileMetadataÚ_convert_data_dataframeÚ_fetch_remoteÚ
load_descrÚ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        
         óN  — t        |¬«      }t        |||||	¬«      }
|
j                  }|
j                  }|
j                  }|
j
                  }| dk(  r—|dk(  }t        j                  |«      }||dd…f   }||   }||dd…f   }||   }|j                  d   }t        |«      }|j                  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   j                  t        d¬«      «      |dd…df<   t        j                  |dd…df   dz   j                  t        d¬«      «      |dd…df<   t        j                  |dd…df   dz   j                  t        d¬«      «      |dd…df<   | d	k(  rO|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(  rO|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(  rEt        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` object.

        .. 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é   é   r   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/skyplay_api_hub/venv/lib/python3.12/site-packages/sklearn/datasets/_kddcup99.pyr7   r7   6   s×  € ôt ¨	Ô2€IÜ$ØØØ/ØØô€Hð �=‰=€DØ�_‰_€FØ×*Ñ*€MØ×(Ñ(€Là�‚~Ø�jÑ ˆÜ�N‰N˜1ÓˆØ˜a¢˜d™ˆØ ™ˆØ ¢1 ™:ÐØ! !™9Ðà-×3Ñ3°AÑ6Ðä)¨,Ó7ˆØ× Ñ  Ð$6¸Ó=ˆØ+¨AÑ.ÐØ+¨AÑ.Ðä�u‰u�^Ð%5Ð5Ñ6ˆÜ—‘�~Ð'7Ð7Ñ8ˆà�‚~˜ 6Ò)¨V°vÓ-=à’�B�‰K˜1ÑˆÜ�u‰u�T˜!˜S˜b˜S˜&‘\ 4¨¨2©3¨¡<Ð/Ñ0ˆØ% c rÐ*¨]¸2¸3Ð-?Ñ?ˆØ˜‘ˆä—V‘V˜T¢! Q $™Z¨#Ñ-×5Ñ5´eÀ%Ð5ÓHÓIˆŠQ�ˆT‰
Ü—V‘V˜T¢! Q $™Z¨#Ñ-×5Ñ5´eÀ%Ð5ÓHÓIˆŠQ�ˆT‰
Ü—V‘V˜T¢! Q $™Z¨#Ñ-×5Ñ5´eÀ%Ð5ÓHÓIˆŠQ�ˆT‰
à�VÒØ’Q˜�T‘
˜gÑ%ˆAØ˜‘7ˆDØ˜A‘YˆFÜ—5‘5˜ša ˜d™ Tª!¨Q¨$¡Z°²a¸°d±Ð;Ñ<ˆDØ*¨1Ñ-¨}¸QÑ/?ÀÈqÑAQÐRˆMà�VÒØ’Q˜�T‘
˜gÑ%ˆAØ˜‘7ˆDØ˜A‘YˆFÜ—5‘5˜ša ˜d™ Tª!¨Q¨$¡Z°²a¸°d±Ð;Ñ<ˆDØ*¨1Ñ-¨}¸QÑ/?ÀÈqÑAQÐRˆMà�TŠ>Ü—5‘5˜ša ˜d™ Tª!¨Q¨$¡Z°²a¸°d±¸TÂ!ÀQÀ$¹ZÐGÑHˆDà˜aÑ Ø˜aÑ Ø˜aÑ Ø˜aÑ ð	ˆMñ Ü% d¨FÀÔ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‘}|D �cg c]  }|d1   ‘Œ	 }}|d2   }|d3d2 }|
r-	 t        j                  |«      }t        j                  |	«      }�nº|�r¬t        |«       t        j                  d6|j                  z  «       t!        ||||¬7«       t#        j$                  |«      }t        j'                  d8«       t        ||j(                  «      }t+        |d9¬:«      }g }|j-                  «       D ]B  }|j/                  «       }|j1                  |j3                  d;d<«      j5                  d=«      «       ŒD |j7                  «        t        j'                  d>«       t9        j:                  |«       t#        j<                  |t>        ¬?«      }tA        d@«      D ]$  }|d3d3…|f   jC                  ||   «      |d3d3…|f<   Œ& |d3d3…d3d2…f   }|d3d3…d2f   }t        jD                  ||d1¬A«       t        jD                  ||	d1¬A«       nt        dB«      ‚tG        ||||g¬C«      S c c}w # t        $ r}t        d4t        |«      › d5�«      |‚d3}~ww xY w)Da5  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.

    r1   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ÚS16r   éÿÿÿÿ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é*   )Úcompressz1Data not found and `download_if_missing` is False)r8   r9   r<   r;   )$r   r   ÚARCHIVE_10_PERCENTÚARCHIVEr   ÚintrG   ÚjoblibÚloadÚ	ExceptionÚOSErrorÚstrÚ_mkdirpÚloggerÚinfor   r   r?   r�   Údebugr   r   Ú	readlinesÚdecodeÚappendÚreplaceÚsplitÚcloseÚosÚremoveÚasarrayÚobjectÚrangerF   Údumpr	   )r&   r(   r'   r+   r,   Ú
dir_suffixÚ
kddcup_dirÚarchiveÚsamples_pathÚtargets_pathÚ	availableÚdtÚcÚcolumn_namesr;   r<   ÚXÚyÚeÚDTÚarchive_pathÚfile_ÚXyÚlineÚjs                            rS   r>   r>   
  só  € ôV ¨	Ô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 #%Ö%˜Q�A�a“DÐ%€LÐ%Ø Ñ#€LØ   "Ð%€Máð	Ü—‘˜LÓ)ˆAÜ—‘˜LÓ)ŠAò 
Ü�
ÔÜ�‰Ð$ w§{¡{Ñ2Ô3Ü�g z¸YÈeÕTÜ�X‰X�b‹\ˆÜ�‰Ð)Ô*Ü˜J¨×(8Ñ(8Ó9ˆÜ ,°SÔ9ˆØˆØ—O‘OÓ%ò 	9ˆDØ—;‘;“=ˆDØ�I‰I�d—l‘l 4¨Ó,×2Ñ2°3Ó7Õ8ð	9ð 	�‰ŒÜ�‰Ð&Ô'Ü
�	‰	�,Ôä�Z‰Z˜¤&Ô)ˆÜ�r“ò 	.ˆAØš!˜Q˜$‘x—‘ r¨!¡uÓ-ˆBŠq�!ˆtŠHð	.ð Šq�#�2�#ˆv‰JˆØŠq�"ˆu‰Iˆô
 	�‰�A�|¨aÕ0Ü�‰�A�|¨aÖ0äÐIÓJÐJäØØØ#Ø"�^ô	ð ùò[ &øô ò 	ÜØIÜ�z“?Ð#Ð#DðFóð ðûð	ús   ÆN.Æ8*N3 Î3	OÎ<OÏOc                 ó˜   — 	 t        j                  | «       y# t        $ r(}|j                  t        j                  k7  r‚ Y d}~y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‰7”e—l‘lÒ"Øô #ûðús   ‚ ˜	A	¡AÁA	)NTTr.   r/   ))Ú__doc__r¼   Úloggingr¢   Úgzipr   Únumbersr   r   Úos.pathr   r   r“   Únumpyr?   Úutilsr	   r
   r   rH   Úutils._param_validationr   r   r   r‹   r   Ú_baser   r   r   r   r‘   r�   Ú	getLoggerÚ__name__r™   r—   ÚPathLiker7   r>   r˜   © rT   rS   ú<module>rÌ      s2  ðñó Û Û 	Ý ß "ß  ã Û ç -Ý -ß KÑ KÝ ÷ó ñ ØØ8ØOô€ñ (ØØ8ØOôÐ ð 
ˆ×	Ñ	˜8Ó	$€ñ áÒ:Ó;¸TÐBØ˜2Ÿ;™;¨Ð-Ø�;Ø'Ð(Ø�[Ø )˜{Ø �kØ�KÙ˜x¨¨D¸Ô@ÐAÙ˜4  d°9Ô=Ð>ñð #'ôð" ØØØØØØØØØ
óBóðBðL RUóXóvrT   