Scikit learn 的 AttributeError: 'LabelEncoder' 对象没有属性 'classes_'?

IS9*_*S92 4 python scikit-learn keras

我正在尝试使用sklearn LabelEncoder,但它说它没有属性classes_,但它存在,我不知道是什么问题。这是我的代码片段

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")                                                               
Run Code Online (Sandbox Code Playgroud)

但是,我收到此错误 AttributeError: 'LabelEncoder' object has no attribute 'classes_'

jav*_*ett 5

在尝试访问之前,您需要调用fit(...)fit_transform(...)on your ,否则您将收到此错误。该属性是通过拟合创建的。LabelEncoderclasses_