码迷,mamicode.com
首页 > 编程语言 > 详细

机器学习(二) 字典使用算法比较

时间:2018-10-17 14:37:06      阅读:158      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!