У меня есть набор данных с около 2000 строк и 260 столбцов без метки. Ярлыки в форме алфавитов. Ошибка немного сложна для понимания.
file = "Sample.csv"
df=pd.read_csv(file,header=None)
X=df.iloc[:,:-1].values
Y=df.iloc[:,-1].values
Xtrain = np.expand_dims(X, axis=2)
label_Encoder = LabelEncoder()
NewTrgLabels = label_Encoder.fit_transform(Y.ravel())
ITrgLabels = to_categorical(NewTrgLabels)
def create_model():
model = Sequential()
model.add(Conv1D(5, 3, activation='relu', batch_input_shape=Xtrain.shape))
model.add(MaxPool1D(2, stride=2))
model.add(Conv1D(10, 4, activation='relu'))
model.add(MaxPool1D(2, stride=2))
model.add(Conv1D(20, 4, activation='relu'))
model.add(MaxPool1D(2, stride=2))
model.add(Flatten())
model.add(Dense(40, activation='relu'))
model.add(Dense(20, activation='relu'))
model.add(Dense(5, activation='softmax'))
opt = optimizers.SGD(lr=0.003, momentum=0.7)
model.compile(optimizer=opt, metrics=['accuracy'], loss='categorical_crossentropy')
return model
from sklearn.model_selection import KFold
n_split=10
for train_index,test_index in KFold(n_split).split(X):
x_train,x_test=X[train_index],X[test_index]
y_train,y_test=ITrgLabels[train_index],ITrgLabels[test_index]
model=create_model()
model.fit(x_train, y_train,epochs=20)
print('Model evaluation ',model.evaluate(x_test,y_test))