逆变换ValueError:操作数无法与形状一起广播

时间:2017-09-19 19:30:21

标签: python numpy

请求帮助 - 不断获取ValueError:执行inverse_transform时,操作数无法与形状一起广播(下面代码中的最后一行)。任何指针都非常感激。 感谢。

代码:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

training_set = pd.read_csv('daily.csv')

from sklearn.preprocessing import LabelEncoder, OneHotEncoder

onehotencoder = OneHotEncoder(categorical_features = [0])
training_set = onehotencoder.fit_transform(training_set).toarray()

from sklearn.preprocessing import MinMaxScaler

sc = MinMaxScaler()
training_set = sc.fit_transform(training_set)
X_train = training_set[:, 0:15]
y_train = training_set[:, 15:]
dims = len(X_train[0])
X_train = np.reshape(X_train, (len(X_train), 1, dims))

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

regressor = Sequential()
regressor.add(LSTM(units = 4, activation = 'sigmoid', input_shape = (None, dims)))
regressor.add(Dense(units = 4))
regressor.compile(optimizer = 'adam', loss = 'mean_squared_error')
regressor.fit(X_train, y_train, batch_size = 32, epochs = 50)

test_set = pd.read_csv('daily_test.csv')

onehotencoder2 = OneHotEncoder(categorical_features = [0])
test_set = onehotencoder2.fit_transform(test_set).toarray()

inputs = sc.transform(test_set)
inputs = inputs[:, 0:15]
inputs = np.reshape(inputs, (len(inputs), 1, dims))

predicted = regressor.predict(inputs)
predicted = sc.inverse_transform(predicted)

1 个答案:

答案 0 :(得分:0)

这听起来很奇怪,但确实帮助我修复了错误。

如果要使用“ excel”篡改“ csv训练数据”文件,并且要从excel中删除列,

您在csv数据中最终会出现一个空白的“,”值,这将对我造成影响。