我将1dCNN用于时间序列数据,但是在model.fit line
中发生以下错误。
错误如下:
Error when checking input: expected conv1d_11_input to have shape (6700, 1)
but got array with shape (1, 1)
。
任何一位PLZ帮助 代码部分如下
dataframe = pd.read_excel("file path", header=None,delim_whitespace=True)
dataset = dataframe.values
X=dataframe.values[:,0]
Y=dataframe.values[:,2]
X = np.expand_dims(X, axis=1)
Y = np.expand_dims(Y, axis=1)
(X_train, X_test, Y_train, Y_test) = train_test_split(X, Y, test_size=0.33, random_state=seed)
X_train = np.reshape(X_train, (-1, X_train.shape[1],1))
Y_train = np.reshape(Y_train, (Y_train.shape[0], 1, Y_train.shape[1]))
X_test = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
print(X_train.shape)
print(Y_train.shape)
n_timesteps, n_features, n_outputs = X_train.shape[0], X_train.shape[1], Y_train.shape[1]
verbose, epochs, batch_size = 0, 100, 32
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=3, activation='relu', input_shape=(n_timesteps,1)))
model.add(Conv1D(filters=64, kernel_size=3, activation='relu'))
model.add(Dropout(0.5))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dense(n_outputs, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
model.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=verbose)'
答案 0 :(得分:0)
使用:
.tiff