如何通过scikit-learn查看MLPRegressor中的过拟合?

时间:2019-07-25 20:11:17

标签: python regression linear-regression mlp

我正在尝试将MLPRegressor用于多变量回归问题。我想知道如何在训练时看是否过度拟合吗?

我能够使用loss_curve_访问训练损失validation_scores_和验证分数,但是我希望看到类似这样的验证损失:

enter image description here

我的代码如下:

x_train = x_train[0:50000,:]
y_train = y_train[0:50000,:]
x_test = x_test[0:10000,:]
y_test = y_test[0:10000,:]
x_train = x_train[0:50000,:]
y_train = y_train[0:50000,:]
x_test = x_test[0:10000,:]
y_test = y_test[0:10000,:]

prediction=MLPRegressor(hidden_layer_sizes=(50,50), activation='relu', solver='adam', alpha=0.0001, batch_size=1000,
                    learning_rate='adaptive', learning_rate_init=0.001, power_t=0.5, max_iter=200,
                    shuffle=True, random_state=None, tol=0.0001, verbose=10, warm_start=True,
                    momentum=0.9, nesterovs_momentum=True, early_stopping=True, validation_fraction=0.2,
                    beta_1=0.9, beta_2=0.999, epsilon=1e-08, n_iter_no_change=100)



prediction.fit(x_train, y_train)

fig = plt.figure()
ax = fig.add_subplot(111)
plt.ylabel('Training Loss')
plt.xlabel('Iterations')
ax.plot(pd.DataFrame(prediction.loss_curve_))
fig.savefig('/home/sagnik/machineLearning/results/loss_curve_.png')

fig = plt.figure()
ax = fig.add_subplot(111)
plt.ylabel('Validation Score')
plt.xlabel('Iterations')
ax.plot(pd.DataFrame(prediction.validation_scores_))
fig.savefig('/home/sagnik/machineLearning/results/validation_scores_.png')

0 个答案:

没有答案