fetch_california_housing#

sklearn.datasets.fetch_california_housing(*, data_home=None, download_if_missing=True, return_X_y=False, as_frame=False, n_retries=3, delay=1.0)[source]#

加载加州房价数据集(回归)。

样本总数

20640

维度

8

特征值范围

真实

目标

真实 0.15 - 5.

欲了解更多信息,请参阅用户指南

参数:
data_homestr or path-like, default=None

为数据集指定另一个下载和缓存文件夹。默认情况下,所有 scikit-learn 数据都存储在 ‘~/scikit_learn_data’ 子文件夹中。

download_if_missingbool, 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_ybool, default=False

If True, returns (data.data, data.target) instead of a Bunch object.

0.20 版本新增。

as_framebool, default=False

如果为 True,则数据是一个 pandas DataFrame,其中包括具有适当 dtype(数字、字符串或分类)的列。目标是一个 pandas DataFrame 或 Series,具体取决于 target_columns 的数量。

0.23 版本新增。

n_retriesint, default=3

Number of retries when HTTP errors are encountered.

1.5 版本新增。

delayfloat, default=1.0

Number of seconds between retries.

1.5 版本新增。

返回:
datasetBunch

Dictionary-like object, with the following attributes.

datandarray, 形状 (20640, 8)

每行对应按顺序排列的 8 个特征值。如果 as_frame 为 True,data 是一个 pandas 对象。

targetnumpy array, 形状 (20640,)

每个值对应以 100,000 为单位的中位数房价。如果 as_frame 为 True,target 是一个 pandas 对象。

feature_names长度为 8 的列表

数据集中使用的有序特征名称数组。

DESCRstr

加州住房数据集的描述。

framepandas DataFrame

仅当 as_frame=True 时存在。包含 datatarget 的 DataFrame。

0.23 版本新增。

(data, target)tuple if return_X_y is True

包含两个 ndarray 的元组。第一个包含一个形状为 (n_samples, n_features) 的二维数组,其中每一行代表一个样本,每一列代表特征。第二个 ndarray 的形状为 (n_samples,),包含目标样本。

0.20 版本新增。

注意事项

此数据集包含 20,640 个样本和 9 个特征。

示例

>>> from sklearn.datasets import fetch_california_housing
>>> housing = fetch_california_housing()
>>> print(housing.data.shape, housing.target.shape)
(20640, 8) (20640,)
>>> print(housing.feature_names[0:6])
['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup']