2

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!

screenshot

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

you also need to apply labelencoder to other categorical variables. ie vendor_id, and medalion
ohhh okay got it thanks! so I'm supposed to use onehotencoder on all categorical variables. I see.
yes, you need to. Also, please accept the answer, if it solves it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.