fetch_openml#
- sklearn.datasets.fetch_openml(name: str | None = None, *, version: str | int = 'active', data_id: int | None = None, data_home: str | PathLike | None = None, target_column: str | List | None = 'default-target', cache: bool = True, return_X_y: bool = False, as_frame: str | bool = 'auto', n_retries: int = 3, delay: float = 1.0, parser: str = 'auto', read_csv_kwargs: Dict | None = None)[源代码]#
通过名称或数据集id从openml中获取数据集。
数据集通过整ID或名称和版本的组合唯一标识(即“iris”数据集可能有多个版本)。请提供名称或data_id(而不是两者兼而有之)。如果给出名称,也可以提供版本。
阅读更多的 User Guide .
Added in version 0.20.
备注
EXPERIMENTAL
该API是实验性的(特别是返回值结构),并且在未来的版本中可能会在没有通知或警告的情况下进行小的向后不兼容更改。
- 参数:
- name字符串,默认=无
数据集的字符串标识符。注意,OpenML可以有多个同名的数据集。
- versionint或“active”,默认=“active”
数据集的版本。只有在以下情况下才能提供
name
给出了如果“活动”,则使用仍然活动的最旧版本。由于数据集可能有多个活动版本,并且这些版本可能从根本上不同,因此强烈建议设置确切的版本。- data_idint,默认=无
数据集的OpenML ID。检索数据集的最具体方法。如果未给出data_id,则使用名称(和潜在版本)来获取数据集。
- data_home字符串或类似路径,默认值=无
为数据集指定另一个下载和缓存文件夹。默认情况下,所有scikit-learn数据都存储在“~/scikit_learn_data”收件箱中。
- target_column字符串、列表或无,默认=' default-Target '
在数据中指定要用作目标的列名。如果“default-targ目标”,则使用存储在服务器上的标准目标列a。如果
None
,所有列都作为数据返回,目标为None
.如果列表(字符串),则具有这些名称的所有列都将作为多目标返回(注意:并非所有scikit-learn分类器都可以处理所有类型的多输出组合)。- cache布尔,默认=True
是否将下载的数据集缓存到
data_home
.- return_X_y布尔,默认=假
如果为True,则返回
(data, target)
而不是Bunch对象。有关的更多信息,请参阅下文data
和target
对象- as_frame布尔或“自动”,默认=“自动”
如果为True,则数据是pandas DataFrame,包括具有适当数据类型(数字、字符串或类别)的列。目标是pandas DataFrame或Series,具体取决于目标_列的数量。The Bunch将包含
frame
具有目标和数据的属性。如果return_X_y
是真的那(data, target)
将是如上所述的pandas DataFrame或Series。如果
as_frame
是“自动”,数据和目标将转换为DataFrame或Series,就像as_frame
设置为True,除非数据集以稀疏格式存储。If
as_frame
is False, the data and target will be NumPy arrays and thedata
will only contain numerical values whenparser="liac-arff"
where the categories are provided in the attributecategories
of theBunch
instance. Whenparser="pandas"
, no ordinal encoding is made.在 0.24 版本发生变更: 的默认值
as_frame
由False
到'auto'
0.24。- n_retriesint,默认=3
遇到HTTP错误或网络超时时的重试次数。状态代码为412的错误不会被重试,因为它们代表OpenML一般错误。
- delayfloat,默认=1.0
再试之间的秒数。
- parser{“Auto”,“pandas”,“liac-arff”},默认=“Auto”
解析器用于加载ARFF文件。实现了两个解析器:
"pandas"
:这是最有效的解析器。然而,它需要安装pandas,并且只能打开密集的数据集。"liac-arff"
:这是一个纯Python ARFF解析器,其内存和MCU效率要低得多。它处理稀疏的ARFF数据集。
如果
"auto"
,自动选择解析器,"liac-arff"
为稀疏ARFF数据集选择,否则"pandas"
直接取上游Added in version 1.2.
在 1.4 版本发生变更: 的默认值
parser
变化"liac-arff"
到"auto"
.- read_csv_kwargsdict,默认=无
关键字参数传递给
pandas.read_csv
当从ARFF文件加载数据并使用pandas解析器时。它可以允许覆盖一些默认参数。Added in version 1.3.
- 返回:
- data :
Bunch
群 类似字典的对象,具有以下属性。
- 数据pp.数组、scipy.sparse.csr_浮点矩阵或pandas DataFrame
特征矩阵。类别特征被编码为顺序。
- 目标NP.数组、pandas Series或DataFrame
回归目标或分类标签(如果适用)。如果是数字型的,D类型是浮动的,如果是类别型的,D类型是对象。如果
as_frame
是真的,target
是一个熊猫物体。- DESCRstr
数据集的完整描述。
- feature_names列表
数据集列的名称。
- 目标名称:列表
目标列的名称。
Added in version 0.22.
- 类别法令或无
将每个类别特征名称映射到值列表,以便编码为i的值在列表中是ith。如果
as_frame
这是真的,这是无。- 细节dict
来自OpenML的更多元数据。
- 帧Pandas DataFrame
仅在当
as_frame=True
.数据框架data
和target
.
- (data, target) :tuple if
return_X_y
是真tuple ifreturn_X_y
is True 备注
EXPERIMENTAL
此接口 experimental 并且后续版本可能会在不通知的情况下更改属性(尽管只应该对
data
和target
).“数据”中缺失的值表示为NaN。“目标”中缺失的值表示为NaN(数字目标)或无(分类目标)。
- data :
注意到
的
"pandas"
和"liac-arff"
解析器可能会导致输出中出现不同的数据类型。显着的区别如下:的
"liac-arff"
解析器始终将分类特征编码为str
对象相反,"pandas"
解析器会在读取时推断类型,并且只要可能,数字类别就会被转换为integer。的
"liac-arff"
解析器使用float 64对元数据中标记为“REAL”和“NUMERIAL”的数字特征进行编码。的"pandas"
解析器会推断这些数字特征是否对应于整数,并使用panda的扩展dtype。特别是,具有整类类别的分类数据集通常会这样加载
(0, 1, ...)
与"pandas"
解析器,"liac-arff"
将强制使用字符串编码的类标签,例如"0"
,"1"
等的
"pandas"
解析器不会删除单引号-即'
- 来自字符串列。例如,字符串'my string'
将保持原样,"liac-arff"
解析器将删除单引号。对于类别列,单引号将从值中删除。
另外当
as_frame=False
使用时"liac-arff"
解析器返回有序编码的数据,其中类别在属性中提供categories
的Bunch
instance.相反,"pandas"
返回类别未编码的NumPy数组。示例
>>> from sklearn.datasets import fetch_openml >>> adult = fetch_openml("adult", version=2) >>> adult.frame.info() <class 'pandas.core.frame.DataFrame'> RangeIndex: 48842 entries, 0 to 48841 Data columns (total 15 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 age 48842 non-null int64 1 workclass 46043 non-null category 2 fnlwgt 48842 non-null int64 3 education 48842 non-null category 4 education-num 48842 non-null int64 5 marital-status 48842 non-null category 6 occupation 46033 non-null category 7 relationship 48842 non-null category 8 race 48842 non-null category 9 sex 48842 non-null category 10 capital-gain 48842 non-null int64 11 capital-loss 48842 non-null int64 12 hours-per-week 48842 non-null int64 13 native-country 47985 non-null category 14 class 48842 non-null category dtypes: category(9), int64(6) memory usage: 2.7 MB