text_plain_output_1.png
from sklearn.ensemble import ExtraTreesRegressor

from sklearn.ensemble import RandomForestRegressor

from sklearn.linear_model import LinearRegression

from sklearn.linear_model import RidgeCV

from sklearn.neighbors import KNeighborsRegressor

import numpy as np

images = np.load('../input/olivetti_faces.npy')
images.shape

targets = np.load('../input/olivetti_faces_target.npy')
targets.shape

data = images.reshape(images.shape[0], images.shape[1] * images.shape[2])
data.shape

train = data[targets < 30]
train.shape

test = data[targets >= 30]
test.shape

n_faces = test.shape[0] // 10
n_faces

face_ids = np.random.randint(0, 100, size=n_faces)
face_ids

test = test[face_ids, :]
test.shape

n_pixels = data.shape[1]
n_pixels

X_train = train[:, :(n_pixels + 1) // 2]
X_train

y_train = train[:, n_pixels // 2:]
y_train

X_test = test[:, :(n_pixels + 1) // 2]
y_test = test[:, n_pixels // 2:]
ESTIMATORS = {'Extra trees': ExtraTreesRegressor(n_estimators=10, max_features=32, random_state=0), 'K-nn': KNeighborsRegressor(), 'Linear regression': LinearRegression(), 'Ridge': RidgeCV(), 'RandomForestRegressor': RandomForestRegressor()}
y_test_predict = dict()
for name, estimator in ESTIMATORS.items():
    estimator.fit(X_train, y_train)
    y_test_predict[name] = estimator.predict(X_test)
y_test_predict['RandomForestRegressor'].shape