问题描述
早上好, 我正尝试使用以下代码测试我的数据。我尝试在代码中使用辍学,但不幸的是,尽管训练和测试的mse值分别为0.007和0.008,但没有辍学,我的验证损失低于培训损失。
如下图所示,具有辍学的女士比没有辍学的女士还要多。
https://ibb.co/ZKxB7fL https://ibb.co/N3vpDCZ 即使我尝试将我的数据集的50%作为验证/测试集,但还是一样 我试图资助这里提到的原因: https://www.pyimagesearch.com/2019/10/14/why-is-my-validation-loss-lower-than-my-training-loss/
原因1:在训练过程中应用正则化,但在验证/测试中不应用(正常情况下,默认情况下,在验证/测试中不使用辍学) 原因2:在每个时期内测量训练损失,而在每个时期后测量验证损失 原因3:验证集可能比训练集更容易(否则可能会泄漏)
你能告诉我我该怎么办吗?
不应该使用辍学内容或您的建议吗?
X_train=174200 samples
X_test=85800
y_train=174200
y_test=85200
the code:
X = dataset[:,0:20].astype(float)
y = dataset[:,20:22]
scaler = StandardScaler()
X = scaler.fit_transform(X)
y = scaler.fit_transform(y)
# split into train test sets
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.33,random_state=1) print(X_train.shape,X_test.shape,y_train.shape,y_test.shape)
# define the keras model
model = Sequential()
model.add(Dense(20,input_dim=20,kernel_initializer=’normal’))
model.add(LeakyReLU(alpha=0.1))
#model.add(Dropout(0.2))
model.add(Dense(7,kernel_initializer=’normal’))
model.add(LeakyReLU(alpha=0.1))
#model.add(Dropout(0.2))
model.add(Dense(2,activation=’linear’))
opt = SGD(lr=0.01,momentum=0.9)
# compile the keras model
model.compile(loss=’mean_squared_error’,optimizer=opt,metrics=[‘mse’])
# fit the keras model on the dataset
history=model.fit(X,validation_data=(X_test,y_test),epochs=25,verbose=0)
# evaluate the model
_,train_mse = model.evaluate(X_train,verbose=0)
_,test_mse = model.evaluate(X_test,y_test,verbose=0)
print(‘Train: %.3f,Test: %.3f’ % (train_mse,test_mse))
#plot loss during training
pyplot.title(‘Loss / Mean Squared Error’)
pyplot.plot(history.history[‘loss’],label=’train’)
pyplot.plot(history.history[‘val_loss’],label=’test’)
pyplot.legend()
pyplot.show()'''
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)