OneHotEncoder Error: cannot convert string to float

纵饮孤独 提交于 2019-12-11 05:48:36

问题


I was wondering if someone could help me with this. I'm learning about Multiple Linear Regression and was trying to do some practice but seem to have hit a problem. I was trying to convert payment_type into a categorical variable using onehotencoder. Here I have the error and the first few rows and columns of the data. I tried looking online and doing things that other people suggested but I kept getting errors from those as well. Is there a way to fix this? I've been trying for hours now. Also I'm not sure why it says cannot convert VTS when its the payment_type that I'm trying to convert. Any thoughts and help on the matter is greatly appreciated.

The code prior to what you see on the screen is basically just loading the data, thats about it.

Thanks!


回答1:


Documentation of sklearn.preprocessing.OneHotEncoder says:

Encode categorical integer features using a one-hot aka one-of-K scheme.

The input to this transformer should be a matrix of integers, denoting the values taken on by categorical (discrete) features.

You need to use sklearn.preprocessing.LabelEncoder, to convert your string variables to categorical integer values.



来源:https://stackoverflow.com/questions/50404130/onehotencoder-error-cannot-convert-string-to-float

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!