Jupyter Notebook
特征脸
import numpy as np
from matplotlib import pyplot as plt
fetch_lfw_people
from sklearn.datasets import fetch_lfw_people
faces = fetch_lfw_people()
print(faces.keys())
dict_keys(['data', 'images', 'target', 'target_names', 'DESCR'])
faces.data.shape
(13233, 2914)
faces.images.shape
(13233, 62, 47)
random_indexes = np.random.permutation(len(faces.data))
X = faces.data[random_indexes]
example_faces = X[:36,:]
example_faces.shape
(36, 2914)
#绘制脸的函数
def plot_faces(faces):
fig, axes = plt.subplots(6, 6, figsize=(10, 10),
subplot_kw={'xticks':[], 'yticks':[]},
gridspec_kw=dict(hspace=0.1, wspace=0.1))
for i, ax in enumerate(axes.flat):
ax.imshow(faces[i].reshape(62,47), cmap='bone')
plot_faces(example_faces)
注:如果用
from sklearn.datasets import fetch_lfw_people
faces = fetch_lfw_people()
出错,则参考:https://blog.csdn.net/pyufftj/article/details/79756327