§
    ¥˜ºhp3  ã                   óŒ  — 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	Z	ddl
ZddlmZmZ ddlmZ ddl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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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)ÚexistsÚjoiné   )ÚBunchÚcheck_random_state)Úshuffle)Ú
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)ÚsubsetÚ	data_homer	   r   Ú	percent10Údownload_if_missingÚ
return_X_yÚas_frameT)Úprefer_skip_nested_validationFc                 ó|  — 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` 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

    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   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_kddcup99r.   r/   r2   r1   ÚnpÚlogical_notÚshaper   ÚrandintÚr_Úc_ÚlogÚastypeÚfloatÚshuffle_methodr   r   r   )r   r    r	   r   r!   r"   r#   r$   Úkddcup99r.   r/   r2   r1   ÚsÚtÚnormal_samplesÚnormal_targetsÚabnormal_samplesÚabnormal_targetsÚn_samples_abnormalÚrÚfdescrr0   s                          úb/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/sklearn/datasets/_kddcup99.pyr-   r-   2   so  € õX ¨	Ð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…         }|r^	 t          j        |¦  «        }t          j        |¦  «        }�n(# t          $ r&}t          d4t          |¦  «        › d5�¦  «        |‚d3}~ww xY w|�rãt          |¦  «         t                               d6|j        z  ¦  «         t!          ||¬7¦  «         t#          j        |	¦  «        }t                               d8¦  «         t          ||j        ¦  «        }t+          |d9¬:¦  «        }g }|                     ¦   «         D ]R}|                     ¦   «         }|                     |                     d;d<¦  «                             d=¦  «        ¦  «         ŒS|                     ¦   «          t                               d>¦  «         t9          j        |¦  «         t#          j        |t>          ¬?¦  «        }tA          d@¦  «        D ].}|d3d3…|f          !                    ||         ¦  «        |d3d3…|f<   Œ/|d3d3…d3d2…f         }|d3d3…d2f         }t          j"        ||dA¬B¦  «         t          j"        ||dA¬B¦  «         nt          dC¦  «        ‚tG          ||||g¬D¦  «        S )EaŽ  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.

    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.

    r'   z-py3Úkddcup99_10r?   Ú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     rI   ú
<listcomp>z)_fetch_brute_kddcup99.<locals>.<listcomp>T  s   € Ð%Ð%Ð%˜Q�A�a”DÐ%Ð%Ð%rJ   éÿÿÿÿNz7The cache for fetch_kddcup99 is invalid, please delete z! and run the fetch_kddcup99 againzDownloading %s)Údirnamezextracting archiverG   )r   Úmodeú
Ú ú,zextraction done)Údtypeé*   r   )Úcompressz1Data not found and `download_if_missing` is False)r.   r/   r2   r1   )$r   r   ÚARCHIVE_10_PERCENTÚARCHIVEr   Úintr=   ÚjoblibÚloadÚ	ExceptionÚOSErrorÚstrÚ_mkdirpÚloggerÚinfor   r   r5   rˆ   Údebugr   r   Ú	readlinesÚdecodeÚappendÚreplaceÚsplitÚcloseÚosÚremoveÚasarrayÚobjectÚranger<   Údumpr   )r    r"   r!   Ú
dir_suffixÚ
kddcup_dirÚarchiveÚsamples_pathÚtargets_pathÚ	availableÚdtÚcolumn_namesr1   r2   ÚXÚyÚeÚDTÚarchive_pathÚfile_ÚXyÚlineÚjs                         rI   r4   r4   ö   s¦  € õF ¨	Ð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øÝð 	ð 	ð 	ÝðFÝ�z‘?”?ðFð Fð Fñô ð ðøøøøð	øøøð 
ñ KÝ�
ÑÔÐÝ�ŠÐ$ w¤{Ñ2Ñ3Ô3Ð3Ý�g zÐ2Ñ2Ô2Ð2ÝŒX�b‰\Œ\ˆÝ�ŠÐ)Ñ*Ô*Ð*Ý˜J¨Ô(8Ñ9Ô9ˆÝ ,°SÐ9Ñ9Ô9ˆØˆØ—O’OÑ%Ô%ð 	9ð 	9ˆDØ—;’;‘=”=ˆDØ�IŠI�d—l’l 4¨Ñ,Ô,×2Ò2°3Ñ7Ô7Ñ8Ô8Ð8Ð8Ø�Š‰ŒˆÝ�ŠÐ&Ñ'Ô'Ð'Ý
Œ	�,ÑÔÐåŒ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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     rI   r“   r“   ‰  s]   € ðÝ
Œ�A‰ŒˆˆˆøÝð ð ð ØŒ7•e”lÒ"Ð"Øð #Ð"Ð"Ð"Ð"Ð"øøøøðøøøs   ‚ ˜
A¢>¾A)NTT)%Ú__doc__r¶   Úloggingr�   Úgzipr   Úos.pathr   r   rŽ   Únumpyr5   Úutilsr   r   r	   r>   Úutils._param_validationr
   r   r†   r   Ú_baser   r   r   r   rŒ   r‹   Ú	getLoggerÚ__name__r”   r’   ÚPathLiker-   r4   r“   r~   rJ   rI   ú<module>rÄ      s2  ððð ð €€€Ø €€€Ø 	€	€	€	Ø Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à €€€Ø Ð Ð Ð à -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø -Ð -Ð -Ð -Ð -Ð -Ø AÐ AÐ AÐ AÐ AÐ AÐ AÐ AØ Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð ð ð Ð
ØØ8ØOðñ ô €ð (Ð'ØØ8ØOðñ ô Ð ð 
ˆÔ	˜8Ñ	$Ô	$€ð €à�:Ð:Ð:Ð:Ñ;Ô;¸TÐBØ˜2œ;¨Ð-Ø�;Ø'Ð(Ø�[Ø )˜{Ø �kØ�Kð	ð 	ð #'ðñ ô ð ØØØØØØØðtð tð tð tñô ðtðnPð Pð Pð Pðfð ð ð ð rJ   