U
    ½mœdã  ã                   @   sÄ   d Z ddlmZ ddlmZmZ ddlZddlZddl	Z	ddl
Z
ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ edddd�Ze	 e¡Zdddddœdd„ZdS )a:  California housing dataset.

The original database is available from StatLib

    http://lib.stat.cmu.edu/datasets/

The data contains 20,640 observations on 9 variables.

This dataset contains the average house value as target variable
and the following input variables (features): average income,
housing average age, average rooms, average bedrooms, population,
average occupation, latitude, and longitude in that order.

References
----------

Pace, R. Kelley and Ronald Barry, Sparse Spatial Autoregressions,
Statistics and Probability Letters, 33 (1997) 291-297.

é    )Úexists)ÚmakedirsÚremoveNé   )Úget_data_home)Ú_convert_data_dataframe)Ú_fetch_remote)Ú_pkl_filepath)ÚRemoteFileMetadata)Ú
load_descré   )ÚBunchzcal_housing.tgzz.https://ndownloader.figshare.com/files/5976036Z@aaa5c9a6afe2225cc2aed2723682ae403280c4a3695a2ddda4ffb5d8215ea681)ÚfilenameÚurlZchecksumTF)Ú	data_homeÚdownload_if_missingÚ
return_X_yÚas_framec              
   C   sÞ  t | d�} t| ƒst| ƒ t| dƒ}t|ƒsÆ|s8tdƒ‚t d tj	| ¡¡ t
t| d�}tjd|d��P}tj| d¡d	d
�}dddddddddg	}|dd…|f }tj||dd� W 5 Q R X t|ƒ n
t |¡}ddddddddg}	|dd…df |dd…dd…f  }
}|dd…df  |dd…df   < |dd…df  |dd…df   < |dd…df |dd…df  |dd…df< |
d }
tdƒ}|}|
}d}d g}|�r¼td!||
|	|ƒ\}}}|�rÊ||fS t|||||	|d"�S )#aÒ	  Load the California housing dataset (regression).

    ==============   ==============
    Samples total             20640
    Dimensionality                8
    Features                   real
    Target           real 0.15 - 5.
    ==============   ==============

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

    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 a IOError 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.data, data.target)`` instead of a Bunch
        object.

        .. versionadded:: 0.20

    as_frame : bool, default=False
        If True, the data is a pandas DataFrame including columns with
        appropriate dtypes (numeric, string or categorical). The target is
        a pandas DataFrame or Series depending on the number of target_columns.

        .. versionadded:: 0.23

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

        data : ndarray, shape (20640, 8)
            Each row corresponding to the 8 feature values in order.
            If ``as_frame`` is True, ``data`` is a pandas object.
        target : numpy array of shape (20640,)
            Each value corresponds to the average
            house value in units of 100,000.
            If ``as_frame`` is True, ``target`` is a pandas object.
        feature_names : list of length 8
            Array of ordered feature names used in the dataset.
        DESCR : str
            Description of the California housing dataset.
        frame : pandas DataFrame
            Only present when `as_frame=True`. DataFrame with ``data`` and
            ``target``.

            .. versionadded:: 0.23

    (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

    Notes
    -----

    This dataset consists of 20,640 samples and 9 features.
    )r   zcal_housing.pkzz1Data not found and `download_if_missing` is Falsez&Downloading Cal. housing from {} to {})Údirnamezr:gz)ÚmodeÚnamez"CaliforniaHousing/cal_housing.dataú,)Ú	delimiteré   é   r   é   é   é   é   r   r   N)ÚcompressZMedIncZHouseAgeZAveRoomsZ	AveBedrmsZ
PopulationZAveOccupZLatitudeZ	Longitudeg     jø@zcalifornia_housing.rstZMedHouseValÚfetch_california_housing)ÚdataÚtargetÚframeÚtarget_namesÚfeature_namesZDESCR)r   r   r   r	   ÚIOErrorÚloggerÚinfoÚformatÚARCHIVEr   r   ÚtarfileÚopenÚnpZloadtxtÚextractfileÚjoblibÚdumpr   Úloadr   r   r   )r   r   r   r   ÚfilepathÚarchive_pathÚfZcal_housingZcolumns_indexr%   r"   r!   ÚdescrÚXÚyr#   r$   © r8   ú]/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/sklearn/datasets/_california_housing.pyr    5   sv    H

ÿ ÿ

ø&$$,ÿ    ÿ
úr    )Ú__doc__Úos.pathr   Úosr   r   r+   Únumpyr-   Úloggingr/   Ú r   Ú_baser   r   r	   r
   r   Úutilsr   r*   Ú	getLoggerÚ__name__r'   r    r8   r8   r8   r9   Ú<module>   s0   ý
   ÿ