0

Getting error in pandas concat during testing of recurrent neural network,just trying to predict google jan 2017 stocks opening using data from 2012-2016

import numpy as np
import pandas as pd 
import matplotlib.pyplot
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense,LSTM,Dropout

dataset=pd.read_csv('C:/Users/DELL/Desktop/Deep_Learning_A_Z/Recurrent_Neural_Networks/Google_Stock_Price_Train.csv')
dataset=dataset.iloc[:,1:2].values

sc=MinMaxScaler(feature_range=(0,1))
trained=sc.fit_transform(dataset)

X_train=[]
y_train=[]
for i in range(60,1258):
    X_train.append(trained[i-60:i,0])
    y_train.append(trained[i,0])
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],1))
regressor=Sequential()

regressor.add(LSTM(units=50,return_sequences=True,input_shape=(X_train.shape[1],1)))
regressor.add(Dropout(.2))
regressor.add(LSTM(units=50,return_sequences=True))
regressor.add(Dropout(.2))
regressor.add(LSTM(units=50,return_sequences=True))
regressor.add(Dropout(.2))
regressor.add(LSTM(units=50))
regressor.add(Dropout(.2))
regressor.add(Dense(units=1))
regressor.compile(optimizer='rmsprop',loss='mean_squared_error')
regressor.fit(X_train,y_train,epochs=100,batch_size=32)

test=pd.read_csv('C:/Users/DELL/Desktop/Deep_Learning_A_Z/Recurrent_Neural_Networks/Google_Stock_Price_Test.csv')
test=test.iloc[:,1:2].values

dataset_total = pd.concat((dataset['Open'],test['Open']), axis = 0)
  • Welcome to Stackoverflow community. Please create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) for your problem so that the busy folks can have a quick look. Please search for [previously asked questions](https://stackoverflow.com/questions) having a similar problem before asking a new question. [Similar Question](https://stackoverflow.com/questions/34952651/only-integers-slices-ellipsis-numpy-newaxis-none-and-intege) – Light_B Apr 02 '20 at 09:54

1 Answers1

0
test=test.iloc[:,1:2].values

With values test is a numpy array.

test['Open']

Indexing that with a string like 'Open'` is wrong, hence the error.

Same is true for dataset.

hpaulj
  • 221,503
  • 14
  • 230
  • 353