python - Keras LSTM is not learning -


i'm trying understand how keras' lstm model works took udemy course , teacher built model lstm predict google stock prices. model works , here is:

# part 1 - data preprocessing # importing libraries import numpy np import matplotlib.pyplot plt import pandas pd  # importing training set training_set = pd.read_csv('google_stock_price_train.csv') training_set = training_set.iloc[:,1:2].values  # feature scaling sklearn.preprocessing import minmaxscaler sc = minmaxscaler() training_set = sc.fit_transform(training_set)  # getting inputs , 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 rnn  # importing keras libraries , packages keras.models import sequential keras.layers import dense keras.layers import lstm  # initialising rnn regressor = sequential()  # adding input layer , lstm layer regressor.add(lstm(units=4, activation = 'sigmoid', input_shape = (none, 1)))  # adding output layer regressor.add(dense(units = 1))  # compiling rnn regressor.compile(optimizer = 'adam', loss = 'mean_squared_error')  # fitting rnn training set regressor.fit(x_train, y_train, batch_size = 32, epochs = 200)  # part 3 - making predictions , visualising results  # getting 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 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 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() 

now want apply own data model predict next product person might purchase using purchased history. thing changed in model input data:

original stock price data open price of stock day day:

720, 800, 520, ... etc (one column, 1 feature)

my data in same format, ids of product user purchased:

15, 1320, 680, ... etc (one column, 1 feature)

the problem model not learning data, loss value not change. want know if there problem data or if model not adapted problem?

please , sorry english. :)

------------------------ update ---------------------- few epochs of training:

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


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -