我正在建立CNN用于信号分类。如下面的代码所示。但是我在model.fit(X_train2, y_train2, batch_size=32,verbose=1)
遇到问题
这给我带来错误
检查目标时出错:预期density_1的形状为(1,),但数组的形状为(14338,)
如果我将训练集更改为y_train
,我会得到
输入数组应具有与目标数组相同数量的样本。找到1个输入样本和14338个目标样本。
from keras.models import Sequential
from keras.layers import Conv1D
from keras.layers import MaxPooling1D
from keras.layers import Flatten
from keras.layers import Dense
import numpy as np
import pandas as pd
dataset = pd.read_csv('All.csv')
X = dataset.iloc[:, 0:100].values
y = dataset.iloc[:, 100].values
# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state = 0)
# Applying LDA
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
lda = LDA(n_components=80)
X_train = lda.fit_transform(X_train, y_train)
X_test = lda.transform(X_test)
num_classes = 1
X_train2=np.reshape(X_train, (1,X_train.shape[0], X_train.shape[1]))
X_test2=np.reshape(X_test, (1, X_test.shape[0], X_test.shape[1]))
y_train2=np.reshape(y_train, (1, y_train.shape[0]))
model = Sequential()
model.add(Conv1D(filters=32, kernel_size=5, input_shape=(14338, 4)))
model.add(MaxPooling1D(pool_size=5 ))
model.add(Flatten())
model.add(Dense(1000, activation='relu'))
model.add(Dense(num_classes, activation='softmax'))
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',metrics=['accuracy'])
model.fit(X_train2, y_train2, batch_size=32,verbose=1)
我的X_train2 =(1,14338,4)和y_train2 =(1,14338)和y_train =(14338,)
亲切的帮助,我试图更改尺寸仍然出现错误。