Finishing Up Persons Using Machine Learning

 3r3119. 3r3-31. This example shows the use of various machine learning algorithms to complete images. The goal is to predict the lower half of the face, given its upper half.
 3r3119. The first column of images shows real faces. The following columns illustrate how trees (extremely randomized trees), the k-nearest neighbor method (k nearest neighbors /K-nn), linear regression (linear regression) and RidgeCV (ridge regression complete) complete the bottom half of these individuals.
 3r3119. Finishing Up Persons Using Machine Learning  3r3119. 3r311.
3r318. # We connect libraries
import numpy as np
import matplotlib.pyplot as plt
3r3119. from sklearn.datasets import fetch_olivetti_faces
from sklearn.utils.validation import check_random_state
3r3119. from sklearn.ensemble import ExtraTreesRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import RidgeCV
3r3119. # Load the datasets
data = fetch_olivetti_faces ()
targets =
3r3119. data = data.images.reshape ((len (data.images), -1))
train = data[targets < 30]3r3119. test = data[targets >= 30]# Test on independent people
3r3119. # Test for a subset of people
n_faces = 5
rng = check_random_state (4)
face_ids = rng.randint (test.shape[0], size = (n_faces,))
test = test[face_ids, :]3r3119. 3r3119. n_pixels = data.shape[1]3r3119. # Top half faces
X_train = train[:, :(n_pixels + 1) //2]3r3119. # Lower half of faces
y_train = train[:, n_pixels //2:]3r3119. X_test = test[:, :(n_pixels + 1) //2]3r3119. y_test = test[:, n_pixels //2:]3r3119. 3r3119. # We define methods
"Extra trees": ExtraTreesRegressor (n_estimators = 1? max_features = 3?
Random_state = 0),
"K-nn": KNeighborsRegressor (), 3r3119. "Linear regression": LinearRegression (),
"Ridge": RidgeCV (),
3r3119. y_test_predict = dict ()
for name, estimator in ESTIMATORS.items (): (X_train, y_train)
y_test_predict[name]= estimator.predict (X_test)
3r3119. # Visualization
image_shape = (6? 64)
3r3119. n_cols = 1 + len (ESTIMATORS)
plt.figure (figsize = (2. * n_cols, ??? * n_faces))
plt.suptitle ("Completing Images with Various Machine Learning Algorithms," size = 16)
3r3119. for i in range (n_faces):
true_face = np.hstack ((X_test[i], y_test[i]))
3r3119. if i:
sub = plt.subplot (n_faces, n_cols, i * n_cols + 1)
sub = plt.subplot (n_faces, n_cols, i * n_cols + ?
title = "true faces")
3r3119. sub.axis ("off")
sub.imshow (true_face.reshape (image_shape),
cmap =,
interpolation = "nearest")
3r3119. for j, est in enumerate (sorted (ESTIMATORS)):
completed_face = np.hstack ((X_test[i], y_test_predict[est] [i]))
3r3119. if i:
sub = plt.subplot (n_faces, n_cols, i * n_cols + 2 + j)
3r3119. else:
sub = plt.subplot (n_faces, n_cols, i * n_cols + 2 + j,
title = est)
3r3119. sub.axis ("off")
sub.imshow (completed_face.reshape (image_shape),
cmap =,
interpolation = "nearest")
3r3119. ()
3r3104. 3r3105.
 3r3119. 3r3108. 3r3115. 3r3119. 3r3119. 3r33112. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e.opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d ): d ()}}} t ("//"""_mediator") () (); 3r3113. 3r3119. 3r3115. 3r3119. 3r3119. 3r3119. 3r3119.
+ 0 -

Comments 4

Good web hosting
Good web hosting 10 May 2019 09:16
As soon as I  detected  this website   I went on reddit to share some of the love with them. Good web hosting
sports betting Malaysia
sports betting Malaysia 15 May 2019 14:43
[hide][/hide]for yet  another great informative article, I’m a loyal reader to this blog and I  can’t say how much valuable information I’ve learned from reading your  content. I really appreciate all the hard work you put into this great blog.  sports betting Malaysia
UTME Past Question and Answers
UTME Past Question and Answers 18 May 2019 13:42
Valuable information. Lucky me I found your site by accident, and I am shocked why this accident did not happened earlier! I bookmarked it. UTME Past Question and Answers

Wow! This could be one particular of the most beneficial blogs We’ve ever arrive across on this subject. Actually Wonderful. I’m also an expert in this topic so I can understand your effort.
18mm dab nail
tati Today, 13:22
Good post. I study one thing tougher on totally different blogs everyday. It can all the time be stimulating to learn content from different writers and observe a bit of something from their store. I’d favor to use some with the content material on my weblog whether or not you don’t mind. Natually I’ll offer you a link on your web blog. Thanks for sharing. Danbury Chiropractic and Wellness - Facebook

It’s perfect time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I want to suggest you some interesting things or suggestions. Perhaps you can write next articles referring to this article. I wish to read more things about it!Sahara occidental

Add comment