Machine Learning Tutorial Python - 17: L1 and L2 Regularization | Lasso, Ridge Regression

Sdílet
Vložit
  • čas přidán 21. 07. 2024
  • In this Python machine learning tutorial for beginners, we will look into,
    1) What is overfitting, underfitting
    2) How to address overfitting using L1 and L2 regularization
    3) Write code in Python and sklearn for housing price prediction where we will see a model overfit when we use simple linear regression. Then we will use Lasso regression (L1 regularization) and ridge regression (L2 regression) to address this overfitting issue
    Code: github.com/codebasics/py/tree...
    #MachineLearning #PythonMachineLearning #MachineLearningTutorial #Python #PythonTutorial #PythonTraining #MachineLearningCource #L1andL2Regularization #Regularization #sklearntutorials #scikitlearntutorials
    Do you want to learn technology from me? Check codebasics.io/?... for my affordable video courses.
    Machine learning tutorials: • Machine Learning Tutor...
    Popular Playlists:
    Data Science Project: • Machine Learning & Dat...
    Data Science Full Course: • Data Science Full Cour...
    Pandas: • Python Pandas Tutorial...
    matplotlib: • Matplotlib Tutorial 1 ...
    Python: • Why Should You Learn P...
    Jupyter Notebook: • What is Jupyter Notebo...
    Tools and Libraries:
    Scikit learn tutorials
    Sklearn tutorials
    Machine learning with scikit learn tutorials
    Machine learning with sklearn tutorials
    🌎 My Website For Video Courses: codebasics.io/?...
    Need help building software or data analytics and AI solutions? My company www.atliq.com/ can help. Click on the Contact button on that website.
    #️⃣ Social Medias #️⃣
    🔗 Discord: / discord
    📸 Dhaval's Personal Instagram: / dhavalsays
    📸 Instagram: / codebasicshub
    🌎 Website: codebasics.io/
    🔊 Facebook: / codebasicshub
    📱 Twitter: / codebasicshub
    📝 Linkedin: / codebasics
    ❗❗ DISCLAIMER: All opinions expressed in this video are of my own and not that of my employers'.

