预测数据
# 预测所有数据 knn_y_ = knn.predict(X_test) linear_y_ = linear.predict(X_test) ridge_y_ = ridge.predict(X_test) lasso_y_ = lasso.predict(X_test) plt.figure(figsize=(10,4)) true_up_face = X_test[0] true_bottom_face = y_test[0] pre_bottom_face = knn_y_[0] axes1 = plt.subplot(1,2,1) true_face = np.concatenate((true_up_face,true_bottom_face)) axes1.imshow(true_face.reshape((64,64)),cmap='gray') axes1.set_title('True') axes2 = plt.subplot(1,2,2) pre_face = np.concatenate((true_up_face,pre_bottom_face)) axes2.imshow(pre_face.reshape((64,64)),cmap='gray') axes2.set_title('Predict') results = np.array([knn_y_,ridge_y_,lasso_y_,linear_y_]) titles = np.array(['KNN','RIDGE','LASSO','LINEAR']) plt.figure(figsize=(16,18)) for i in range(5): true_up_face = X_test[i] true_bottom_face = y_test[i] true_face = np.concatenate((true_up_face,true_bottom_face)).reshape((64,64)) axes = plt.subplot(5,5,i*5+1) axes.imshow(true_face,cmap='gray') axes.set_title('True') for index,y_ in enumerate(results): axes = plt.subplot(5,5,i*5+1+index+1) pre_bottom_face = y_[index] pre_face = np.concatenate((true_up_face,pre_bottom_face)).reshape((64,64)) axes.imshow(pre_face,cmap='gray') axes.set_title(titles[index])数据量较少,仅为测试使用