Python 热编码和pandas.category.code有什么区别
我正在处理一些问题,有如下疑问: 在数据集中有一个具有以下唯一值的文本列:Python 热编码和pandas.category.code有什么区别,python,pandas,scikit-learn,categorical-data,one-hot-encoding,Python,Pandas,Scikit Learn,Categorical Data,One Hot Encoding,我正在处理一些问题,有如下疑问: 在数据集中有一个具有以下唯一值的文本列: array(['1 bath', 'na', '1 shared bath', '1.5 baths', '1 private bath', '2 baths', '1.5 shared baths', '3 baths', 'Half-bath', '2 shared baths', '2.5 baths', '0 shared baths', '0 baths', '5 ba
array(['1 bath', 'na', '1 shared bath', '1.5 baths', '1 private bath',
'2 baths', '1.5 shared baths', '3 baths', 'Half-bath',
'2 shared baths', '2.5 baths', '0 shared baths', '0 baths',
'5 baths', 'Private half-bath', 'Shared half-bath', '4.5 baths',
'5.5 baths', '2.5 shared baths', '3.5 baths', '15.5 baths',
'6 baths', '4 baths', '3 shared baths', '4 shared baths',
'3.5 shared baths', '6 shared baths', '6.5 shared baths',
'6.5 baths', '4.5 shared baths', '7.5 baths', '5.5 shared baths',
'7 baths', '8 shared baths', '5 shared baths', '8 baths',
'10 baths', '7 shared baths'], dtype=object)
如果我使用Count Vectorize将它们转换为一个热编码
我得到以下错误:
AttributeError:“float”对象没有属性“lower”
请告诉我错误的原因 除此之外,我可以使用:
pd.Categorical(_DF_LISTING_EDA.bathrooms_text).codes
一个热编码和pd.category.code之间有什么区别
谢谢
阿米特·莫迪
pandas.get_dummies(X_train[colname])[0]
当前使用
CountVectorizer
的代码与一个热编码无关。一个热编码也是不计数矢量化。你想做什么?我想把这些分类数据转换成一个热门编码谢谢你的回复。我已经通过了一个热编码器在Sk学习的文件。在一个ho编码器中,我们为测试列车分割数据集,并在列车数据上训练一个热编码器,并从测试数据中获得输出。通过这种方式,它可以处理看不见的数据,pandas.get_假人也可以处理看不见的数据吗?不,你需要为此做额外的工作,比如对编码的序列变量进行dict,如果没有新变量,你就将其添加为“其他”
pandas.get_dummies(X_train[colname])[0]