机器学习 字典使用算法比较
Posted gugubeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了机器学习 字典使用算法比较相关的知识,希望对你有一定的参考价值。
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‘)
以上是关于机器学习 字典使用算法比较的主要内容,如果未能解决你的问题,请参考以下文章