标签:nump learn mode sklearn sre near plt sha ext
from sklearn.model_selection import train_test_split X_train,X_test,y_train,y_test = train_test_split(face_up,face_down,test_size = 0.02) estimators = {‘linear‘:LinearRegression(), ‘ridge‘:Ridge(), ‘Knn‘:KNeighborsRegressor(), ‘extratree‘:ExtraTreesRegressor()} face_pred = dict() for key,estimator in estimators.items(): # 进行训练 estimator.fit(X_train,y_train) y_ = estimator.predict(X_test) # 将预测的结果保存起来 face_pred[key] = y_ import numpy as np for item in enumerate(face_pred): print(item) plt.figure(figsize=(6*3,8*3)) for i in range(8):# 6代表6列 axes = plt.subplot(8,6,i*6 + 1) face_up = X_test[i] face_down = y_test[i] face = np.concatenate([face_up,face_down]) axes.imshow(face.reshape((64,64)),cmap = ‘gray‘) plt.axis(‘off‘) if i == 0: axes.set_title(‘True Face‘) # 半脸 axes2 = plt.subplot(8,6,i*6 + 2) face_up = X_test[i] axes2.imshow(face_up.reshape((32,64)),cmap = ‘gray‘) plt.axis(‘off‘) if i == 0: axes2.set_title(‘Half Face‘) # 机器学习预测的数据 # face_pred for j,key in enumerate(face_pred): axes = plt.subplot(8,6,i*6+3+j) if i == 0: axes.set_title(key) face_up = X_test[i] y_ = face_pred[key] face_down_pred = y_[i] face = np.concatenate([face_up,face_down_pred]) axes.imshow(face.reshape((64,64)),cmap = ‘gray‘) plt.axis(‘off‘)
标签:nump learn mode sklearn sre near plt sha ext
原文地址:https://www.cnblogs.com/gugubeng/p/9803448.html