成功解决TypeError: Encoders require their input to be uniformly strings or numbers.

成功解决TypeError: Encoders require their input to be uniformly strings or numbers. Got [‘float‘, ‘int‘,‘str’]

今天在给数据编码的时候,在将离散特征转换为整数编码时,出现了报错如下:
​​成功解决TypeError: Encoders require their input to be uniformly strings or numbers.
后来发现可以先将要编码的离散变量全部转换成字符型的,例如作出如下修改:

from sklearn.preprocessing import LabelEncoder
clean_loan_of[attri_cols] = clean_loan_of[attri_cols].astype('str') 
dfobject = clean_loan_df[attri_cols].select_dtypes(['object'])
def labelencode(columnlabel):
    clean_loan_df[columnlabel] = LabelEncoder().fit_transform(clean_loan_df[columnlabel])
for i in range(0, len(dfobject.columns)):
    labelencode(dfobject.columns[i])

就可以完成转换啦!

上一篇:AV1编码时间下降,接近使用水平


下一篇:于冰:用户导向的音视频体验优化