Stitched Seminoles Winston 5 Jameis Jersey Limited Red College

This example shows the use of multi-output estimator to complete images. The goal is to predict the lower half of a face given its upper half.

The first column of images shows true faces. The next columns illustrate how extremely randomized trees, k nearest neighbors, linear regression and ridge regression complete the lower half of those faces.

Stitched Seminoles Winston 5 Jameis Jersey Limited Red Out:

downloading Olivetti faces from https://ndownloader.figshare.com/files/5976027 to /home/circleci/scikit_learn_data

print(__doc__)

import numpy as np
import matplotlib.pyplot as plt

from sklearn.datasets import fetch_olivetti_faces
from sklearn.utils.validation import check_random_state

from sklearn.ensemble import ExtraTreesRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model Stitched Seminoles Winston 5 Jameis Jersey Limited Red import LinearRegression
from sklearn.linear_model import RidgeCV

# Load the faces datasets
data = fetch_olivetti_faces()
targets = data.target

data = data.images.reshape((len(data.images), -1))
train = data[targets < 30]
test = data[targets >= Stitched Seminoles Winston 5 Jameis Jersey Limited Red 30Stitched Seminoles Winston 5 Jameis Jersey Limited Red ]  # Test on independent people

# Test on a subset of people
n_faces = 5
rng = check_random_state(4)
face_ids = rng.randintStitched Seminoles Winston 5 Jameis Jersey Limited Red (test.shape[0], size=(n_faces, ))
test = test[face_ids, :]

n_pixels = data.shape[1]
# Upper half of the faces
Stitched Seminoles Winston 5 Jameis Jersey Limited Red X_train = trainStitched Seminoles Winston 5 Jameis Jersey Limited Red [:, :(n_pixels + 1) // 2]
# Lower half of the faces
y_train = train[:, n_pixels // 2:]
Stitched Seminoles Winston 5 Jameis Jersey Limited Red X_test = test[:, :(n_pixels + 1) // 2]
y_test = test[:, n_pixels // 2:]

# Fit estimators
ESTIMATORS = {
    "Extra trees": Stitched Seminoles Winston 5 Jameis Jersey Limited Red ExtraTreesRegressor(n_estimators=10, max_features=32,
                                       random_state=0),
    "K-nn": KNeighborsRegressor(),
    "Linear regression": Stitched Seminoles Winston 5 Jameis Jersey Limited Red LinearRegression(),
    "Ridge": RidgeCV(),
}

y_test_predict = dict()
for name, estimator in ESTIMATORS.items():
    estimator.fit(X_train, y_train)
    y_test_predict[name] = estimator.predict(X_test)

# Plot the completed faces
image_shape = (64, 64)

n_cols = 1 + len(ESTIMATORS)
plt.figure(figsize=(2. * n_cols, 2.26 * n_faces))
Camo Tigers 14 Stewart Base Collection Stitched Jersey Realtree Cool Christin Baseball("Face completion with multi-output estimators", size=16)

for i in range(n_faces):
    true_face =Bluejays College Stitched Doug Basketball 3 Mcdermott Light Blue Jersey np.hstack((X_test[i], y_test[i]))

    if i:
        sub = plt.subplot(n_faces, n_cols, i * n_cols + 1)
    else:
        sub = plt.subplot(n_faces, n_cols, i * n_cols + 1,
                          title="true faces")

    sub.axis("off")
    sub.imshow(true_face98 Brian Jersey Orakpo Longhorns College Stitched Orange.reshape(image_shape),
               cmap=plt.cm.gray,
               interpolationStitched Seminoles Winston 5 Jameis Jersey Limited Red ="nearest")

    for j, est in enumerate(sorted(ESTIMATORS)):
        completed_face = np.hstack((X_test[i], y_test_predict[est][Stitched Seminoles Winston 5 Jameis Jersey Limited Red i]))

        if i:
            sub = plt.subplot(n_faces, n_cols, i * n_cols + 2 + j)

        else:
            sub = plt.subplot(n_faces, n_cols, i * n_cols7 Murray College Jersey Red Sooners Demarco Stitched + 2 Stitched Seminoles Winston 5 Jameis Jersey Limited Red + j,
                              title=est)

        sub.axis("off")
        sub.imshow(completed_face.reshape(image_shape),
                   cmap=plt.cm.gray,
                   interpolation="nearest")

plt.show()

Total running time of the script: ( 0 minutes 3.749 seconds)

Gallery generated by Sphinx-Gallery