Reputation: 720
I am trying to use sklearn LabelEncoder but it say that it has no attribute classes_, but it exists, I don't know what is the problem. Here's a snippet of my code
from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()
def classes_():
#Return the classes which are classified by this model
return encoder.classes_
def num_of_classes():
"""
Return the number of ouput classes
"""
return len(classes_())
X=TimeDistributed(Dense(output_dim = num_of_classes(),293,activation = "softmax")
However, I get this error AttributeError: 'LabelEncoder' object has no attribute 'classes_'
Upvotes: 4
Views: 11958
Reputation: 7618
You need to call fit(...)
or fit_transform(...)
on your LabelEncoder
before you try an access classes_
, or you will get this error. The attribute is created by fitting.
Upvotes: 5