1 导入需要的类库
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression,Ridge,Lasso
from sklearn.tree import DecisionTreeRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
import numpy as np
2拉取数据集
faces=datasets.fetch_olivetti_faces()
images=faces.images
display(images.shape)
index=np.random.randint(0,400,size=1)[0]
img=images[index]
plt.figure(figsize=(3,3))
plt.imshow(img,cmap=plt.cm.gray)
3 处理图片数据(将人脸图片分为上下两部分)
index=np.random.randint(0,400,size=1)[0]
up_face=images[:,:32,:]
down_face=images[:,32:,:]
axes=plt.subplot(1,3,1)
axes.imshow(up_face[index