Я начинаю свой первый код машинного обучения с python. Но я столкнулся с ошибкой при разработке матрицы путаницы для моей мультиклассовой модели.
#Defining the model
model = Sequential()
model.add(Dense(32,input_shape=(22,),activation='tanh'))
model.add(Dense(16,activation='tanh'))
model.add(Dense(6,activation='tanh'))
model.add(Dense(5,activation='softmax'))
model.compile(Adam(lr=0.004),'sparse_categorical_crossentropy',metrics=['accuracy'])
#fitting the model and predicting
model.fit(X_train,Y_train,epochs=1)
Y_pred = model.predict(X_test)
Y_pred = Y_pred.astype(int)
Y_test_class = np.argmax(Y_test, axis=0)
Y_pred_class = np.argmax(Y_pred, axis=0)
#Accuracy of the predicted values
print(metrics.classification_report(Y_test_class,Y_pred_class))
print(metrics.confusion_matrix(Y_test_class,Y_pred_class))
Я получаю эту ошибку:
TypeError: Singleton array 3045 cannot be considered a valid collection.
Детали тестовых данных X_test [: 5]
[['0' '1' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0'
'0' '1' '0' '0']
['1' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0'
'0' '0' '0' '0']
['1' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0'
'0' '0' '0' '0']
['0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0'
'0' '0' '0' '0']
['0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0' '0'
'0' '1' '1' '0']]
Y_test [: 5]
['1' '2' '2' '2' '2']
Форма
Y_test_class
==> ()
Y_pred_class
==> (5,)