我在重塑数据以适应卷积神经网络时遇到问题。我尝试了很多解决方案,但仍然无法做到这一点。数据集包含 800 行和 271 列(最后一列包含类标签)。共有9个班。以下是我的代码:
dataset = pd.read_csv('train.csv')
X = dataset.iloc[:, 0:270].values
y = dataset.iloc[:, 270].values
print("X Shape: "+str(X.shape)) ---> (804, 270)
*** Reshaping Variables here
X_train, X_test, y_train, y_test = train_test_split(X_reshaped, Y_reshaped, test_size = 0.20)
model = Sequential()
model.add(Convolution1D(64, kernel_size=(10), input_shape=(X_train.shape[1],X_train.shape[2])))
model.add(Activation('relu'))
model.add(MaxPooling1D(3))
model.add(Flatten())
model.add(Dense(100))
model.add(Dropout(0.5))
model.add(Dense(9))
model.add(Activation('softmax'))
model.compile(loss='sparse_categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
model.fit(X_train,y_train,validation_data=(X_test,y_test))
print(str(model.evaluate(x_test,y_test)))
反正有没有成功重塑变量来训练模型?谢谢!