fetch_lfw_pairs#

sklearn.datasets.fetch_lfw_pairs(*, subset='train', data_home=None, funneled=True, resize=0.5, color=False, slice_=(slice(70, 195, None), slice(78, 172, None)), download_if_missing=True, n_retries=3, delay=1.0)[source]#

加载 Labeled Faces in the Wild (LFW) 对数据集(分类)。

Download it if necessary.

类别数

2

样本总数

13233

维度

5828

特征值范围

实数,介于 0 和 255 之间

原始论文中,“配对”(pairs)版本对应于“受限任务”(restricted task),在该任务中,实验者不应使用人的姓名来推断训练集中未明确给出的两张人脸图像是否等价。

原始图像大小为 250 x 250 像素,但默认的切片(slice)和调整大小(resize)参数将其缩减为 62 x 47。

用户指南 中了解更多信息。

参数:
subset{‘train’, ‘test’, ‘10_folds’}, default=’train’

选择要加载的数据集:“train”为开发训练集,“test”为开发测试集,“10_folds”为用于 10 折交叉验证的官方评估集。

data_homestr or path-like, default=None

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

funneledbool, default=True

下载并使用该数据集的校准(funneled)版本。

resizefloat, default=0.5

用于调整每张人脸图像大小的比例。

colorbool, default=False

保留 3 个 RGB 通道,而不是将其平均为单个灰度通道。如果 color 为 True,则数据的形状比 color = False 时的形状多一个维度。

slice_tuple of slice, default=(slice(70, 195), slice(78, 172))

提供自定义的 2D 切片(高度, 宽度)以提取 jpeg 文件中的“感兴趣”区域,并避免使用背景中的统计相关性。

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.

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 版本新增。

返回:
dataBunch

Dictionary-like object, with the following attributes.

datandarray, 形状为 (2200, 5828)。形状取决于 subset

每一行对应 2 张展平(ravel'd)的人脸图像,原始大小为 62 x 47 像素。更改 slice_resizesubset 参数将改变输出的形状。

pairsndarray, 形状为 (2200, 2, 62, 47)。形状取决于 subset

每一行包含 2 张人脸图像,对应于包含 5749 个人的数据集中相同或不同的人。更改 slice_resizesubset 参数将改变输出的形状。

targetnumpy array, 形状为 (2200,)。形状取决于 subset

与每对图像关联的标签。两个标签值分别为“不同的人”或“同一个人”。

target_namesnumpy array, 形状为 (2,)

解释 target 数组中的目标值。0 对应“不同的人”,1 对应“同一个人”。

DESCRstr

Labeled Faces in the Wild (LFW) 数据集的描述。

示例

>>> from sklearn.datasets import fetch_lfw_pairs
>>> lfw_pairs_train = fetch_lfw_pairs(subset='train')
>>> list(lfw_pairs_train.target_names)
[np.str_('Different persons'), np.str_('Same person')]
>>> lfw_pairs_train.pairs.shape
(2200, 2, 62, 47)
>>> lfw_pairs_train.data.shape
(2200, 5828)
>>> lfw_pairs_train.target.shape
(2200,)