【问题标题】:Scikit learn's AttributeError: 'LabelEncoder' object has no attribute 'classes_'?Scikit learn的AttributeError:'LabelEncoder'对象没有属性'classes_'?
【发布时间】:2019-07-03 03:40:03
【问题描述】:

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

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")                                                               

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

【问题讨论】:

    标签: python keras scikit-learn


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 2013-05-20
      • 2020-02-26
      • 1970-01-01
      • 2019-06-18
      • 2015-07-03
      • 2017-11-24
      相关资源
      最近更新 更多