1、因为要下载的数据过大,运行缓慢,或者直接就报错:可手动下载数据解压至C:\Users\Administrator\scikit_learn_data\lfw_home 路径。
对每一张图片而言完整的路径是:"C:\Users\Administrator\scikit_learn_data\lfw_home\lfw_funneled\Aaron_Eckhart\Aaron_Eckhart_0001.jpg"
数据资源下载连接为:https://www.cnblogs.com/shanger/articles/11901085.html
2、修改为如下的代码运行:
from sklearn.datasets import fetch_lfw_people people = fetch_lfw_people(min_faces_per_person=20, resize=0.7, download_if_missing=False)
如果提示缺少
之一
点击下载:https://www.cnblogs.com/shanger/articles/11901085.html
并存入 C:\Users\Administrator\scikit_learn_data\lfw_home 路径
3、再次运行
from sklearn.datasets import fetch_lfw_people people = fetch_lfw_people(min_faces_per_person=20, resize=0.7, download_if_missing=False)
应该不会报错了。
4、显示图片
image_shape = people.images[0].shape import matplotlib.pyplot as plt %matplotlib notebook fig, axes = plt.subplots(2, 5, figsize=(18, 5), subplot_kw={'xticks': (), 'yticks':()}) for target, image, ax in zip(people.target, people.images, axes.ravel()): ax.imshow(image) ax.set_title(people.target_names[target])
完美解决!