I am interested to use multivariate regression with LSTM (Long Short Term Memory). As an example, we can take the stock price prediction problem, where the price at time t is based on multiple factors (open price, closed price, etc.). Using this information we need to predict the price for t+1. Another example can be the house price prediction (which depends on factors like, age of house, area, no. of beds, no. of baths, etc). Using this information, we can predict the price of a given house.

I have found many examples where they just used a single variable regression, but I am interested to use multiple features.

Has anyone tried this and can anyone point out the right direction for this?

I tried the following but have no idea if this is the efficient way.

# Importing the training set
training_set = pd.read_csv('Google_Stock_Price_Train.csv').iloc[:,1:3].values#has fields: Date,Open,High,Low,Close,Volume
# Feature Scaling
from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler()
training_set_scaled = sc.fit_transform(training_set)
X_train = training_set_scaled[0:1257]
y_train = training_set_scaled[1:1258]
# Reshaping
X_train = np.reshape(X_train, (1257, 1, 2))
X_train, y_train = np.array(X_train), np.array(y_train)
X_train = np.reshape(X_train, (X_train.shape[0], X_train.shape[1], 2))
from keras.models import Sequential
from keras.layers import Dense, LSTM
regressor = Sequential()
regressor.add(LSTM(units = 4, activation = 'sigmoid', input_shape = (None, 2)))
regressor.add(Dense(units = 2))
regressor.compile(optimizer = 'rmsprop', loss = 'mean_squared_error')
regressor.fit(X_train, y_train, batch_size = 32, epochs = 100)


  • $\begingroup$ the sample data in Google_Stock_Price_Train.csv is : 1/3/2012,325.25,332.83,324.97,663.59,"7,380,500" 1/4/2012,331.27,333.87,329.08,666.45,"5,749,400" 1/5/2012,329.83,330.75,326.89,657.21,"6,590,300" 1/6/2012,328.34,328.77,323.68,648.24,"5,405,900" 1/9/2012,322.04,322.29,309.46,620.76,"11,688,800" 1/10/2012,313.7,315.72,307.3,621.43,"8,824,000" 1/11/2012,310.59,313.52,309.4,624.25,"4,817,800" 1/12/2012,314.43,315.26,312.08,627.92,"3,764,400" 1/13/2012,311.96,312.3,309.37,623.28,"4,631,800" 1/17/2012,314.81,314.81,311.67,626.86,"3,832,800" $\endgroup$
    – Ramesh
    Jun 28, 2017 at 16:45

2 Answers 2


Here's a great example for Multivariate Regression using LSTM:


Most Examples you will find will be for time-series prediction using LSTM, like the one you listed for Stock Prices.


Here is the elegant research paper with the python implementation of multivariate regression using GRU, LSTM, and GAN for stock prediction:



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.