在用MLPR预测相关数据时,刚开始正常。但当运行多次时,图像变成另张图所示的一行一行的结果。重启内核运行后恢复,这是为什么呢?这样的预测是否有问题
利用GBRT模型预测时也会得到类似的情况
# building the model
regr_1 =MLPRegressor(activation='identity',solver='lbfgs',hidden_layer_sizes=(21,),max_iter=5000,random_state=0)
scores = cross_val_score (regr_1, X_train, y_train, cv=10, scoring='neg_mean_squared_error', n_jobs = -1)
# training the model
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
regr_1.fit(X_train, y_train)
# predicting the results
Z1 = regr_1.predict(X_train)
Z2 = regr_1.predict(X_test)
print("Training R2:", r2_score(y_train, Z1), "RMSE:", np.sqrt(mean_squared_error(y_train, Z1)),
"MAE:", mean_absolute_error(y_train, Z1), "MAPE:", MAPE(y_train, Z1))
print("Testing R2:", r2_score(y_test, Z2), "RMSE:", np.sqrt(mean_squared_error(y_test, Z2)),
"MAE:", mean_absolute_error(y_test, Z2), "MAPE:", MAPE(y_test, Z2))
# plotting the scatter for the training and testing sets
import matplotlib.pyplot as plt
xx = np.linspace(0, 0.003)
yy = xx
plt.figure(figsize=(12,8))
plt.plot(xx, yy, c='k', linewidth=2)
plt.scatter(y_train, Z1, marker='s')
plt.scatter(y_test, Z2, marker='o')
plt.grid()
plt.legend(['y=x', '训练集', '测试集'], loc = 'upper left', fontsize=35)
plt.tick_params (axis = 'both', which = 'major')
plt.axis('tight')
plt.xlabel('计算最大位移角 ', fontsize=35)
plt.ylabel('预测最大位移角', fontsize=35)
plt.tick_params(labelsize=30)
plt.tick_params(labelsize=30)
plt.title('MLPR',fontsize=35,fontproperties='Times New Roman')
plt.tight_layout()