Search code examples
tflearn

how to use tflearn.data_utils.to_categorical (y, nb_classes)


I am new to python and also to tflearn. I am stuck with the to_categorical function of TFlearn. I read up the documentation and the below is from the website:

tflearn.data_utils.to_categorical (y, nb_classes)

Convert class vector (integers from 0 to nb_classes) to binary class matrix, for use with categorical_crossentropy.

Arguments y: array. Class vector to convert. nb_classes: int. Total number of classes.

My question is, what does it take in as arguments actually? I have 3 labels, A, B, C.(pandas series). I can get them into numpy array with .iloc().values to give a massive array of [A,C,B,C,C,B,A....A] And I just want them to become ([1,0,0],[0,0,1],...). So what format actually do i have to pass them in as the argument of the to_categorical function?

Advice greatly appreciated. Thanks.
nb: can do this without the to_categorical function but I thought will be good to make use of it.


Solution

  • the parameters of tflearn.datautils.to_categorical must be integer string, that is to say y must like [1,2,3,....]!