Я работаю над проектом Kaggle о распознавании рукописных цифр . Есть база для интересующихся. Я провел первое исследование с использованием kNN, и результаты были великолепны с точностью до 97%.
Я пытаюсь внедрить искусственную нейронную сеть для того же анализа.
Мой код на Pythonis
import keras
from keras.models import Sequential
from keras.layers import Dense# Initialising the ANN
classifier = Sequential()# Adding the input layer and the first hidden layer
classifier.add(Dense(units =15 , kernel_initializer = 'uniform', activation = 'sigmoid', input_dim = 784))# Adding the second hidden layer
classifier.add(Dense(units = 15, kernel_initializer = 'uniform', activation = 'sigmoid')) # Adding the output layer
classifier.add(Dense(units = 10, kernel_initializer = 'uniform', activation = 'sigmoid'))# Compiling the ANN
classifier.compile(optimizer = 'sgd', loss = 'sparse_categorical_crossentropy', metrics = ['accuracy'])# Fitting the ANN to the Training set
classifier.fit(X_train, Y_train, batch_size = 128, epochs = 300)
# Activation functions: 'sigmoid', 'tanh', 'relu',
# Predicting the Test set results
Y_pred_ann = classifier.predict(X_test)
score_ann = classifier.evaluate(X_test, Y_test)
score_ann
c_matrix_ann = confusion_matrix(Y_test, Y_pred_ann) # rows = truth, cols = prediction
sns.heatmap(c_matrix_ann, annot=True, square=True, cmap = 'Greens_r')
plt.xlabel('Predicted')
plt.ylabel('Actual')
plt.rcParams['figure.figsize'] = (8.0, 8.0) # ... and big plots
Результат вывода
array([[2.7740002e-04, 3.3974648e-06, 4.1400194e-03, ..., 2.4288893e-05,
7.5080991e-04, 2.3245811e-06],
[1.0848045e-05, 4.5597553e-06, 6.5565109e-06, ..., 3.4272671e-06,
1.7035007e-04, 1.5136600e-04],
[3.2186508e-06, 3.0972064e-03, 9.4562769e-05, ..., 3.3088624e-03,
1.4249086e-03, 2.0797372e-02],
...,
[3.5762787e-07, 6.1863720e-02, 1.0821521e-03, ..., 1.0878146e-03,
2.4909973e-03, 4.0937960e-03],
[5.4240227e-06, 1.4960766e-05, 7.5727701e-05, ..., 1.9669533e-06,
3.6263466e-04, 3.2812357e-05],
[1.5248895e-02, 0.0000000e+00, 3.1948090e-05, ..., 1.0699034e-05,
3.5730004e-04, 1.1205673e-05]], dtype=float32)
, в то время как он должен быть чем-то похожим на
array([3, 6, 9, ..., 1, 6, 5])
Я получаю сообщение об ошибке ValueError: Classification metrics can't handle a mix of multiclass and continuous-multioutput targets
потому что первый массив имеет форму (12600,10), а второй - (12600,0).
Что я делаю не так? У кого-нибудь была такая же проблема раньше? Я не могу найти ошибку.