<jupyter_start><jupyter_text>特征脸<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import fetch_lfw_people
faces = fetch_lfw_people()
faces
faces.keys()
faces.data.shape
faces.images.shape
random_indexes = np.random.permutation(len(faces.data))
X = faces.data[random_indexes]
example_faces = X[:36, :]
example_faces.shape
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')
    plt.show()
plot_faces(example_faces)
faces.target_names
len(faces.target_names)<jupyter_output><empty_output><jupyter_text>特征脸<jupyter_code>%%time
from sklearn.decomposition import PCA
pca = PCA(svd_solver='randomized')
pca.fit(X)
pca.components_.shape
plot_faces(pca.components_[:36, :])
faces2 = fetch_lfw_people(min_faces_per_person=60)
faces2.data.shape
faces2.target_names
len(faces2.target_names)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1321266968325792, 'fraction_numerical': 0.02171945701357466, 'mean_word_length': 5.144444444444445, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '6283', 'license': 'Apache-2.0', 'n_tokens_mistral': 436, 'n_tokens_neox': 419, 'n_words': 64, 'path': 'data-science/scikit-learn/05/05-Eigenface.ipynb', 'repo_name': 'le3t/ko-repo', 'size': '1105'}