Linear Regression From Scratch in Python (Mathematical)

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ม.ค. 2025

ความคิดเห็น • 162

  • @NerdyPickle-moe
    @NerdyPickle-moe 3 ปีที่แล้ว +246

    Please do more mathematical implementations like this please! This really helped me to understand the math behind these algorithms

  • @Ossigen8
    @Ossigen8 9 หลายเดือนก่อน +5

    I don’t comment often videos but this one is really good, you explained the math concept really well by doing the examples on the graph etc… Good stuff in this channel !

  • @cambridgebreaths3581
    @cambridgebreaths3581 3 ปีที่แล้ว +55

    I do like all your videos that contain the keywords "mathematical theory" and "from scratch" :). Please do more similar videos. Thank you kindly

    • @samas69420
      @samas69420 3 ปีที่แล้ว +3

      same, stuff from scratch is the best stuff for learning

    • @fater8711
      @fater8711 3 ปีที่แล้ว +3

      @@samas69420 yeah, and it's really fun
      I am always so proud when I am able to code something from scratch

  • @nasr-rsln
    @nasr-rsln ปีที่แล้ว +3

    this video is amazing, good job, im now actually thinking about re visiting the math classes i couldn't take before in order to get better at these machine learning algorithims.

  • @vardhanr8177
    @vardhanr8177 3 ปีที่แล้ว +10

    AMAZING video!!! I love these videos which teach theory too! Thank youuu!!!

  • @santrix1595
    @santrix1595 ปีที่แล้ว +3

    dude Slammer video!! love the fact that you made the math interesting and super easy to understand

  • @kapilsonyt
    @kapilsonyt 3 ปีที่แล้ว +3

    I recently stumbled upon this while looking for similar approach via python and I subscribed you now.
    Thank you very much for imparting knowledge.

  • @PML37
    @PML37 7 หลายเดือนก่อน +1

    That was just wow! The way you explained it was amazing.
    Thank you!

  • @SabarishanM
    @SabarishanM 7 หลายเดือนก่อน

    I was searching everywhere and final found what I need. Your video really clears up the fundamentals of creating Linear Regression Model. Thank you

  • @zukofire6424
    @zukofire6424 3 ปีที่แล้ว +8

    Thanks very much for this!! I am a data analysis student and close to giving up but still hanging on!

    • @zukofire6424
      @zukofire6424 4 หลายเดือนก่อน +1

      @kelvinthomas-pr8sd Thank you! I did then but it still apllies now. I now work but have 2 classes I haven't passed yet. Never give up!

  • @TheVerbalAxiom
    @TheVerbalAxiom 3 ปีที่แล้ว +1

    I am subscribing, definitely. You have taught in the most straight forward and explanatory way a concept that other videos made a bit too complicated. Thank you!

  • @ileshdhall
    @ileshdhall 4 หลายเดือนก่อน

    The way you explained and implemented was really efficient and easy, it was really helpful as I am just getting started on my ML journey and after implementing this I feel m a step forward. Thank You!!

  • @curtezyt1984
    @curtezyt1984 ปีที่แล้ว +1

    on 10:00 we need to take derivative of each weight (M) like this, first for M1 then for M2 then M3.... to Mn

  • @AkhilendraOjhaBME
    @AkhilendraOjhaBME 2 ปีที่แล้ว +2

    Greatly explained in simple words, looking forward to learn more methods from you.

  • @Ryguy12543
    @Ryguy12543 ปีที่แล้ว +1

    Thank you so much. Im working through problem set for a Neural Analysis class and this really helps. Great video.

  • @kenadams2261
    @kenadams2261 2 ปีที่แล้ว +1

    Amazing video, looking forward for more implementations from scratch!

  • @graphicsguy1965
    @graphicsguy1965 2 ปีที่แล้ว +3

    Thanks man! Awesome video that dumbed it down enough for me. Could you do linear regression of fitting a sphere to points given the sphere radius (or not) like is used in terrestrial laser scanning? If you've never messed with it, you place spheres around what you are scanning, then the software uses the spheres to align all of the different scans at different locations together.

  • @prathamshah9167
    @prathamshah9167 5 หลายเดือนก่อน

    A really insightful video to learn this concept!! I found it very helpful !!
    Just one suggestion @NeuralNine, please include the files (that you display in the video) in the description of the video.
    Everything else is amazing and praiseworthy!

  • @salambostaji9315
    @salambostaji9315 3 หลายเดือนก่อน

    Easy to follow and goes straight to the point, thank you!

  • @unknowncorsairtim
    @unknowncorsairtim ปีที่แล้ว +4

    Awesome tutorial! Could you please explain why you use gradient descent to minimize squared error instead of using the formula: divide the standard deviation of y values by the standard deviation of x values and then multiply this by the correlation between x and y?

  • @dragnar4743
    @dragnar4743 6 หลายเดือนก่อน

    Damn !! I like your video so much, especially the implementation part. Most of the people would just directly use sklearn library and call it a day. But, you really have showed how the code actually runs behind the scene. 👍👍💛💛

  • @atrumluminarium
    @atrumluminarium 3 ปีที่แล้ว +8

    It would have been nice to compare it to the analytical solution of least squares regression being (Xᵀ•X)⁻¹•(Xᵀ•Y) just to show they're identical

    • @andreagalloni92
      @andreagalloni92 ปีที่แล้ว

      quicker and theoretically more correct for solving this problem!

    • @JohnMacPherson-hr4yz
      @JohnMacPherson-hr4yz ปีที่แล้ว +1

      @@andreagalloni92 could you make a video and share it with everyone please? (theory and python code)

    • @andreagalloni92
      @andreagalloni92 ปีที่แล้ว +1

      @@JohnMacPherson-hr4yz mmm... Maybe I can :)
      I'll try to do it

  • @LyamanOsmanlı
    @LyamanOsmanlı 6 หลายเดือนก่อน +1

    hi , really you have the best videos in youtube. Your speaking is also very clear for me although my native language is not English. Thanks you very much it helps me very much , and i am in 17 years old.I want to improve and in my this way you help me.

  • @happypotato4252
    @happypotato4252 ปีที่แล้ว

    Excellent explanation of the implementation of linear regression, thanks!!

  • @davidmedina1886
    @davidmedina1886 3 ปีที่แล้ว +2

    This is a great video! Thank you so much!

  • @naitikpatil243
    @naitikpatil243 3 ปีที่แล้ว +2

    Waiting for series of such videos 🤩

  • @bluestar2253
    @bluestar2253 3 ปีที่แล้ว +14

    Yes, please do more videos like this one. Even Einstein gives it 2 thumbs up! :)

  • @lashrack4548
    @lashrack4548 2 ปีที่แล้ว

    You got a new subscriber... Best in detail explanation ever!!!

  • @atharezzeldin2802
    @atharezzeldin2802 5 หลายเดือนก่อน

    I really appreciate the time and the effort to simplify such a thing, Thanks a bunch 🌹🌹🌹🌹

  • @fraggodgaming4433
    @fraggodgaming4433 2 ปีที่แล้ว

    Thank you so much man! Great vid...Keep up the good work!

  • @baivabdattamajumder6568
    @baivabdattamajumder6568 ปีที่แล้ว

    If you're counting from 0 to n, it means you have (n+1) data points, so should the dividing factor not be 1/(n+1) while calculating mean of squared errors at 4:43?

    • @l-unnamed802
      @l-unnamed802 16 วันที่ผ่านมา

      U are right, it should be like that. He just made an accidental mistake.

  • @yxyyy
    @yxyyy 3 ปีที่แล้ว +5

    Next for logistic regression please!

  • @sryps
    @sryps 3 ปีที่แล้ว +2

    love the videos, finally

  • @zezestyles6215
    @zezestyles6215 ปีที่แล้ว

    Thank youuu :) Loved the way you explained it.

  • @actualBIAS
    @actualBIAS 11 หลายเดือนก่อน

    Bruder, danke dir. Es wollte nicht in meinen Kopf. Dank dir habe ich das verstanden.

  • @mysticrustacean4065
    @mysticrustacean4065 ปีที่แล้ว

    Brother! I simply love you after I came across this video!

  • @archer9056
    @archer9056 9 หลายเดือนก่อน

    Amazing simple explanation of linear regression. Please also cover the other techniques in same way

  • @deveshjain9543
    @deveshjain9543 ปีที่แล้ว

    I implemented it myself and it came out to be more accurate then sckit-learn
    import numpy as np
    from sympy import Symbol, solve, diff
    class LinearRegression:
    def __init__(self):
    self.w = {}
    def fit(self, x, y):
    for i in np.arange(x.shape[1] + 1):
    self.w[f"w{i}"] = Symbol(f"w{i}")
    e = 0
    for i in range(len(x)):
    yp = 0
    for j in np.arange(len(self.w)):
    if j == 0:
    yp += self.w[f"w{j}"]
    else:
    yp += self.w[f"w{j}"] * x[i][j-1]
    e += (yp-y[i]) ** 2
    eq = []
    for i in np.arange(len(self.w)):
    eq.append(diff(e, self.w[f"w{i}"]))
    w = solve(eq, list(self.w.keys()))
    for i in np.arange(len(self.w)):
    self.w[f"w{i}"] = w[self.w[f"w{i}"]]
    def predict(self, x):
    def prediction(features):
    yp = 0
    for i in np.arange(len(self.w)):
    if i == 0:
    yp += self.w[f"w{i}"]
    else:
    yp += self.w[f"w{i}"] * features[i-1]
    return yp
    return list(map(prediction, x))

  • @ahmedifhaam7266
    @ahmedifhaam7266 2 ปีที่แล้ว

    dude did my 6 hours lecture + lab class all in just 24 minutes, bruh. Ez Clap hahah, thanks a lot.

  • @aproudkafir7459
    @aproudkafir7459 2 หลายเดือนก่อน +1

    The flow should terminate on global minima right ?? Is this program complete ??

  • @madi6736
    @madi6736 10 หลายเดือนก่อน

    your explanations are really clear and precise, thank you very much♥♥♥

  • @saxenayashxi3974
    @saxenayashxi3974 หลายเดือนก่อน +1

    Loved it .......Thank you so much ❤❤

    • @NeuralNine
      @NeuralNine  หลายเดือนก่อน

      Glad you enjoyed it!

  • @quegon6125
    @quegon6125 13 วันที่ผ่านมา

    I have a question regarding the expression (-2 / n). Shouldn't it be placed outside the for loop since it is calculated multiple times, even though it's a constant that should be computed once for the gradient?🙂

  • @anonymousvevo8697
    @anonymousvevo8697 2 ปีที่แล้ว

    the math part as awesome! thanks a lot very clear and simple

  • @bharth_yadav
    @bharth_yadav 2 ปีที่แล้ว +1

    yoo out all explanations i saw u did the best work this is what i wanted best work man subbed

  • @omeshnath6826
    @omeshnath6826 ปีที่แล้ว

    got a good idea about linear regression thnx bud!!

  • @throgmortonartstudio2402
    @throgmortonartstudio2402 2 ปีที่แล้ว

    That was so much easier to understand. thank you.

  • @trido3815
    @trido3815 5 หลายเดือนก่อน

    Excellent explanation. Thanks

  • @drewprof
    @drewprof 9 หลายเดือนก่อน

    Nicely done!

  • @sajid_ahamed
    @sajid_ahamed 3 ปีที่แล้ว

    awesome video and dark mode paint rocksss

  • @donowen9848
    @donowen9848 ปีที่แล้ว

    Awesome representation!!!

  • @thomashoughton228
    @thomashoughton228 3 ปีที่แล้ว +1

    Why does 1/n become -2/n. As I read in towards data science that it would be 1/n and then the -2 would be after the sum symbol as 2x'i' so like why or how does 1/n become -2/n. Also great video btw, helped me unlock a few skills in the ml skill tree :)

  • @mohammadf9646
    @mohammadf9646 10 หลายเดือนก่อน +1

    well done

  • @amirnaeej7986
    @amirnaeej7986 ปีที่แล้ว

    You’re a life saver thank you soooo much❤❤

  • @lamiyanabaova3020
    @lamiyanabaova3020 2 ปีที่แล้ว

    Thanks a lot for great explanation!

  • @chadstrachan9696
    @chadstrachan9696 ปีที่แล้ว

    Great video, very informative

  • @JonasHolzbrecher
    @JonasHolzbrecher ปีที่แล้ว +1

    This is amazing!
    How can I store the current m and b values for every iteration?

  • @vallabhshelar3176
    @vallabhshelar3176 2 ปีที่แล้ว

    loved it bro u r just amazing

  • @roomian
    @roomian ปีที่แล้ว

    I dont understand the reasoning behind [m * x * b for x in range(20, 80)] why is this the y axis. What does it represent. Why the equation? Also why arent we just reading the found values of x and y? I have understood all the calculations being done but I dont understand the visualization/graph representation part. Please let me know if you see this.

    • @OfficialMazLi
      @OfficialMazLi ปีที่แล้ว

      He did it all wrong just ignore it imo

  • @felixliang7558
    @felixliang7558 4 หลายเดือนก่อน

    Great video!

  • @allenallen5136
    @allenallen5136 ปีที่แล้ว +1

    Combine theory with practice,and show the calculate procedure,really good👍

  • @dronedangwal447
    @dronedangwal447 ปีที่แล้ว +1

    Nice video! Could you please provide the dataset that you used

  • @minuet6919
    @minuet6919 3 ปีที่แล้ว

    Lmao, I finished summer school for algebra 1 and we just learned this and to calculate it, we used a calculator this is a amazing video the mathematics where correct and your explanation is amazing!

  • @steviegillen82
    @steviegillen82 5 หลายเดือนก่อน +1

    Excellent video, although I will need to scrub up on my mathematics!! I think I am one of the few that loves looking at formulas and wonders; "What in the hell is going on there?" 😆😆

  • @kuroisan2698
    @kuroisan2698 ปีที่แล้ว

    great video NeuralNine
    I feel this the gradiant descent. is not it ?
    if It is, is there an implementation for the least square
    because I feel it is just so random you take some values and you choose the least one from those random values not necessarily the least value you can get

  • @piyush9555
    @piyush9555 2 ปีที่แล้ว

    wow, that is exactly what is called simplicity

  • @shashwatbalodhi4042
    @shashwatbalodhi4042 ปีที่แล้ว

    I am getting error
    AttributeError Traceback (most recent call last)
    Cell In[10], line 39
    37 if i % 50 == 0:
    38 print(f"Epoch: {i}")
    ---> 39 m, b = gradient_descent(m, b, data, L)
    41 print(m, b)
    43 plt.scatter(data.studytime, data.score, color = "black")

  • @milorday5141
    @milorday5141 2 ปีที่แล้ว

    Thank you, very useful and clear.

  • @quaka96
    @quaka96 3 ปีที่แล้ว +1

    Why the gradient descent method? The pseudo inverse solves this immediately

    • @CptAJbanned
      @CptAJbanned ปีที่แล้ว

      Make a video about it and link me, plz

  • @farukesatergin8129
    @farukesatergin8129 2 ปีที่แล้ว +1

    Where can we get the csv file he worked on?

  • @ertugrulturkseven7565
    @ertugrulturkseven7565 5 หลายเดือนก่อน

    where can we find the data you uploaded. I would be happy to try the code. thanks for making these videos.

  • @fishfanaticgokul4758
    @fishfanaticgokul4758 ปีที่แล้ว

    bro how does the model created by these mathematical output and how does the predict function works
    ;

  • @Graverman
    @Graverman 3 ปีที่แล้ว +1

    here to learn something that I already know but the video is too entertaining to click off

  • @sneha.tiwari
    @sneha.tiwari 2 ปีที่แล้ว

    Hello, do you have a video or notes on plotting the linear regression when attributes in the input data points are more than one. Say 10 columns of x, and 1 column of y??
    Please respond.
    Thank you.

    • @sairekhaunnam3001
      @sairekhaunnam3001 2 ปีที่แล้ว

      I too need explanation on this. It will be really helpful

    • @sneha.tiwari
      @sneha.tiwari 2 ปีที่แล้ว

      @@sairekhaunnam3001 Hey, if there is one attribute the we can plot it on 2D, if two attributes, then in 3D, and for three attribute, we will plot in 4D, which is not possible visually. That's why we restrict ourselves.

  • @debashishsarkar649
    @debashishsarkar649 ปีที่แล้ว +2

    Hi sir , it's really helps me to understand linear regression and build it by myself from scratch. Thanks 👍 can you describe all the models from scratch? Like it's

  • @shubhamchoudhary5461
    @shubhamchoudhary5461 3 ปีที่แล้ว

    that's pretty good lecture.. 😍

  • @phoneix24886
    @phoneix24886 ปีที่แล้ว

    why did we do a partial derivative?

  • @adejumoadeniyi5152
    @adejumoadeniyi5152 3 ปีที่แล้ว

    This was really helpful

  • @ashenbandara6903
    @ashenbandara6903 5 หลายเดือนก่อน

    amazing crystal clear

  • @nilothpalbhattacharya8230
    @nilothpalbhattacharya8230 ปีที่แล้ว

    this is the real algorithm. great :)

  • @munazirhussain5450
    @munazirhussain5450 ปีที่แล้ว

    Which software you use for the video ?

  • @Meerkat_33
    @Meerkat_33 19 วันที่ผ่านมา

    where can I get the dataset? This is all new to me and I can't figure out how to get a test script going on my end, I keep getting dead ends

    • @ivan-jw1pf
      @ivan-jw1pf 3 วันที่ผ่านมา

      you can just ask chatgpt to generate you a dataset. It will even convert it into csv file

  •  2 หลายเดือนก่อน

    the defined lossfunction is not called anywhere ,why

  • @annawilson3824
    @annawilson3824 2 ปีที่แล้ว

    What's the point of printing Epochs if we see nothing on the screen in that regard lol, why is it highly mathematical if we do not even derive anything? I would redo the video with loss_function being in the print, o/w it just hangs in the code for God knows what reason.

  • @anidea8012
    @anidea8012 2 ปีที่แล้ว

    please provide the dataset which you use bcz it will us to follow along with you

  • @lucasgonzalezsonnenberg3204
    @lucasgonzalezsonnenberg3204 ปีที่แล้ว

    Hi, I really like your videos. One question, what is h?
    Thank you!

  • @sriram2k4
    @sriram2k4 2 ปีที่แล้ว

    Amazing video!!!!

  • @gamingwithdingo
    @gamingwithdingo 7 หลายเดือนก่อน +1

    I love this guy

  • @shaileshchauhan7855
    @shaileshchauhan7855 2 ปีที่แล้ว

    Why did you decrease the no of epocs ? And doesn't minima can be found with partial derivative =0 ?

    • @CptAJbanned
      @CptAJbanned ปีที่แล้ว

      The minima of one of the partial derivatives wont necessarily be the minima for the loss function since it also depends on the other variables/features

  • @tusharvashistha190
    @tusharvashistha190 ปีที่แล้ว

    amazing content

  • @kaleemahmed3300
    @kaleemahmed3300 3 ปีที่แล้ว

    Great explanation
    Upload more model implementation plz

  • @muhammadhammadsarwar698
    @muhammadhammadsarwar698 8 หลายเดือนก่อน

    Can Anyone tell me some practical usecase or some example where we can implement this? It should be great if anyone can give me full scenario

    • @lsgamingff6695
      @lsgamingff6695 หลายเดือนก่อน

      as of it own this wont be any useful but as we keep learining we can def find some more models which used in predicting some many useful things but as of this right now it is not useful

  • @mehdibouhamidi4675
    @mehdibouhamidi4675 3 ปีที่แล้ว

    can you do the same for Support vector machine

  • @eslamashraf5847
    @eslamashraf5847 ปีที่แล้ว +1

    Amazing explaining, thanks a lot!
    Can you upload the csv file and send me the link, please ?

  • @naturemusic7391
    @naturemusic7391 2 ปีที่แล้ว

    there is a improvement need to be done sir while discussing about error you are constantly saying the function as mean squared error right! but this is not the error function the function which need to minimize is the cost function. loss or error function measure the error of single training set while cost function is the summation of all the error of the training set.

  • @navardowilliams7484
    @navardowilliams7484 ปีที่แล้ว

    You sound like tech with Tim😂😂😂

  • @MultiCodFTW
    @MultiCodFTW 2 ปีที่แล้ว +1

    @NeuralNine How do I test the trained models to give a prediction based on a newly given value/independent variable (a value that is foreign to the training set)?
    Great video btw!

    • @adrianbitsinnie1537
      @adrianbitsinnie1537 ปีที่แล้ว

      Yes! This is a good question I hope he answers. If he already has can someone link me please? :)

  • @keyurpancholi4277
    @keyurpancholi4277 2 ปีที่แล้ว

    where is the csv file?

  • @rockymani94
    @rockymani94 3 ปีที่แล้ว

    Lstm ,rnn , logistics and more we are expecting more from you

  • @davidlanda2324
    @davidlanda2324 ปีที่แล้ว

    You should not to "think" that it is a best line, you should verify it!