0

I want to train and test my data with Skitlearn MLPClassifier but I got ValueError: Can't handle mix of multiclass and multilabel-indicator error. Here is my code:

mlp = MLPClassifier(hidden_layer_sizes=(HIDDEN_1_COUNT,HIDDEN_2_COUNT),
                    activation="logistic",
                    solver="sgd", 
                    max_iter=EPOCH_COUNT, 
                    learning_rate_init=LEARNING_RATE)

mlp.fit(dataset_train, labels_train)
print(mlp.score(dataset_test, np.reshape(labels_test, (20, 1))))

According to PyCharm error happens at the last line.

Shape of dataset_test: 20x901, labels_test: 1x20

P.S: If I use labels_test instead of np.reshape(labels_test, (20,1)) I got ValueError: Found input variables with inconsistent numbers of samples: [1, 20] error. I couldn't find exact solution for both of them.

Vivek Kumar
  • 35,217
  • 8
  • 109
  • 132
Ilkin
  • 386
  • 3
  • 17
  • You should print your `labels_train` and `labels_test` here. What is the shape of `dataset_train`, `labels_train` and `labels_test`? – Vivek Kumar Apr 28 '17 at 01:35
  • all of are numpy arrays with integer values. Shape of dataset_train: 901x6, shape of labels_train: 20x4 (I've 20 samples), shape of labels_test: 1x20. I didn't use one-hot encoding for labels_test but when I use, the problem solved – Ilkin Apr 29 '17 at 15:50

1 Answers1

0

Probably it is because result of mlp is in one-hot-encoding type and it expects one-hot-encoded labels. When I changed my labels_test to one-hot-encoding it worked

Ilkin
  • 386
  • 3
  • 17