python - LabelEncoder fit_transform() 函数中的问题

标签 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'

最佳答案

你的问题很困惑......

缺少很多变量。

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

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

关于python - LabelEncoder fit_transform() 函数中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52437481/

相关文章:

python - 代码运行缓慢 - python 中的性能问题

python:如何在 scikit 学习分类器 (SVM) 等中使用 POS(词性)特征

python - 接收分类指标无法处理多类混淆矩阵的混合

python - Python 中的 JIRA OAuth 流程

python - sqlite数据库放在python命令行项目的什么地方

python - 在读取实际行之前,如何自动解析打开的audit.log 文件的语法?

python - Python3 中的 Gevent 支持

python-3.x - Visual Studio 安装 python 的位置

python - SVM Scikit-Learn : Why prediction time decrease with SVC when increasing parameter C?

python - pandas dataframe - 根据列标题更改值