python - 获得更高损失和 val_loss 的原因是什么?
问题描述
我已经编码了神经网络。
数据集如下:
aqi timestamp junctionid Dates Time Day
0 94 2014-08-01 00:05:00 1 2014-08-01 5 0
1 90 2014-08-01 00:10:00 1 2014-08-01 10 0
2 85 2014-08-01 00:15:00 1 2014-08-01 15 0
3 85 2014-08-01 00:20:00 1 2014-08-01 20 0
4 84 2014-08-01 00:25:00 1 2014-08-01 25 0
... ... ... ... ... ... ...
95 95 2014-08-01 08:00:00 1 2014-08-01 480 0
96 90 2014-08-01 08:05:00 1 2014-08-01 485 0
97 91 2014-08-01 08:10:00 1 2014-08-01 490 0
98 92 2014-08-01 08:15:00 1 2014-08-01 495 0
99 96 2014-08-01 08:20:00 1 2014-08-01 500 0
代码 :
Y = dataset[['aqi']]
X = dataset[['Day','Time','junctionid']]
X_scale =X
# normalize the dataset
scaler = MinMaxScaler(feature_range=(0, 0.99))
Y = scaler.fit_transform(Y['aqi'].values.reshape(-1, 1))
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
X_train, X_val_and_test, Y_train, Y_val_and_test = train_test_split(X_scale, Y, test_size=0.3)
X_val, X_test, Y_val, Y_test = train_test_split(X_val_and_test, Y_val_and_test, test_size=0.5)
print(X_train.shape, X_val.shape, X_test.shape, Y_train.shape, Y_val.shape, Y_test.shape)
from keras.models import Sequential
from keras.layers import Dense
model = Sequential([
Dense(32, activation='relu', input_shape=(3,)),
Dense(32, activation='relu'),
Dense(1, activation='sigmoid'),
])
history = model.compile(loss='mean_squared_error', optimizer='adam')
hist = model.fit(X_train, Y_train,
batch_size=70, epochs=5,
validation_data=(X_val, Y_val))
损失的原因是什么:0.0369 - val_loss: 0.0368?
解决方案
损失将是训练数据集中所有数据之间的均方误差。验证数据集不同,不用作训练的一部分。验证是指在训练集中未包含的数据上测试网络,以确保网络能够泛化到所有数据并且不会过度拟合训练集。
在预测验证数据时,网络权重可能已经优化到更准确的程度。这是偶然的,在您的示例中,差异通常非常小。
推荐阅读
- tensorflow - keras 自定义层加载数据
- prolog - 如何在不使用 findall 的情况下创建列表?序言
- django - django从shell中的一对多模型关系中检索所有对象
- wordpress - 使用 Wordpress REST API 获取帖子缩略图
- c - 如何使用 C 语言将目录从一个地方复制到另一个地方?
- r - partykit:修改终端节点以包括回归量的标准差和显着性
- python - Pathlib 仅通过子目录循环
- c++ - 如何在 ARM ELF 文件中找到函数内存映射?
- python - 生成代码时的错误消息 - selenium 和 python 类型错误
- azure - Octopus Deploy:操作返回了无效的状态代码“冲突”