I think if you specify “sparse_output = False” when initializing the OneHotEncoder, the resulted ohe instance will not be a scipy csr_matrix and you won’t need to use the toarray() method to see the resulted matrix. But obviously it uses more storage this way…
Thank you for the tutorial! In cells [14] & [15] I couldn't make a straight array to later pass it as column names. So I used this line of code (from sklearn documentation): feature_labels = ohe.get_feature_names_out() print(feature_labels)
Hi! Great video but I have a question for you. Can i map, from one categories, es "STATE", with 30 different states, an onehotencoder that map for example, 5 states in a new categories Europe, 6 in America, and so on, without create 30 different new binary categories with every states?
Hello. Thanks for this video. It's quite informative. How can I deal with a situation where the categories are of varying lengths? I got this error message, "ValueError: all arrays must be same length"
It occurs when the categorical data you're trying to encode has varying lengths. One-hot encoding requires that all arrays (or columns) being encoded have the same number of unique categories.
Hi, Great video. I faced one problem. I have three categorical columns, and the # of unique values in these columns are different. I tried to add (dtype= object) in the (np.array command as I found the solution in many sites) but the result was in three different arrays not in one array. so please if you can help me. Thank u
OneHotEncoder is a preprocessing technique used in machine learning to convert categorical data (e.g., words, categories, labels) into a numerical format.
Hi Roshini, label enconder is used to label your target variable(Y) and one hot encoder is used to encode independent variables(X). One hot encoding will create new columns but label encoding will just create numbers instead of strings it will not create new columns
Can you please help me I got error " For a sparse output, all columns should be a numeric or convertible to a numeric" for pipe.fit(X_train,y_train) I double checked all this I dont why encoder error is fromed. PS- Car is already defined. X=car.drop(columns='Emissions_CO_[mg/km]') y=car['Emissions_CO_[mg/km]']
from sklearn.model_selection import train_test_split X_train,X_test,y_train,y_test= train_test_split(X,y, test_size=0.2)
from sklearn.linear_model import LinearRegression from sklearn.metrics import r2_score from sklearn.preprocessing import OneHotEncoder from sklearn.compose import make_column_transformer from sklearn.pipeline import make_pipeline
This is so straightforward. No other source where it's so simply put
Thank you
This is a good, direct steps to use ohe. This helps me alot. Thank you!
You're welcome!
Amazing explanation! Left no questions in my mind...
Thank you!
REALLLY REALLY HELPFUL YOU SAVE MY DAY!!!!!
You're welcome!
Very good video greetings from Argentina land of LEO MESSI
Thank you. I like Leo Messi a lot.
Great video regarding ohe using sklearn . Describe everything that we need to understand. Thank you
Glad it was helpful!
Great Tutorial...Only thing is that ravel() does not work for uneven arrays, one need to use concat or hstack
Thank you for sharing. I will try.
thanks my man
Thank you dude! I was wondering why ravel() wasn't working for me
I think if you specify “sparse_output = False” when initializing the OneHotEncoder, the resulted ohe instance will not be a scipy csr_matrix and you won’t need to use the toarray() method to see the resulted matrix. But obviously it uses more storage this way…
Yes
Thank you for the tutorial! In cells [14] & [15] I couldn't make a straight array to later pass it as column names. So I used this line of code (from sklearn documentation): feature_labels = ohe.get_feature_names_out()
print(feature_labels)
Great!
Thanks bro, was searching for this!
@@ajeyamandikal2010 You're welcome
Hello friend, is this method used to predict data or what is the method used to predict data?
This method is to convert categorical columns into numerical columns for machine learning model
great explaining sir .your video helped as .make more videos recarding data science
Thank you for your kind words!
After doing this, should I remove the columns color and country?
Yes, use dummy columns.
Thank you so much
Great Tutorial
You're welcome!
Very good video! Helped me a lot! Thanks ❤❤
You're welcome!
good video bro but could be better if you droped the unnessessary columns like color and country
Thank you. This video was only for encoding purpose not for feature selection :)
Greate tutorial!
Thank you
Hi! Great video but I have a question for you. Can i map, from one categories, es "STATE", with 30 different states, an onehotencoder that map for example, 5 states in a new categories Europe, 6 in America, and so on, without create 30 different new binary categories with every states?
Yes you can!
Hello. Thanks for this video. It's quite informative.
How can I deal with a situation where the categories are of varying lengths?
I got this error message, "ValueError: all arrays must be same length"
It occurs when the categorical data you're trying to encode has varying lengths. One-hot encoding requires that all arrays (or columns) being encoded have the same number of unique categories.
I got the same error, how can it be resolved?@@StatsWire
Very Quick !! Or So Simple. Unexpected Bruh!!
Thank you
Hi, Great video. I faced one problem. I have three categorical columns, and the # of unique values in these columns are different. I tried to add (dtype= object) in the (np.array command as I found the solution in many sites) but the result was in three different arrays not in one array. so please if you can help me. Thank u
I have the exact same problem as you, have you found the solution?
I've found the solution! the method np.hstack(x) worked for me
@@franfernandez795 life saver! thanks :)
@@franfernandez795 #danke
@@franfernandez795 BLESS YOUR SOUL
Onehotencoder will convert the word into binary or number format right ?
OneHotEncoder is a preprocessing technique used in machine learning to convert categorical data (e.g., words, categories, labels) into a numerical format.
@@StatsWire ok thanks 👍
Thanks a lot, really helpful video! :)
You're welcome!
Amazing
Thank you!
Thanks a lot! Great tutorial!
You're welcome!
I'm getting so many rows at the bottom where entire row is has NaN except for the encoded columns. What could be the issue.
I did remove all null values before encoding
Can you please check your code again or post it here.
.ravel() or .flatten() is just not working it's returning array of array as it is
Can you please check all the steps to see that you are not missing anything
Well explained bro
Thank you
Very nice tutorial
Thank you
Thank you!
You're welcome!
thank you so much
You're welcome!
what's the role of toarray() methode ?
Its primary role is to convert a sparse or structured array into a dense NumPy array.
I got an error in line 17 says >> ValueError: Shape of passed values is (988, 35), indices imply (988, 7) how can I fix it?
You made a mistake. Please follow steps again then you won't get the error.
Hi, I don't know where I can download the data set
Hi, you can download the data and jupyternotebook from my GitHub account: github.com/siddiquiamir/Python-Data-Preprocessing
Include problem of Dummy variable trap in one hot encoding please.
Thank you for your feedback. I have added it to my list.
hi whats the difference between one hot encoding and label encoder
Hi Roshini, label enconder is used to label your target variable(Y) and one hot encoder is used to encode independent variables(X). One hot encoding will create new columns but label encoding will just create numbers instead of strings it will not create new columns
@@StatsWire thanks alot
also when do we use minmax scaler and standard scaler and whats the difference betn them
@@roshini_begum When we have outliers in the dataset we use standard scaler otherwise minmax scaler is good to use
@@StatsWire thanks
It seems the code "ravel()" does not work if the columns have different number of unique values =(
I did not try that. Can you check the official documentation?
.ravel() isn’t working bro. It returns same two arrays as before
Please re-run the code and check.
It's also sad that such common use-case requires so many steps. Should be available in 1 step like pandas dummies
Yes, pandas dummies is easier
Could you olease share the csv file of this data
Sure. Here is the dataset link
Github: github.com/siddiquiamir/Data/blob/master/data-one-hot-encoder.csv
Bro paithiyama neee avlo variables podra
I did not understand the language but thank you :D
.ravel() did not work. I used .flatten()
That's great. I hope it's working for you
Can you please help me I got error " For a sparse output, all columns should be a numeric or convertible to a numeric" for pipe.fit(X_train,y_train) I double checked all this I dont why encoder error is fromed.
PS- Car is already defined.
X=car.drop(columns='Emissions_CO_[mg/km]')
y=car['Emissions_CO_[mg/km]']
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test= train_test_split(X,y, test_size=0.2)
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import make_column_transformer
from sklearn.pipeline import make_pipeline
ohe = OneHotEncoder()
ohe.fit(X[['Manufacturer', 'Model', 'Fuel_Type']])
ohe.categories_
column_trans= make_column_transformer((OneHotEncoder(categories=ohe.categories_),['Manufacturer','Model','Fuel_Type']),
remainder= 'passthrough')
lr=LinearRegression()
pipe=make_pipeline(column_trans,lr)
pipe.fit(X_train,y_train)