Logistic Regression in Python from Scratch | Simply Explained

Поделиться
HTML-код
  • Опубликовано: 27 июл 2024
  • Implement Logistic Regression in Python from Scratch ! In this video, we will implement Logistic Regression in Python from Scratch. We will not use any build in models, but we will understand the code behind the Logistic Regression in Python.
    ➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖
    This is Your Lane to Machine Learning ⭐
    ➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖
    📕 Download Implementation Code with Dataset : github.com/Jaimin09/Coding-La...
    ➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖
    ✔ What is Logistic Regression ? : • Logistic Regression Ma...
    ✔ Cost Function in Logistic Regression : • Logistic Regression Co...
    ✔ Gradient Descent in Logistic Regression : • Logistic Regression Gr...
    ✔ Derivative of Cost Function for Logistic Regression : • Derivative of Cost fun...
    ➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖
    Know the difference between Artificial Intelligence, Machine Learning, Deep Learning and Data Science, here : • Artificial Intelligenc...
    Complete Logistic Regression Playlist : • Logistic Regression Ma...
    ➖➖➖➖➖➖➖➖➖➖➖➖➖➖➖
    Subscribe to my channel, because I upload a new Machine Learning video every week : / @codinglane

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

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

    If you found this video valuable, then hit the *_like_* button👍, and don't forget to *_subscribe_* ▶ to my channel as I upload a new Machine Learning Tutorial every week.

  • @saumyashah6622
    @saumyashah6622 3 года назад +11

    Very few people explain things mathematically and a very few people want a mathematical explanation. People just want to code without understanding the algorithm. You and your subscribers are the best :)

    • @CodingLane
      @CodingLane  3 года назад +1

      Thank you so much for such a good compliment 😊

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

    Please don't stop uploading videos it's really really superb explanation in a precise manner. Great job keep it up bro 😎

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

    A very good video, been searching for something like this for so long. Finally found it. Thanks bro.

  • @pavithranpavithran7354
    @pavithranpavithran7354 5 месяцев назад +2

    Man for the past 2 days i have been searching the explanation
    Man you rocked it .Keep going brother

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

      Thanks a lot ! 😁

  • @MeetPatel-sk7pu
    @MeetPatel-sk7pu 3 года назад +5

    I don't have words for give compliment for your explanation bro.
    MOST CLEAR EXPLANATION I EVER SEEN BEFORE. 🍺🥂

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

      And I don’t have words to appreciate your comment ! Thank you very much ! It really means alot to me

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

    Thank you so much you really helped me start my ML journey

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

    I was searching a lot and finally bro!!! I got you!!!!! thanks a lot

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

      Thank you so much! This means a lot to me.

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

    thanks, very good video 👍

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

    500th like by me, good luck👍

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

    Thanks for sharing these videos😀. Your all videos are informative and make it so simple for me to understand the concept🤓.

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

      It's my pleasure. Happy to hear that! 🙂

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

    in your cost where did you get y and from cause you never defined them

  • @003kazimehrabrashid4
    @003kazimehrabrashid4 Год назад

    well , in your cost function video you told that
    dCost/dW = (A-Y).X
    but in code you wrote that
    dCost/dW = (1/m)(A-Y).X
    should I multiply (1/m) or not?please tell me bro

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

    Hey, thanks a lot for the video!
    So I'm facing a major problem. When I run the model, I am getting cost as NaN for every iteration after the 0th iteration.
    Why is this happening? How do I fix this?
    For context, I am using a different dataset (adult census income dataset from Kaggle) but all the preprocessing has been done and all the columns have numerical values.

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

      Its because you might be taking very large “learning_rate”
      Try to reduce its value by 100 times or 10000 times or may be more.
      Once you see cost function takes some value which is not NaN, you can increase the learning_rate or adjust it to train the model faster.
      If still it shows NaN, then check if you have implemented the equations of logistic regression properly or not. A slight change in equation can also cause model not to train.

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

    how to plot logistic regression ?

  • @mukeshgupta9806
    @mukeshgupta9806 Месяц назад

    By implementing the same code it is showing an error: weight is not defined what should I do

  • @mdtufajjalhossain1246
    @mdtufajjalhossain1246 3 года назад +1

    Thanks a lot. your explanation was just awesome. Would you please make a similar video on Multiclass Logistic Regression from scratch? I am expecting it from you bro.

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

      Thank you so much! And yea... I will try to make that video too

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

    you just saved my life mate thx

  • @ShivamSharma-eh8vb
    @ShivamSharma-eh8vb Год назад +1

    you are awsome

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

    thanks for this useful video .. I just have one question : I have a dataset for students performance in a course and I am required to split my dataset into 70% for training and 30% for testing without using sklearn .. How to do so?

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

      For this you can learn numpy and pandas from any video tutorial. That will help you in all these sorts of data preprocessing.

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

    you sir are a legend. I took several tutorials on machine learning , your videos are the only one that make sense to me. I don't know if you have any paid course out there, if you do please let me know, i will definitely purchase it. good luck :)

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

      Thanks a lot for the compliment 😇. Means a lot. Currently, I don’t have any paid courses, hoping to make them in future!

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

    Thanks for this video, it was very informative.
    Could you please explain the formula you have used for accuracy in accuracy function?

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

      Hi… I calculated error rate… which is % of wrong predictions and then subtracted it from 100

  • @brindhasenthilkumar7871
    @brindhasenthilkumar7871 3 года назад +1

    hi, I had been learning machine learning by my own and had seen many videos, your explanation was remarkable, keep going, there is a clarity after we listen to your videos, great great, all the best for making more videos on all algos of ML

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

      Thank you so much ! I am elated after reading this. I am glad you find my videos helpful.

    • @brindhasenthilkumar7871
      @brindhasenthilkumar7871 3 года назад +1

      @@CodingLane certainly yes, kindly upload more videos which can teach us from the scratch so that it will be easy for us to understand better than blindly using the python machine learning libraries. Great job, keep going

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

      Sure ! Thanks @@brindhasenthilkumar7871

  • @-alfeim2919
    @-alfeim2919 Год назад +1

    Amazing job!

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

    it was really helpful

  • @larrysummer2015
    @larrysummer2015 3 года назад +1

    keep it up man... you couldn't be better teaching...

  • @IbrahimAli-kx9kp
    @IbrahimAli-kx9kp 2 года назад +3

    Thanks for the video Jay 💙
    Just a simple question, at 5:31: You used the method (reshape) to modify Y but the (transpose) to modify X!
    Why don't we use transpose for both? I tried it and I think it works, otherwise you have other reason!
    Thanks again for your amazing content 😄

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

      You can perform the operation using reshape or transpose. Both are fine. There is no specific reason for me to use reshape instead of transpose. You can use any 😇

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

    bro thank you for good video

  • @taruchitgoyal3735
    @taruchitgoyal3735 3 года назад +1

    Hi
    At 1:11 you are uploading csv files for train and test.
    I am using Google Colab.
    Thus, the code to upload the files I got was
    =files.upload()
    Thus, how do I fit the same using Pandas as demonstrated by you?

    • @CodingLane
      @CodingLane  3 года назад +1

      Hello,
      here are the ways to use the files on google colab and load into pandas:
      towardsdatascience.com/3-ways-to-load-csv-files-into-colab-7c14fcbdcb92
      Hope it helps!

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

    Thank you for this video, it is really helpful.
    Can you make a video on feature scaling from scratch?

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

      Thanks for the suggestion… i will see if i can make a video on it

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

      @@CodingLane Thank you for your support

  • @acno_randintrandint4182
    @acno_randintrandint4182 3 года назад +1

    would A > 0.5 get us a sum of correct predictions or just one class? can you please explain a bit clearly maybe i missed

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

      Sure.
      Let say if A = [0.2, 0.7, 0.8, 0.3, 0.4, 0.6]
      Then A > 0.5 will be = [false, true, true, false, false, true]
      And if you convert it into integer, then it will be, Afinal = [0, 1, 1, 0, 0, 1]
      Thus, A initially were just probabilities. Now Afinal are predictions for class 0 and 1

    • @CodingLane
      @CodingLane  3 года назад +1

      Hope I made it clear now.

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

      @@CodingLane hey thanks but accuracy is sum of all the correct predictions / total predictions meaning and apologies if I am wrong ... compared to y truth and y predict how many in [0, 1, 1, 0, 0, 1] were right / total , not simply > 0.5 which yes will simply separate the classes ... i did calculate it back yesterday and my accuracy was around 68 - 71 % .. Super sorry if i did it all wrong and big thanks again

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

      def accuracy_manual(slope, intercept, X_test,Y_test):
      predictions = np.dot(slope.T, X_test) + intercept
      predictions_log =(sigmoid(predictions))
      all_predictions=[1 if i >= 0.5 else 0 for i in predictions_log[0]]
      print("all predictions == ", len(all_predictions))
      count=0
      for i in ap:
      if Y_test[0][i] == all_predictions[i]:
      count+=1
      else:
      pass
      print("correct count ", count)
      #alternate way
      s= sum([all_predictions[i] == Y_test[0][i] for i in all_predictions])
      print("correct count ", s)
      #accuracy = correct count / total count
      accuracy = count/len(all_predictions)
      print("accuracy of model ", accuracy)
      return accuracy

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

      np.mean(P == y_test)

  • @vg5675
    @vg5675 Месяц назад

    how to select best features to get the highest possible f1 score

  • @babaabba9348
    @babaabba9348 3 года назад +1

    very informative, you are the best continue

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

      Thank You so much 😇 !!

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

      @@CodingLane
      i have a question that concerns boudary and logistic regression how can i contact you in person

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

      @@babaabba9348 mail me on codeboosterjp@gmail.com

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

      @@CodingLane
      thank you so much mate

    • @babaabba9348
      @babaabba9348 3 года назад +1

      @@CodingLane
      maybe it would be better that you delete your address

  • @proterotype
    @proterotype 3 года назад +1

    Great video. You made it seem easy. And Easy is good. Thanks a lot

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

      Thank you so much ! I really appreciate it

  • @RajivKumar-nv2gj
    @RajivKumar-nv2gj 3 года назад +1

    Thanks bro

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

    Very Nice.

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

    Please make more videos on ml algorithms

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

      Thanks for the suggestion. Will also make videos on other ML algorithms. Though it might take some time.

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

    Content is very good, but the presentation is not satisfactory.

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

      Thank you for your feedback. I have tried to improve the presentation style in the newer videos. I hope you find it better.

  • @glenmason6680
    @glenmason6680 3 года назад +1

    sorry mate you need to slow down a bit

  • @danish5326
    @danish5326 3 года назад +1

    I love your explanation but please don't fake your accent. Its quite annoying.

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

      Thank You Danish !

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

      What do you mean by ''Fake your accent'' ?