#python #minmax
#python #minmax
Вопрос:
Я использую преобразователь MinMax для данных с одним 27 coulmn, но я использую только один столбец для обучения и прогнозирования, а затем использую lstm для прогнозирования тестовых значений. но когда я использую обратное преобразование minMax в значения prdiction (18,1) shape . он показывает ошибку
Ошибка значения: не транслируемый выходной операнд с формой (18,1) не соответствует форме трансляции (18,27)
это некоторые из строк кода:
# convert series to supervised learning
def series_to_supervised(data, n_in=1, n_out=1, dropnan=True):
n_vars = 1 if type(data) is list else data.shape[1]
df = DataFrame(data)
cols, names = list(), list()
# input sequence (t-n, ... t-1)
for i in range(n_in, 0, -1):
cols.append(df.shift(i))
names = [('var%d(t-%d)' % (j 1, i)) for j in range(n_vars)]
# forecast sequence (t, t 1, ... t n)
for i in range(0, n_out):
cols.append(df.shift(-i))
if i == 0:
names = [('var%d(t)' % (j 1)) for j in range(n_vars)]
else:
names = [('var%d(t %d)' % (j 1, i)) for j in range(n_vars)]
# put it all together
agg = concat(cols, axis=1)
agg.columns = names
# drop rows with NaN values
if dropnan:
agg.dropna(inplace=True)
return agg
# load dataset
dataset = read_csv('newtours.csv', header=0, index_col=0)#hh.csv 20 train
values = dataset.values
#print(values)
values = values.astype('float32')
# normalize features
scaler = MinMaxScaler(feature_range=(0, 1))
scaled = scaler.fit_transform(values)
# frame as supervised learning
reframed = series_to_supervised(scaled, 1, 1) #####################scaled
# split into train and test sets
values = reframed.values
#print(values)
n_train = 57
train = values[:n_train, :]
test = values[n_train:, :]
print (train)
train_X = train[:, 26]
print (train_X)
train_y = train[:, 53]
print (train_y)
train_X = train_X.reshape(len(train_X),1)
print (train_X)
train_y = train_y.reshape(len(train_X),1)
print (train_y)
train_X = train_X.reshape(train_X.shape[0],1, train_X.shape[1])
print (train_X)
train_y = train_y.reshape(train_y.shape[0],1, train_y.shape[1])
print (train_y)
test_X = test[:, 26]
test_y = test[:, 53]
test_X = test_X.reshape(len(test_X),1)
test_y = test_y.reshape(len(test_X),1)
test_X = test_X.reshape(test_X.shape[0],1, test_X.shape[1])
test_y = test_y.reshape(test_y.shape[0],1, test_y.shape[1])
model = Sequential()
#model.add(LSTM(3, input_shape=( train_X.shape[1], train_X.shape[2]), stateful=True))
model.add(LSTM(1, input_shape=(train_X.shape[1], train_X.shape[2])))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(train_X, train_y, epochs=10, batch_size=1, verbose=2)
yhat = model.predict(test_X)
yhat = yhat.reshape(len(yhat),1)
print(yhat.shape)
yhat1=scaler.inverse_transform(yhat)