首页 > 解决方案 > 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

标签: pythontensorflowkeraslstmdata-science

解决方案


推荐阅读