1
$\begingroup$

I'm a beginner with scikiti-learn library. I have an ANN with 3 input, 2 hidden layers and 3 output.

mlp = MLPClassifier(hidden_layer_sizes= hidden_layers,max_iter=iterations, activation=activation_fun)

I read on the documentation that the classifier uses softmax for the output activation function and cross-entropy loss function. I have a multi-class problem where the three outputs will predict the classes 0,1,2. My question is that. How can I retrieve the vectors that enconds the classes 0,1,2? example: [1,0,0] -> 0 [0,1,0] -> 1 [0,0,1] -> 2

$\endgroup$
0
$\begingroup$

How did you create the labels in the first place? You can know which corresponds to which by using scikit-learn's Label Encoder. This handles the labeling and at the end you can use inverse transformation to get the label names.

For one-hot-encoding the labels, you can use Label Binarizer, which again has an inverse defined in the link.

$\endgroup$
  • $\begingroup$ Than you for your help :) we have to use Label Encoder when we have to encode textual data in numerical label? I have already numerical labels. I tested it, but return the same labels. I'd like know the output vector of the neural network.. or maybe I don't understand how to apply it $\endgroup$ – Paul Nov 15 at 9:26
  • $\begingroup$ Then it's probably in numerical order. If you already tested the label encoder, you can try the inverse transform defined in the link above to make sure they are so. $\endgroup$ – serali Nov 15 at 9:35
  • $\begingroup$ @Paul please also check the edited part $\endgroup$ – serali Nov 15 at 9:45
  • $\begingroup$ It convert the label 0,1,2 into three vector. but how can I be sure that the same encoding is used by the mlp classifier? $\endgroup$ – Paul Nov 15 at 14:18
  • $\begingroup$ Here is the source code for the predict function for MLP. It returns the inverse transforms of the label binarizer. github.com/scikit-learn/scikit-learn/blob/1495f6924/sklearn/… $\endgroup$ – serali Nov 15 at 14:52
0
$\begingroup$

If you are interested on the probability output of your model, simply call mlp.predict_proba(X)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.