Keras模型预测错误值(精度:0.0000e + 00)

时间:2019-03-20 05:56:51

标签: python tensorflow keras lstm data-science

陈词滥调“这是我的第一个Keras项目”,可惜,这是事实。对于任何严重的初学者错误,我深表歉意。

数据设置如何

A列:我们以24小时时间格式记录给定火车的发车时间。

B列:给定火车目的地的整数表示。 EX加利福尼亚== 2,纽约== 0

列C:分配给给定火车的轨道。

Screenshot of data setup

目标

通过使用这些数据,我们可以使用时间和位置来预测轨道号。

当前尝试

# 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

0 个答案:

没有答案
相关问题