8000 DOC: Use notebook-style plot_dict_face_patches.py by teunpe · Pull Request #22929 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

DOC: Use notebook-style plot_dict_face_patches.py #22929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions examples/cluster/plot_dict_face_patches.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Online learning of a dictionary of parts of faces
==================================================
=================================================

This example uses a large dataset of faces to learn a set of 20 x 20
images patches that constitute faces.
Expand All @@ -21,20 +21,24 @@

"""

import time

import matplotlib.pyplot as plt
import numpy as np

# %%
# Load the data
# -------------

from sklearn import datasets
from sklearn.cluster import MiniBatchKMeans
from sklearn.feature_extraction.image import extract_patches_2d

faces = datasets.fetch_olivetti_faces()

# #############################################################################
# %%
# Learn the dictionary of images
# ------------------------------

import time

import numpy as np

from sklearn.cluster import MiniBatchKMeans
from sklearn.feature_extraction.image import extract_patches_2d

print("Learning the dictionary... ")
rng = np.random.RandomState(0)
Expand Down Expand Up @@ -64,8 +68,12 @@
dt = time.time() - t0
print("done in %.2fs." % dt)

# #############################################################################
# %%
# Plot the results
# ----------------

import matplotlib.pyplot as plt

plt.figure(figsize=(4.2, 4))
for i, patch in enumerate(kmeans.cluster_centers_):
plt.subplot(9, 9, i + 1)
Expand Down
0