我正在努力了解Keras的LSTM模型是如何工作的,所以我选择了Udemy课程,老师 Build 了一个带有LSTM的模型来预测Google股票价格 . 该模型非常有效,现在它是:

# Part 1 - Data Preprocessing
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the training set
training_set = pd.read_csv('Google_Stock_Price_Train.csv')
training_set = training_set.iloc[:,1:2].values

# Feature Scaling
from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler()
training_set = sc.fit_transform(training_set)

# Getting the inputs and the ouputs
X_train = training_set[0:1257]
y_train = training_set[1:1258]

# Reshaping
X_train = np.reshape(X_train, (1257, 1, 1))

# Part 2 - Building the RNN

# Importing the Keras libraries and packages
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM

# Initialising the RNN
regressor = Sequential()

# Adding the input layer and the LSTM layer
regressor.add(LSTM(units=4, activation = 'sigmoid', input_shape = (None, 1)))

# Adding the output layer
regressor.add(Dense(units = 1))

# Compiling the RNN
regressor.compile(optimizer = 'adam', loss = 'mean_squared_error')

# Fitting the RNN to the Training set
regressor.fit(X_train, y_train, batch_size = 32, epochs = 200)

# Part 3 - Making the predictions and visualising the results

# Getting the real stock price of 2017
test_set = pd.read_csv('Google_Stock_Price_Test.csv')
real_stock_price = test_set.iloc[:,1:2].values

# Getting the predicted stock price of 2017
inputs = real_stock_price
inputs = sc.transform(inputs)
inputs = np.reshape(inputs, (20, 1, 1))
predicted_stock_price = regressor.predict(inputs)
predicted_stock_price = sc.inverse_transform(predicted_stock_price)

# Visualising the results
plt.plot(real_stock_price, color = 'red', label = 'Real Google Stock Price')
plt.plot(predicted_stock_price, color = 'blue', label = 'Predicted Google Stock Price')
plt.title('Google Stock Price Prediction')
plt.xlabel('Time')
plt.ylabel('Google Stock Price')
plt.legend()
plt.show()

现在,我想将自己的数据应用于此模型,以预测一个人可能使用他们购买的历史记录购买的下一个产品 . 我在这个模型中唯一改变的是输入数据:

原始股票价格数据是每天股票的开盘价:

720,800,520,......等(一列,一个功能)

我的数据格式相同,即用户购买的产品的ID:

15,1320,680,......等(一列,一个特征)

问题是模型没有学习我的数据,损失值不会改变 . 我想知道我的数据是否有问题,或者模型是否适合我的问题?

请帮忙,抱歉我的英语 . :)

------------------------更新----------------------几个时代训练:

Epoch 1/200 12507/12507 [==============================] - 2s - 损失:0.1870
Epoch 2/200 12507/12507 [==============================] - 1s - 损失:0.0705
Epoch 3/200 12507/12507 [==============================] - 1s - 损失:0.0699
Epoch 4/200 12507/12507 [==============================] - 1s - 损失:0.0699
Epoch 5/200 12507/12507 [==============================] - 1s - 损失:0.0699
Epoch 6/200 12507/12507 [==============================] - 1s - 损失:0.0699
Epoch 7/200 12507/12507 [==============================] - 1s - 损失:0.0699
Epoch 8/200 12507/12507 [==============================] - 1s - 损失:0.0699
Epoch 9/200 12507/12507 [==============================] - 1s - 损失:0.0699