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])
完美解決!