python - Keras 模型预测错误值(精度:0.0000e+00)
问题描述
陈词滥调“这是我的第一个 Keras 项目”,但唉,这就是事实。我提前为任何畏缩的初学者错误道歉。
数据设置如何
A 列:我们以 24 小时时间格式记录给定火车的出发时间。
B 列:给定火车目的地的整数表示。前加利福尼亚 == 2,纽约 == 0
C 列:分配给给定火车的轨道。
目标
通过使用这些数据,我们可以使用时间和位置来预测轨道编号。
当前尝试
# multivariate one step problem
from numpy import array
from numpy import hstack
from numpy import insert
from numpy import zeros,newaxis
from numpy import reshape
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import LSTM
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing.sequence import TimeseriesGenerator
import pandas as pd
file_name = "DATA_DUMP.csv"
destination = 0
departure = 1622
#extract values
raw_data = pd.read_csv(file_name)
data = raw_data
in_seq1 = array([data['TIME'].values])
in_seq2 = array([data['LOCATION'].values])
result = array([data['TRACK'][0:-1].values])
# reshape series
in_seq1 = in_seq1.reshape((in_seq1.shape[1],len(in_seq1)))
in_seq2 = in_seq2.reshape((in_seq2.shape[1],len(in_seq2)))
result = result.reshape((result.shape[1],len(result)))
dataset = hstack((in_seq1, in_seq2))
result = insert(result,0,0)
result = result.reshape((len(result),1))
# define generator
n_features = dataset.shape[1]
n_input = 1
generator = TimeseriesGenerator(dataset, result, length=n_input, batch_size=1)
for i in range(len(generator)):
x, y = generator[i]
print('%s => %s' % (x, y))
# define model
model = Sequential()
model.add(LSTM(100, activation='sigmoid', input_shape=(n_input, n_features)))
model.add(Dense(1))
model.compile(optimizer=Adam(lr=0.00001), loss='mse',metrics=['accuracy'])
# fit model
model.fit_generator(generator, steps_per_epoch=1, epochs=500, verbose=2)
# make a one step prediction out of sample
raw_array = array([1507,3]) #predict arrival at 15:07 destination 3, what track will it be?
x_input = array(raw_array).reshape((1,n_input,n_features))
yhat = model.predict(x_input, verbose=1)
print(yhat)
问题
尽管我的代码运行,但我得到的预测非常不准确。我假设这是由于我的巨大损失。非常感谢您在启动和运行此模型方面提供的任何帮助。
Epoch 500/500
1/1 - 0s - loss: 424.2032 - accuracy: 0.0000e+00
解决方案
推荐阅读
- r - dplyr 函数用于合并重复数据、删除缺失数据和维护冲突数据
- python - 如何将分类器和 lambda 修复为 TextBlob
- javascript - 如何使用 AJAX 发送来自?
- css - 无法在 adminlte 中滚动控制侧边栏
- html - 浮动左元素和浮动右元素被标题(chrome)向上推
- java - 调用 init 方法失败;嵌套异常是 java.lang.ClassCastException:java.time.LocalDateTime 不能转换为 java.lang.String
- python - 尝试通过 ansible 任务在 SQL Server 上创建数据库时 pymssql 出现分段错误
- mongodb - Mongodb文本搜索(精确匹配、模糊匹配)
- javascript - 同步 iframe
- r - 如何在R中的同一图中将线图和箱线图与显着差异结合起来