LabelEncoder fit_transform()函数

时间:2018-09-21 06:00:45

标签: python python-3.x scikit-learn

尝试执行以下代码时出现以下错误。

class LabelOneHotEncoder():
    def __init__(self):
        self.ohe = OneHotEncoder()
        self.le = LabelEncoder()
    def fit_transform(self, x):
        features = self.le.fit_transform( x)
        return self.ohe.fit_transform( features.reshape(-1,1))
    def transform( self, x):
        return self.ohe.transform( self.le.transform( x.reshape(-1,1)))
    def inverse_tranform( self, x):
        return self.le.inverse_transform( self.ohe.inverse_tranform( x))
    def inverse_labels( self, x):
        return self.le.inverse_transform( x)

y = list(map(ImageToLabelDict.get, train_images))
lohe = LabelOneHotEncoder()
y_cat = lohe.fit_transform(y)

错误

perm = ar.argsort(kind='mergesort' if return_index else 'quicksort')
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'

1 个答案:

答案 0 :(得分:0)

您的问题非常令人困惑...

缺少很多变量。

我猜可能会在ar发生。由ar生成的LabelOneHotEncoder可能具有一些np.NaN值。当您将data放入需要转换为没有某些特征/值的模型时,可能会发生这种情况。

One word: your training data is bigger than the transformed data.