我使用线性回归建立了ML模型,但遇到了问题。这是我的结果值
Model1训练均方误差:154.96
[Model1测试均方误差:72018955075415565139968.00
培训分数:0.48
测试分数:-236446352571492139008.00
我不知道为什么打印这些值因为过度拟合?
我正在使用tensorflow 1.13.1
和python 3.7
Overfitting
似乎是这种情况。
您可以
Missing Value Imputation
2.Fixing the Outliers
3. Scaling
或Normalizing
功能Feature Engineering
(删除不需要的功能,添加有意义的功能)Shuffle
数据,通过使用shuffle=True
中的model.fit
。代码如下所示:history = cnn_model.fit(x = X_train_reshaped,
y = y_train,
batch_size = 512,
epochs = epochs, callbacks=[callback],
verbose = 1, validation_data = (X_test_reshaped, y_test),
validation_steps = 10, steps_per_epoch=steps_per_epoch,
shuffle = True)
使用Early Stopping
。代码如下所示
callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=15)
使用Dropout
Regularization
。 Regularization
的代码如下所示(您也可以尝试l1 Regularization
或l1_l2 Regularization
):`从tensorflow.keras.regularizers导入l2
Regularizer = l2(0.001)
model.add(tf.keras.layers.Dense(
units = 64, activation='relu', kernel_regularizer=Regularizer, bias_regularizer=Regularizer,
activity_regularizer=Regularizer))
tf.keras.layers(Dropout(0.4))
model.add(Dense(units = 10, activation = 'sigmoid',
activity_regularizer=Regularizer, kernel_regularizer=Regularizer))`
Layers
,因为它会减少可训练参数的数量希望这会有所帮助。祝您学习愉快!