Komentáře • 190

  • @codebasics
    @codebasics  Před 2 lety +5

    Check out our premium machine learning course with 2 Industry projects: codebasics.io/courses/machine-learning-for-data-science-beginners-to-advanced

  • @bharathis9295
    @bharathis9295 Před 3 lety +202

    Statquest theory+Codebasics Practical implementation=😍😍😍

    • @codebasics
      @codebasics  Před 3 lety +55

      ha ha .. nice :) Yes I also like statquest.

    • @gokkulkumarvd9125
      @gokkulkumarvd9125 Před 3 lety +2

      Exactly!

    • @ItsSantoshTiwari
      @ItsSantoshTiwari Před 3 lety +2

      Same😂👌

    • @abhinavkaul7187
      @abhinavkaul7187 Před 3 lety +7

      @@codebasics BAM!! :P Btw, the way you explained Yolo that was superb, bro!

    • @sandydsa
      @sandydsa Před 3 lety +1

      Yes! Minor comment, kindly please switch age and matches won. Got confused at first 😂

  • @AlonAvramson
    @AlonAvramson Před 3 lety +8

    I have been following all 17 videos on ML you provided so far and found this is the best resource to learn from . Thank you!

  • @gyanaranjanbal10
    @gyanaranjanbal10 Před rokem

    Clean, crisp and crystal clear, I was struggling to understand this from a long time, your 20 mins video cleared it in one attempt, thanks a lot💌💌

  • @DrizzyJ77
    @DrizzyJ77 Před měsícem

    Bro, you don't know how you've helped me in my computer vision journey. Thank you❤❤❤

  • @bhavikjain1077
    @bhavikjain1077 Před 3 lety +2

    A good video to understand the practical implementation of L1 and L2. Thank You

  • @javiermarchenahurtado7013

    Such a great video!! I was struggling to understand regularization and now it's crystal clear to me!

  • @tusharsethi2801
    @tusharsethi2801 Před 3 lety

    One of the best videos out there for Regularization.

  • @piyushlanjewar6274
    @piyushlanjewar6274 Před 2 lety

    That's a really great explanation, Anyone can use this method in real use cases now. Keep it up.

  • @haintuvn
    @haintuvn Před 3 lety +5

    Thank you for your interesting video. As far as I get from the video, L1, L2 regulations help to overcome the overfit problem from Linear regression! What is about other algorithms ( Support vector machine, logistic regression..) , how can we overcome the overfit problem?

  • @amruth3
    @amruth3 Před 2 lety

    Sir your all the vedios are really helpful...Now Iam giving you the feed back of the vedio Iam going to see.This is also an beautiful vedio and Hyperparamter tuning also an very best vedio......God Bless you..u..work hard in getting think to understand in easy manner..

  • @ajaykushwaha-je6mw
    @ajaykushwaha-je6mw Před 2 lety

    Best tutorial on l1 and L2 Regularization.

  • @joehansie6014
    @joehansie6014 Před 3 lety +1

    All your videos are totally great. Keep working on it

  • @phuonglethithanh8498
    @phuonglethithanh8498 Před rokem

    Thank you for this video. Very straightforward and comprehensive ❤

  • @Hari-xr7ob
    @Hari-xr7ob Před 3 lety +53

    you should probably change the X and Y axes. Matches won is a function of Age. So, Age should be on X axis and Matches won on Y axis

  • @atulupadhyay1542
    @atulupadhyay1542 Před 3 lety +3

    machine learning concepts and practicals made easy, Thank you so much Sir

    • @codebasics
      @codebasics  Před 3 lety +1

      I am happy this was helpful to you.

  • @shashankdhananjaya9923

    Couldn't have explained it any simpler. Perfect tutorial.

  • @nastaran1010
    @nastaran1010 Před 5 měsíci

    best learning with very good explanation. Thanks

  • @nationhlohlomi9333
    @nationhlohlomi9333 Před rokem

    I really love your content….. You change lives❤❤❤

  • @yash422vd
    @yash422vd Před 3 lety +1

    As per the equation y = mX + c, you inter-changed the y & X axis, if I'm not wrong.
    Because you are trying to predict match won(yhat) which is your horizontal line and age(X) is on vertical line.
    Maybe using something unconventional mislead new-learners.
    As X is a horizontal line and y is vertical line, that's what we learned since school time.
    Assigning X & y to axis(as per your explanation) will be great help to learner.
    I hope you are not taking personally. My opologies if so!

  • @kouider76
    @kouider76 Před 3 lety

    Just came across this video accidentally simply great thank you

  • @user-nf3si6gw2n
    @user-nf3si6gw2n Před 8 měsíci +1

    Nice explanation .. Adding to that
    L2 Ridge : Goal is to prevent multicollinearity and control magnitude of the coefficients
    where highly corelated features can be removed by shirking the coefficients towards to zero not exactly zero , stability and generalization.
    L1 Lasso : Goal is to prevent sparsity in the model by shirking the coefficients exactly to zero , importance in feature selection, preventing overfitting..

    • @r0cketRacoon
      @r0cketRacoon Před 4 dny

      so, in what cases should we use L1 and L2?

  • @victorbenedict8743
    @victorbenedict8743 Před 3 lety

    Great tutorial sir.Its a privilege to be a fan of yours.Please sir could you please do a video on steps to carry out when doing data cleaning for big data.Thank you.

  • @bors1n
    @bors1n Před 3 lety +1

    thank you a lot, I'm from Russia and I'm student. I watch your video about ML and It helps me to understand better

  • @anuragsingh-pt5cy
    @anuragsingh-pt5cy Před 3 lety +1

    on taking these parameter-: xtrain,xtest,ytrain,ytest=train_test_split(x,y,test_size=0.30,random_state=101)
    i got lr.score(xtest,ytest) =0.6642052270622596
    lr.score(xtrain,ytrain) =0.6819231366292379
    so it doesn't seems me that much overfitting.. stll i have to do regularization??

  • @priyankshekhar2454
    @priyankshekhar2454 Před 3 lety

    Very good videos by you on each topic..thanks !!

  • @raufurrahmankhan1284
    @raufurrahmankhan1284 Před 3 lety

    Can we use Lasso for feature selection on classification problems?

  • @haneulkim4902
    @haneulkim4902 Před 3 lety

    Don't we have to one-hot encode Postcode, Propertycount as well since they are actually categorical values instead of continuous values?

  • @NeekaNeeksz
    @NeekaNeeksz Před 3 měsíci

    Clear introduction. Thanks

  • @unifarzor7237
    @unifarzor7237 Před 2 lety

    Always excellent lessons, thank you

  • @nexthome1445
    @nexthome1445 Před 3 lety +7

    Kindly make video on Feature selection for Regression and classification problem

  • @leonardomenar55
    @leonardomenar55 Před 2 lety

    Excellent Tutorial, Thanks.

  • @sunzarora
    @sunzarora Před 3 lety

    Nice video, my question is what will u do so accuracy will jump on this dataset from 67 to 90+?

  • @soumyopattnaik6787
    @soumyopattnaik6787 Před 3 lety

    IS it ok to impute with mean such large number of records without any justification? Shouldn't the column be dropped altogether?

  • @armghan2312
    @armghan2312 Před rokem

    is there any algorithm using which we can determine the unimportant features in our datasets?

  • @koustavbanerjee8195
    @koustavbanerjee8195 Před 3 lety +3

    Please do videos about XGBoost, LGBoost !! You Videos Are Pure GOLD !!

  • @nehareddy4619
    @nehareddy4619 Před 2 lety

    I really liked your way of explanation sir

  • @ankitmaheshwari7310
    @ankitmaheshwari7310 Před 2 lety

    Good.model representation is good.hoping some deep knowledge in next video

  • @furkansalman7108
    @furkansalman7108 Před 2 lety +1

    I tried Linear Regression on the same dataset but it scored the same with Ridge and Lasso why?

  • @dylanloh5327
    @dylanloh5327 Před 2 lety

    Thank you vm for this video. This is straight-forward and simple to understand!

  • @rohantalaviya136
    @rohantalaviya136 Před 2 měsíci

    Really great video

  • @SahilAnsari-gl3xu
    @SahilAnsari-gl3xu Před 3 lety +1

    Thank a lot Sir❤️ Very good teaching style (theory+practical)👍

  • @ajaykushwaha-je6mw
    @ajaykushwaha-je6mw Před 2 lety

    Sir, is there a way to find best parameter for LASSO and Rigid regression, if yes then please create a video for the same

  • @anvarshathik784
    @anvarshathik784 Před 2 lety

    achine learning concepts and practicals made easy, Thank you so much Sir

  • @SohamPaul-xy9jw
    @SohamPaul-xy9jw Před rokem

    When I am creating dummies, it is showing that the Suburb column is of type NoneType() and no dummies are getting created. What can be the problem?

  • @vyduong276
    @vyduong276 Před rokem

    I can understand it now, thanks to you 🥳

  • @joehansie6014
    @joehansie6014 Před 3 lety

    Simple but powerful😎👍

  • @YogaNarasimhaEpuri
    @YogaNarasimhaEpuri Před rokem

    @7:00 what does the penalizing means, can anyone explain, I'm confused with this term.
    Thanks in Advance.

  • @m.shiqofilla4246
    @m.shiqofilla4246 Před 3 lety

    Very nice video sir but at first i hoped you show the plot of scatter plot of the data and how the curve of the L1/L2 regression...

  • @kaizen52071
    @kaizen52071 Před rokem

    Nice video....good lesson......funny enough i see my house address in the dataset

  • @analuciademoraislimalucial6039

    Thank you so much teacher

  • @rithikas5849
    @rithikas5849 Před 2 lety

    Can you please provide the jupyter notebook link for this piece of code sir?

  • @mohammadrasheed9247
    @mohammadrasheed9247 Před 2 lety

    Nice Explanation. Also Recommended to play on 2X

  • @MrMadmaggot
    @MrMadmaggot Před rokem

    First when you apply lasso, you apply it apart from the first linear regression model you made right?
    Which means applying scikit Lasso is like making a linear regression but with regularization or it is applied to the linear regresion from the cell above??
    So what if I use a knn or a forest?

  • @Ultimate69664
    @Ultimate69664 Před 2 lety

    thank you ! this video save my exam :)

  • @surbhigulati9350
    @surbhigulati9350 Před rokem

    Hello Sir
    why did you noy fill the distance parameter with mean value?

  • @sanooosai
    @sanooosai Před 6 měsíci

    thank you great work

  • @king1_one
    @king1_one Před 5 měsíci

    good explanation sir and you need appreciation , i am here .

  • @jongcheulkim7284
    @jongcheulkim7284 Před rokem

    Thank you. This is very helpful.

  • @PollyMwangi-cp3jn
    @PollyMwangi-cp3jn Před 4 měsíci

    Thanks so much sir. Great content

  • @kibesamuel697
    @kibesamuel697 Před 9 měsíci

    The best of two worlds wow!

  • @mukeshkumar-kh2fh
    @mukeshkumar-kh2fh Před 2 lety

    thank you for helping the DS community

  • @gefett
    @gefett Před 3 lety

    Thank's for class it's very clearly for me.
    But I had a problem to create a sending file my code from to Kaggle, help me please.

  • @nikolinastojanovska
    @nikolinastojanovska Před 2 lety

    great video, thanks!

  • @gouravsapra8668
    @gouravsapra8668 Před 2 lety

    Hi...The equation, shouldn't it be : Theta0 + Theta1.x1 + Theta2.square (x1)+Theta3.cube (x1) rather than Theta0 + Theta1.x1 + Theta2.square (x2)+Theta3.cube (x3) because we have only one x feature ?
    2) the Regularization expression (Lambda part), my understanding is that we should not take "i & n" , rather we should take "j & m" etc. The reason is that in first half of equation, we took "i & n" for number of rows whereas in second half, we need to take number of features, so different parameters should be used.
    Please correct me if my understanding is wrong.

  • @phamnhatanh4485
    @phamnhatanh4485 Před rokem

    Sir, i can't find link Belbourne_housing csv .

  • @rash_mi_be
    @rash_mi_be Před 2 lety +1

    In L2 regularization, how can theta reduce when lambda increases, and increase when lambda decreases?

  • @ajaysaroha2539
    @ajaysaroha2539 Před 3 lety +1

    Sir,I am fresher & want to make career in finance domain data analyst & I have no any experience in finance domain so how can I gain knowledge in finance domain so pls give some suggestion about it.

  • @RadioactiveChutney
    @RadioactiveChutney Před 2 lety

    Note for myself: This is the guy... his videos can clear doubts with codes.

  • @vishvam1307
    @vishvam1307 Před 3 lety +1

    Nice explanation

  • @035-harshitsingh7
    @035-harshitsingh7 Před rokem

    sir can you provide ppt and jupyter notebook link of above used resources?

  • @tanishsadhwani730
    @tanishsadhwani730 Před 2 lety

    Amazing sir thank you so much

  • @Microraptorofmillinea
    @Microraptorofmillinea Před 2 lety +1

    what about alpha value and other two parameters ?

  • @tjbwhitehea1
    @tjbwhitehea1 Před 3 lety +2

    Hey, great video thank you. Quick question - what's the best way to find the optimal alpha? Do you do a grid search?

    • @codebasics
      @codebasics  Před 3 lety +1

      Yes doing grid search would be a way

  • @bruh-jr6wj
    @bruh-jr6wj Před 6 měsíci +1

    I believe the most appropriate imputing method here is to group by the similar type of houses and then fill with the mean value of the group. For example, if the average is, say, 90 m^2, and the home is only a flat, the building area is incorrectly imputed.

  • @anjalipatel9028
    @anjalipatel9028 Před 5 měsíci

    L1,L2 Regularization is valid for regression algorithm only?

  • @marthanyarkoa9007
    @marthanyarkoa9007 Před 8 měsíci

    Thanks so simple ❤😊

  • @DarkTobias7
    @DarkTobias7 Před 3 lety +3

    These are the videos we like!!!

    • @codebasics
      @codebasics  Před 3 lety

      Thanks DarkTobias. Good to see your comment.

  • @aadityashukla8535
    @aadityashukla8535 Před 2 lety

    good theory!

  • @SGandhi
    @SGandhi Před 2 lety

    Can you make a video of ensemble model of using decision tree,knn and svm code

  • @yayavellilion8136
    @yayavellilion8136 Před 6 měsíci

    where can i find a the script for this lecture

  • @adia9791
    @adia9791 Před 2 lety

    I think one must not use those imputations(mean) before train test split as it leads to data leakage, correct me if I am wrong.

  • @MrCentrax
    @MrCentrax Před rokem

    So are l1 and l2 polynomial regression models?

  • @JAVIERHERNANDEZ-wp6qj

    Maybe in the Cost formula, the indices for summation should be different (in general): for the MSE term the sum should be over the entire training dataset (in this case n), and the sum for the regularization term should run over the number of features or columns in the dataset

  • @sridharbajpai420
    @sridharbajpai420 Před rokem

    ho to ccomputer gradient of L1 reg its not even differentiable

  • @denisvoronov6571
    @denisvoronov6571 Před 2 lety

    Nice example. Thank you so much!

  • @ArunKumar-yb2jn
    @ArunKumar-yb2jn Před 2 lety

    something doesn't look right. How many degrees of the polynomial was fit via the ridge/lasso regression?

  • @sagarvarandekar8279
    @sagarvarandekar8279 Před 2 lety

    My lasso regression is getting wrong results. It is giving all coefficients as zero except the constant and R2 score as --0.001825328970232576. Someone please help.

  • @ayenewyihune
    @ayenewyihune Před 2 lety

    Cool video

  • @Nimmi_bro
    @Nimmi_bro Před 3 lety

    can you share melborune hosuing price here in youtube while you upload

  • @davuthdy876
    @davuthdy876 Před 2 lety

    Thank for your video for sharing to the world.

  • @bhoomi5398
    @bhoomi5398 Před 2 lety

    what is dual parameter and please explain what is primal formal & dual

  • @HA-bj5ck
    @HA-bj5ck Před 7 měsíci +1

    Appreciate the efforts, but there were issues with the foundational understanding. Additionally, the inclusion of dummy variables expanded the columns to 745 without acknowledgement or communication regarding its potential adverse effects to viewers was not expected.

  • @uswakhan3050
    @uswakhan3050 Před 6 měsíci

    from where can i download csv files

  • @nomanshaikhali3355
    @nomanshaikhali3355 Před 3 lety +1

    Kindly explain Boosting algos!!

  • @ravikumarrai7325
    @ravikumarrai7325 Před 3 lety

    Awesom video....really awesom..

  • @arjunbali2079
    @arjunbali2079 Před 2 lety

    thanks sir

  • @ranganitejasai459
    @ranganitejasai459 Před 3 lety

    hello sir currently i am pursuing b tech final year..I want very badly to do projects on ml . Can u plzz give me the project ideas.

  • @ayusharora2019
    @ayusharora2019 Před 3 lety

    Very well explained !!

  • @daretoschool4113
    @daretoschool4113 Před 3 lety +1

    Please make video for genetic algorithm