Data Preprocessing 06: One Hot Encoding python | Scikit Learn | Machine Learning

Поделиться
HTML-код
  • Опубликовано: 15 сен 2024

Комментарии • 102

  • @ngneerin
    @ngneerin 2 года назад +27

    This is so straightforward. No other source where it's so simply put

  • @_danfiz
    @_danfiz 2 года назад +6

    This is a good, direct steps to use ohe. This helps me alot. Thank you!

  • @violetasaguier1370
    @violetasaguier1370 Год назад +3

    Very good video greetings from Argentina land of LEO MESSI

    • @StatsWire
      @StatsWire  Год назад +2

      Thank you. I like Leo Messi a lot.

  • @aliyildirim5343
    @aliyildirim5343 9 месяцев назад

    Amazing explanation! Left no questions in my mind...

  • @nirajkhatri2017
    @nirajkhatri2017 Год назад +1

    Great video regarding ohe using sklearn . Describe everything that we need to understand. Thank you

  • @RR-hq4cv
    @RR-hq4cv Год назад +2

    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)

  • @ashutoshdongare5370
    @ashutoshdongare5370 Год назад +3

    Great Tutorial...Only thing is that ravel() does not work for uneven arrays, one need to use concat or hstack

    • @StatsWire
      @StatsWire  Год назад

      Thank you for sharing. I will try.

    • @ZAZ069
      @ZAZ069 7 месяцев назад

      thanks my man

    • @SMoon453
      @SMoon453 5 месяцев назад

      Thank you dude! I was wondering why ravel() wasn't working for me

  • @kyleiong7311
    @kyleiong7311 9 месяцев назад

    REALLLY REALLY HELPFUL YOU SAVE MY DAY!!!!!

    • @StatsWire
      @StatsWire  9 месяцев назад

      You're welcome!

  • @ngneerin
    @ngneerin 2 года назад +1

    .ravel() or .flatten() is just not working it's returning array of array as it is

    • @StatsWire
      @StatsWire  2 года назад +1

      Can you please check all the steps to see that you are not missing anything

  • @poojakumarirollno9880
    @poojakumarirollno9880 Год назад

    great explaining sir .your video helped as .make more videos recarding data science

    • @StatsWire
      @StatsWire  Год назад

      Thank you for your kind words!

  • @arenashawn772
    @arenashawn772 7 месяцев назад

    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…

  • @fefefefezzz
    @fefefefezzz Год назад

    Very good video! Helped me a lot! Thanks ❤❤

  • @mdhasanuzzaman4039
    @mdhasanuzzaman4039 Год назад

    Thank you so much
    Great Tutorial

  • @jeanfabraruiz7994
    @jeanfabraruiz7994 2 года назад +1

    After doing this, should I remove the columns color and country?

    • @StatsWire
      @StatsWire  2 года назад +1

      Yes, use dummy columns.

  • @ammarayounas170
    @ammarayounas170 9 месяцев назад

    thank you so much

    • @StatsWire
      @StatsWire  9 месяцев назад

      You're welcome!

  • @mob-INchalangady
    @mob-INchalangady 10 месяцев назад

    good video bro but could be better if you droped the unnessessary columns like color and country

    • @StatsWire
      @StatsWire  10 месяцев назад

      Thank you. This video was only for encoding purpose not for feature selection :)

  • @fullnesmindcristiano8638
    @fullnesmindcristiano8638 Год назад +1

    Hello friend, is this method used to predict data or what is the method used to predict data?

    • @StatsWire
      @StatsWire  Год назад +1

      This method is to convert categorical columns into numerical columns for machine learning model

  • @Hellios92
    @Hellios92 Год назад

    Thanks a lot, really helpful video! :)

  • @waleedahmad2012
    @waleedahmad2012 11 месяцев назад

    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.

    • @waleedahmad2012
      @waleedahmad2012 11 месяцев назад

      I did remove all null values before encoding

    • @StatsWire
      @StatsWire  11 месяцев назад

      Can you please check your code again or post it here.

  • @emanuelea9967
    @emanuelea9967 2 года назад +1

    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?

  • @codingzone4690
    @codingzone4690 2 года назад

    Very Quick !! Or So Simple. Unexpected Bruh!!

  • @mousabmohammadshtayat4788
    @mousabmohammadshtayat4788 2 года назад +3

    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

    • @franfernandez795
      @franfernandez795 2 года назад +1

      I have the exact same problem as you, have you found the solution?

    • @franfernandez795
      @franfernandez795 2 года назад +20

      I've found the solution! the method np.hstack(x) worked for me

    • @taylorgood1007
      @taylorgood1007 2 года назад +1

      @@franfernandez795 life saver! thanks :)

    • @fatihmercan6023
      @fatihmercan6023 Год назад

      @@franfernandez795 #danke

    • @bvbyballena472
      @bvbyballena472 Год назад

      @@franfernandez795 BLESS YOUR SOUL

  • @tymothylim6550
    @tymothylim6550 2 года назад

    Thanks a lot! Great tutorial!

  • @aakashrai2749
    @aakashrai2749 Год назад

    Onehotencoder will convert the word into binary or number format right ?

    • @StatsWire
      @StatsWire  Год назад

      OneHotEncoder is a preprocessing technique used in machine learning to convert categorical data (e.g., words, categories, labels) into a numerical format.

    • @aakashrai2749
      @aakashrai2749 Год назад

      @@StatsWire ok thanks 👍

  • @alonzoslim
    @alonzoslim 9 месяцев назад

    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"

    • @StatsWire
      @StatsWire  9 месяцев назад

      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.

    • @lucykelly499
      @lucykelly499 8 месяцев назад

      I got the same error, how can it be resolved?@@StatsWire

  • @Intellectual_House
    @Intellectual_House Год назад

    what's the role of toarray() methode ?

    • @StatsWire
      @StatsWire  Год назад

      Its primary role is to convert a sparse or structured array into a dense NumPy array.

  • @dhm9818
    @dhm9818 Год назад

    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?

    • @StatsWire
      @StatsWire  Год назад

      You made a mistake. Please follow steps again then you won't get the error.

  • @mazharalamsiddiqui6904
    @mazharalamsiddiqui6904 3 года назад

    Very nice tutorial

  • @ibragim_on
    @ibragim_on 2 года назад

    Greate tutorial!

  • @vamsikrishna-ft8rn
    @vamsikrishna-ft8rn 2 года назад

    Well explained bro

  • @rubennadevi
    @rubennadevi Год назад

    Thank you!

  • @ayeshabibi-b3l
    @ayeshabibi-b3l 11 месяцев назад

    Amazing

  • @victorarayal
    @victorarayal Год назад

    It seems the code "ravel()" does not work if the columns have different number of unique values =(

    • @StatsWire
      @StatsWire  Год назад

      I did not try that. Can you check the official documentation?

  • @uchennaonyema989
    @uchennaonyema989 Год назад

    .ravel() isn’t working bro. It returns same two arrays as before

    • @StatsWire
      @StatsWire  Год назад

      Please re-run the code and check.

  • @bthekhoa2704
    @bthekhoa2704 Год назад

    Hi, I don't know where I can download the data set

    • @StatsWire
      @StatsWire  Год назад

      Hi, you can download the data and jupyternotebook from my GitHub account: github.com/siddiquiamir/Python-Data-Preprocessing

  • @anshulsharma7080
    @anshulsharma7080 Год назад

    Include problem of Dummy variable trap in one hot encoding please.

    • @StatsWire
      @StatsWire  Год назад

      Thank you for your feedback. I have added it to my list.

  • @roshini_begum
    @roshini_begum 2 года назад

    hi whats the difference between one hot encoding and label encoder

    • @StatsWire
      @StatsWire  2 года назад +2

      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

    • @roshini_begum
      @roshini_begum 2 года назад

      @@StatsWire thanks alot

    • @roshini_begum
      @roshini_begum 2 года назад

      also when do we use minmax scaler and standard scaler and whats the difference betn them

    • @StatsWire
      @StatsWire  2 года назад +1

      @@roshini_begum When we have outliers in the dataset we use standard scaler otherwise minmax scaler is good to use

    • @roshini_begum
      @roshini_begum 2 года назад

      @@StatsWire thanks

  • @ngneerin
    @ngneerin 2 года назад

    It's also sad that such common use-case requires so many steps. Should be available in 1 step like pandas dummies

    • @StatsWire
      @StatsWire  2 года назад

      Yes, pandas dummies is easier

  • @AbdullahAlMamun-jm4qm
    @AbdullahAlMamun-jm4qm 2 года назад

    Could you olease share the csv file of this data

    • @StatsWire
      @StatsWire  2 года назад

      Sure. Here is the dataset link
      Github: github.com/siddiquiamir/Data/blob/master/data-one-hot-encoder.csv

  • @aravindng5157
    @aravindng5157 11 месяцев назад

    Bro paithiyama neee avlo variables podra

    • @StatsWire
      @StatsWire  11 месяцев назад

      I did not understand the language but thank you :D

  • @umeshk0697
    @umeshk0697 2 года назад

    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)

  • @VinitKhandelwal
    @VinitKhandelwal 2 года назад

    .ravel() did not work. I used .flatten()

    • @StatsWire
      @StatsWire  2 года назад

      That's great. I hope it's working for you