How to transfrom back from the MinMaxScaler?

When I use the lstm to predict stock, I totally succeed to predict something.But, When I use the inverse_transform to make the number of predictions become normal from MinMaxScaler, it shows me error.

import pandas as pd
import numpy as np
import datetime as datetime
import pandas_datareader as pdr

start = datetime.datetime(2015,6,29)
end = datetime.datetime(2018,6,29)
df_2330 = pdr.DataReader("2330.TW", 'yahoo', start=start,end=end)
data = df_2330.drop(['Adj Close'],axis=1)
change = data.Close.diff()
data['Change'] = change
change.fillna(change.mean(),inplace=True)
data['RD'] = data.Close.pct_change()*100
data = data.dropna(axis=0,how='any')
df = data.drop(['Change'],axis=1)
train = df[0:491]
test = df[491:]

from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
train = pd.DataFrame(scaler.fit_transform(train), columns=df.columns)
test = pd.DataFrame(scaler.fit_transform(test), columns=df.columns)

import tqdm
n = 30 
feature_names = list(train.drop('RD', axis=1).columns)
X = []
y = []
indexes = []
norm_data_x = train[feature_names]
for i in tqdm.tqdm_notebook(range(0,len(train)-n)): 
    X.append(norm_data_x.iloc[i:i+n]. values) 
    y.append(train['RD'].iloc[i+n-1]) 
    indexes.append(train.index[i+n-1]) 
X=np.array(X) 
y=np.array(y)

import keras
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Dropout

n_steps = 30 
n_features = 5
model = Sequential()
model.add(LSTM(50,activation='relu', return_sequences=True, input_shape = (n_steps, n_features)))
model.add(Dropout(0.2))
model.add(LSTM(units = 50,activation='relu',return_sequences = True))
model.add(Dropout(0.2))
model.add(LSTM(units = 50, return_sequences = True))
model.add(Dropout(0.2))
model.add(LSTM(units = 50))
model.add(Dropout(0.2))
model.add(Dense(units = 1))
model.add(Dense(1))
model.compile(optimizer = 'adam', loss = 'mse' , metrics=['mse','mape'])
history = model.fit(X,y,batch_size=32,epochs=20)

import tqdm
n = 30
feature_names = list(test.drop('RD', axis=1).columns)
X = []
y = []
indexes = []
norm_data_x = test[feature_names]
for i in tqdm.tqdm_notebook(range(0,len(test)-n)): 
    X.append(norm_data_x.iloc[i:i+n].values) 
    y.append(test['RD'].iloc[i+n-1]) #現有資料+30天的Y
    indexes.append(test.index[i+n-1]) #Y的日期
X=np.array(X)
y=np.array(y)
predictions = model.predict(X)
predictions = pd.DataFrame(predictions).rename(columns={0: '預測值'})
Y_test = pd.DataFrame(y).rename(columns={0: '實際值'})
final = pd.concat([predictions,Y_test],axis=1)
final['mae'] = abs(final['預測值'] - final['實際值'])
print(final.columns)
norm_data = pd.DataFrame(scaler.inverse_transform(final), columns=final.columns, index=final.index)
print(final)
  File "C:\Users\apple\.spyder-py3\try\untitled5.py", line 105, in <module>
    norm_data = pd.DataFrame(scaler.inverse_transform(final), columns=final.columns, index=final.index)

  File "C:\ProgramData\Anaconda3\envs\tensorflowenv\lib\site-packages\sklearn\preprocessing\_data.py", line 529, in inverse_transform
    X -= self.min_

ValueError: operands could not be broadcast together with shapes (214,3) (6,) (214,3) 
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum