Computing gradients using TensorFlow | Training a Linear Regression model from scratch.

Harshit Tyagi · Beginner ·📐 ML Fundamentals ·5y ago

Key Takeaways

The video demonstrates training a linear regression model from scratch using TensorFlow, computing gradients using TensorFlow's Gradient Tape feature, and performing partial derivatives to optimize model parameters. It covers key concepts such as linear regression, gradient descent, and automatic differentiation.

Full Transcript

hello everyone welcome to the channel data science with harshad so in this particular video i want to talk about the essence of machine learning it's in fact a tutorial where we learn how we can you know train a linear regression model right from the scratch using tensorflow and i was actually you know fiddling around with the the automatic differentiation uh feature of tensorflow and i was trying to learn how to compute gradients and how can we actually you know how would back propagation work so just was trying to build an intuition and uh i came up with this tutorial uh you know at a random point where i decide that let's just create something very interesting so this is a very uh interesting concept where you'll learn a little bit about linear regression i suggest that you go through some in-depth post post and there's some mathematics involved partial derivatives and as well so that is used because you want to minimize the loss so we talk about the main components the loss the optimizer and how you can perform partial derivatives using gradient tape uh from tensorflow so we only cover the applied part of it uh the coding part of it if you want to dive into the math of things you might want to go to andrew angie's videos or someone else so i have linked all the resources below so you can check them out as well uh but yeah let's get down to business let's start coding uh this simple linear regression model and we'll train it from scratch without using anything else except tensorflow so what we are trying to do is we are going to learn the essence of machine learning so we're going to do that by learning how we generally train a machine learning model and in this case we have taken an example of a linear regression model so it's going to be very simple we are going to do it from the scratch and we'll see how tensorflow chips into this whole paradigm and this whole system so the important concepts that one should learn is you know you should know what is linear regression and if you do not i mean i'll give you a brief understanding but you should definitely check out some uh in-depth post do google it there are plenty of resources on linear regression then second point is how does a gradient descent work that is something that you should do kind of have an understanding and i'll tell you uh you know how gradient descent kind of works just briefly again i will tell you i have linked all the resources below where you can learn gradient descent from and then lastly we are going to understand like how tensorflow library can be used in order to uh you know compute those gradients and we'll talk about automatic differentiation which is basically used in all sorts of neural networks that we see these days so uh let's see what we have so let's say uh we have a bunch of data points all right just like the blue points over here and we are trying to fit a line uh to this data set and based on so basically a single line a line uh is has an equation a general equation of y equals m x plus c now whenever you are training a linear regression model what is generally generally happening is we the model is trying to learn the value of m and c because y and x you have provided but m and c decides what would be m decides the slope and c is basically the y-intercept where the line uh cuts your y-axis when the value of x is zero so basically uh what we are trying to do in a linear regression model is we are trying to get to the best possible values of m and c where our model would converge and we'll reach the best fit line so for example here uh let's say this is the first line which is y equals mx plus c then uh the model learns and it gets to a better stage and then it kind of tilts again you see this is a better fit and then this is the final line for this particular data set so this is basically what is actually happening across you know uh different sorts of epochs or different training uh iterations so at last it kind of learns that you know yeah this is where the best possible values of m and c and uh how do you do that let's talk about that so the main components of any simple machine learning model like there are different types and they're different learning methods as well but i'm simply talking about the traditional you know the laws and optimization methods so first of all you need data to train your model so you you must have data sets so that's fine then the second step or the second component is the model itself which is uh basically any model that you're trying to learn is some sort of an equation that so if you have a lot of features then a lot of values x1 x2 x3 you'd be providing and it will compute the result based on that equation based on that model and it will give you the value of y which would can be a real value it could be a discrete value so and then once you've got the y value you have to check all right what is the difference between your learned value that is the predicted value and the actual ground truth which is the real value so this is we are talking about the training uh data set so the loss function basically helps you get the errors in your predictions and based on how uh how big the error is you try and optimize your loss function you try to minimize it and how do you minimize it let's see so for let's say we if we are talking about linear regression so our goal is to learn the value of m and c that's clear loss function we are going to use mean squared error so there can be you could have used mean absolute error as well but we are using mean squared error as a loss function and here is the equation as well so y hat is the predicted value y i is the the normal y is the basically the ground truth and this is this system for uh this is the equation for uh yours mean squared error you square the value of the sum and you divided by the number of values that is your mean squared error now this is basically kind of a convex function and in order to minimize so our basically target here is to minimize this loss function and we'll do it again and again and again until we get to a point where we get the best possible values for m and c now this loss function is basically written in terms of m and c so every time we actually calculate the gradient and we try and find out okay can we like move further ahead and if we can based on how a big step big of a step you want to take that is being dictated by your learning rate so you then you move on and you find out the best basically you find out the bottom or the minimum of your loss function so we're going to use the gradient descent so to minimize this loss function and for gradient descent so this is what the function our loss function would kind of look like for this uh loss function mean squared error so here what we are doing is uh this is on the y axis you have the loss and on the x axis you let's say you write it in the form of m and c or some sort of a weight okay so uh you can also call it with that what is the weight so uh starting point we basically start off from any random value so we start off from there and then based on how big of a step you want to take uh that is actually when you define your learning rate that is how big of a step you want to take and it should be somewhere in the range of this point zero one or point zero zero one because you don't want to like uh be you want you don't want to keep it too big because otherwise it there can be a chance that you might miss the minimum or you cannot keep it like too small otherwise it will the training would be very slow it would move very slowly so uh what we are going to do here is we need to compute partial derivative so equation of the loss function would be with respect to your m and c with respect to the weights that we have to learn so we would be using partial derivatives uh we'll have to compute the partial derivative of this loss function with respect to each of those values m and c if you want to practice the math you can do this manually in order to build a better understanding and you can watch andrew angie's videos for that if you want to learn more like but here uh we are going to use tensorflow's gradient tape so tensorflow provides us all the features uh for automatic differentiation that we are going to use and i'll just show you how so further we'll be writing a training loop where we'll define okay how many uh epochs you want to train it for the number of times you want to run that loop and we'll define the learning rate which is the step size of our gradient descent we'll keep updating the weights that is the values fm and c and then we'll keep on calculating the loss as well so at every point you'll get the loss you'll get uh basically the updated values of m and c and we'll see how the model actually tries to learn and converge and we keep doing that until we get to a best fit line so let's quickly dive into the code so for the code i am using google collaboratory notebook i've created a new notebook over here so let's quickly rename it computing gradient descent so this is this part is done now first of all let's quickly import all the required libraries so so we are using import tensorflow as tf that's the main library uh for this particular uh tutorial over here and if we would need any other library we'll import it uh based on our needs so that's fine uh the first step is to basically create our data set so let's quickly create the data set and uh for what we are doing is we are let me just quickly define the learning objectives so and what all we have to do so here what we are doing is we are uh basically writing a low level code all right to implement a linear regression using a tf all right and what we need to do is we are actually also learning how to compute compute gradients using gradient tape and lastly learn the model so our model is basically of the form so the equation that we are trying to model is equation so let's quickly check this so this is our model basically y equals five x plus eight so uh according to this uh we'll create some toy data set we just we are just we don't we are not using any real world data set we will create our own data set so for data creation we again are going to use a tensorflow df dot constant so let's quickly do that itself create data okay so how are we creating the data set so we need x and y so let's quickly create x so x is basically our tf dot constant so you you can create tensors using constant or you can use the variable so this will i'll just show you how this creates a tensor so tf.constant and you need to provide right uh the range of values so let's define range equals 10 and keep it keep the data type to float d type equals float 32 all right and then we are going to create y all right so y is going to be 5 star x plus c so that would be our y so yeah so after creating this let's print what is in our x and y so x is going to be this and y is going to be uh this so once we've done this uh c is not okay 5x plus 8 sorry i'm still running in the five y equals mx plus c mode so yeah x we have got x so x is basically these are both tensors uh so if you like check x this way this is going to tell you that this is a tensor of shape 10 so basically we have 10 elements 1d array it's a numpy array of data type float32 so this is basically what we have in our dataset so we have now created the training set you can also create a testing set so testing set is again going to be the same way x underscore test so you can you can use tf dot constant we are creating a tensor and this time we keep the range from 10 to 20 and provide the data type which is float 32 all right so this is our x test and again y test is equal to 5 star x underscore test plus 8. so this is our this is basically our testing data set now what we are going to do next is we are going to simply create a model uh so let's say what would happen forget about linear regression what would happen if we predict the mean of the trading sample as the prediction for all the values so in that case let's say uh predicting mean so there's no model basically we're using that let's just uh predict the mean as the final answer to all the testing samples so if you are passing testing the asset to our model we will simply give you the mean as the answer so predicting mean as the solution so here what would happen is uh basically i am going to write a function so uh function is basically defined uh let's say this is our predict function to this function if i'll pass the x the sample data set and what it will do is it'll do y underscore trend so how many uh based on number the number of samples that you have sent us uh all we'll do is we'll provide you the mean so let's define this mean here uh y underscore mean uh equals that is or based on our training samples so y dot numpy tensorflow is based uh you know built on top of numpy so you can you have this numpy method uh as you can see over here in the tensor as well so y dot number i am getting all the values and then i'm calculating the mean in this way so based on all the so in why i have all of these elements i'm just cam computing the mean over here and i have stored it in y underscore mean here i have all i will do is based on the number of samples that you send to this predict function i will simply predict or send you the mean as the solution for each of those samples so this is our y underscore thread so this is our predictions and we'll again we'll have to find out what what's the error so for computing the error so again we write our compute msc function so this basically takes the predicted value or you can say by underscore thread and the original value and based on this we will compute all the errors so errors is going to be y minus y underscore thread and we simply square it and so this would be basically uh so uh it's broadcasting that's happening so each individual element so there would be element wise subtraction happening over here so return tensorflow uh we'll have to create uh mean squared error so mean we'll have to calculate for this we are using tensorflow reduce mean function and you pass this errors uh tensor to this and it will compute the mean of square so here we are calculating the square terms and here we are calculating the mean so we this is our mean squared error all right so this part is done now let's compute the loss for our baseline model so this is basically our currently this is our baseline model the baseline model is very simple basically we haven't done anything we have simply said that the answer would be the average of our training sample so here why underscore pred again we pass predict and let's just run this on our test samples so we'll get the wire predictions and loss we'll have to compute so compute underscore msc and to this we need to pass the predictions and the original values or sorry the test in by underscore test basically so if you'll pass this you'll get the loss it'll compute the loss for you for the testing samples and you can check the loss so loss is basically 2706 so loss dot numpy you can do and it'll give you the value exactly so this is our loss so you've kind of got the gist we have predicted we have computed the loss now comes to the linear model so let's try to code the linear model all right linear regression model so here uh we'll be doing a bunch of things all right so first of all what we'll have to do is uh so we are trying to predict the values of m and c uh all right and we need to compute partial derivatives uh and these values would be in the form of it will be the equation will be written in the form of m and c so the function that we'll have to uh you know derive using the gradient tape it should be written in the form of mnc so let's so here we'll have to like change our compute uh msc function so compute underscore msc for let's say linear model so to this compute linear compute msc function what we'll do is we'll pass x okay then we'll pass y as well we'll pass m and we'll pass c so this is basically what would hap what would be these are basically all the components of our linear regression model and what would happen is we'll first calculate the predictions so y underscore thread and we'll get it by m star x plus c whatever we have passed to this model sorry uh this is sometimes the intellisense just plays around with you so here again the next step compute msc we are calculating the error so that would be again that would be simple so y underscore red you can simply use this line over here so this is again this is fine y uh minus y underscore pred and you square it and then you return the tf dot reduce underscore mean uh mean of the errors okay so this is our compute msc function for our linear model so this is pretty simple now comes the important part this is the loss function that we have to calculate the derivative of and we have computed it in the form of m and c so m and c we'll keep learning and we'll have to initialize it but we'll do that in the training loop in just a bit so here what we'll do next is we'll have to write the compute gradient function we have to minimize this function so to let's say to minimize the above loss function we have to compute the partial derivative with respect to m and c so with respect to m and c is the part where we have defined the compute msc function and this is all going to be done very easily so let's define our compute gradient function so this is the function that we write and again here as well this is the main function that we'll be calling x y m and c all right and to this function what we'll do is we'll use with so this is the syntax for gradient tape uh with gradient tape you just sorry tf dot gradient tape as you can call it simply tape so this is basically the syntax that we have on the tensorflow documentation as well and if you want to see like you can do uh let's say gradient tape yeah so you can learn more about automatic differentiation and gradient tape how it works so they've given a bunch of examples over here you can deep dive into these as well so all right so how they are calculating the gradient tape uh and it's used in a lot of other functions and you know values as well tensorflow is more of a mathematical library as compared to a machine learning library that we have a notion of so again uh with tf.gradient tape as tape that is that part is done now you have to wrap this loss function that you have around this on this tape so loss equals you have to compute the loss within this tape so compute msc underscore for linear model and you pass x comma y comma m comma c so we have passed all the parameters the required parameters to this compute so loss function and all you need to do is simply return tape dot gradient all right and the loss that you have calculated along with the parameters on which you have to you know with respect to which you have to uh compute the derivative so here it's going to be m and c so this is as simple as that it'll compute the derivative will get you the dm and dc which is the derivative with respect to m and derivative with respect to c so how are we going to use these so let's quickly uh you know define the functions so let's say we have computed some random uh values for m and c so let's start off by 0.0 and similarly for c as well so m and c we have defined so dm is so we'll calculate the loss with respect to dm and derivative of loss with respect to c so here we'll compute underscore gradient and we'll pass x comma y comma m comma c yeah i'm just running it for once we'll define the training loop now so that is fine and then we'll just simply print okay uh dm or you can say gradient with with respect to m so this is going to be dl underscore dm and the next one is going to be dl respect to c so let's print these so here you see this is a gradient with respect to m and this is all happening uh here so we have already defined x y m and c m and c we didn't know we have randomly initialized the values of m and c so this is uh you can say random initialization of m and c all right so we have used the variable tensorflow variable tensor here so b these two are basically scalar tensors you can say rank zero tensors and i have computed the gradient so this is the initial gradient this is the first time now i need to in order to find the best possible value of m and c we need to minimize this loss we have to keep minimizing until we get to a stage where we are convinced with the values of m and c that we get so what we do here is uh we simply have to define our training loop so this is the part where we define our training loop so quickly all we need to do is we need to first of all uh define some steps so the number of steps is going to be let's say we train it for 1000 steps okay and we also define our learning rate let's call it lr which is let's say 0.01 okay and then for our we are kind of i'm trying to give it as a form of you know when you train a neural network with the tensorflow we'll kind of give it the same message so message is going to be a simple string so this is let's say you know or you can say epoch epoch uh which is going to be your step and then this is going to be loss is going to be your loss and then lastly the values of m and c as well let's print those as well m and c is going to be sorry c and that's it backslash and let's add one acceleration new line so again we will do the same uh first of all random initialization of m and c so that part is done training loop we of uh we have initialized the values of m and c we'll start off from 0.0 okay and then uh the next step is going to be defining the loop so the loop is basically very easy so for each step in this range of let's say we start off from zero and we do [Music] steps uh plus one so this is from going from zero to uh thousand so this is easy and then we compute first of all we get the dm and dc so this is simply compute the gradient so this will calculate the prediction do all of those steps and we need to simply pass x y m and c so it'll compute the gradients it'll do everything give you the gradients with respect to m and c now you need to update these mnc values based on the gradients that you have got so how do you do how do you update the value so we use the assign function so the constant tensor cannot be updated but the variable tensor so these are the variable tensor that we have defined so these can be updated using the assign method or you can say assign sub method so here all you need to do is dm the derivative that you have got the gradient you multiply it with the learning rate so here gradient descent is doing its job all you need to do is that you know how quickly i want to train this you know how what would be the step size of my learning so that is your learning rate so you divide you multiply your gradient with your learning rate and that will be your new m and similarly you do this for your c as well dm and this is your dc so after that all you need to do is uh simply print so we are going to print it for let's say every 100 every 100 iteration so step 100 equal to equal to 0 and what we're going to do is loss equals let's say compute underscore msc so we compute the loss over here and we'll get the value so in order to print our loss uh m comma c and then we print the message so let's quickly try to run this now uh we have done everything all right step this part is not defined okay uh and x uh we'll define it over here and print this message okay uh learning read is not defined okay sorry the learning rate is lr all right so okay so you have you see epoch 0 100 200 300 400 and you can see we have we started off from the loss of 208 right after the first gradient or the first derivative was calculated first iteration uh oh sorry after the 100th iteration we got from 200 to 4 loss of 4.5 and then after that we went to a loss of 1.46 and uh at epoch number 300 we reached a loss of 0.47 so on and so forth up until 1000 we had a loss of 0.0 so this has really converged and you can check the value of m and c as well so here you can actually do m dot num pi and c dot numpy as well so let's quickly run this again you see the values of 3.5 5.65 so it has reached 5 quickly and it has gone to gone on to you know predict the best possible values of m and c so our original solution was five x plus eight m was five and a c was eight and it has basically predicted the right kind of the right values value is 5.00 and this value of c is 7.97 so it's close to 8. so this is basically the you know the magic behind calculating partial derivatives and how you can do that intense flow so the back end you can imagine the back end of tensorflow how strong it is and how it is computing all such uh gradients and different other uh optimization methods that you see in neural networks so i hope you found this video useful uh you must have gone some idea some intuition of how you know gradients are computed how partial derivative is actually minimizing the loss and you know how to define learning rate how does it speed up your training you know how quickly your model converges so all those kind of things are actually the essence of machine learning how a supervised learning problem is actually solved uh so there's a lot of math that actually runs behind it and this is the reason like i created an applied version of this uh using tensorflow and there'll be a lot more uh sessions on tensorflow that i'd be doing some streaming sessions as well so yeah uh please consider subscribing if you like this one uh do not forget to give this a thumbs up and yeah i will catch you guys in the next one feel free to comment down below catch hold of me or message me on any of the platform twitter linkedin i have provided all the links below so yeah until next time keep learning data science and machine learning

Original Description

Gradient Descent: https://www.ibm.com/cloud/learn/gradient-descent Linear regression: https://www.youtube.com/playlist?list=PLJs7lEb1U5pYnrI0Wn4mzPmppVqwERL_4 Intro to deep learning: You can follow me on: LinkedIn: https://www.linkedin.com/in/tyagiharshit/ Twitter: https://twitter.com/dswharshit Instagram: https://www.instagram.com/upgradewithharshit Medium: https://dswharshit.medium.com/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Harshit Tyagi · Harshit Tyagi · 37 of 60

1 Your PATH to learning Data Science
Your PATH to learning Data Science
Harshit Tyagi
2 Ideal Python environment setup for Data Science projects - Unix shell, Anaconda and Git.
Ideal Python environment setup for Data Science projects - Unix shell, Anaconda and Git.
Harshit Tyagi
3 Building COVID-19 interactive dashboard from Jupyter Notebook | No frontend/backend coding required.
Building COVID-19 interactive dashboard from Jupyter Notebook | No frontend/backend coding required.
Harshit Tyagi
4 Introduction to Jupyter Notebooks - Interface | Ipython Kernel | Sharing | GitHub
Introduction to Jupyter Notebooks - Interface | Ipython Kernel | Sharing | GitHub
Harshit Tyagi
5 Python fundamentals for Data Science - Part  1 | Data types | Strings | Lists
Python fundamentals for Data Science - Part 1 | Data types | Strings | Lists
Harshit Tyagi
6 Python fundamentals for Data Science - Part 2 Dictionaries | Conditionals | Loops | Functions
Python fundamentals for Data Science - Part 2 Dictionaries | Conditionals | Loops | Functions
Harshit Tyagi
7 Python fundamentals for Data Science - Part 3 OOPS | Working with External Libraries & Modules
Python fundamentals for Data Science - Part 3 OOPS | Working with External Libraries & Modules
Harshit Tyagi
8 NumPy Essentials for Data Science - part-1 | One Dimensional Array
NumPy Essentials for Data Science - part-1 | One Dimensional Array
Harshit Tyagi
9 NumPy Essentials for Data Science - part-2 | Multi-Dimensional Array
NumPy Essentials for Data Science - part-2 | Multi-Dimensional Array
Harshit Tyagi
10 Math For Data Science | Practical reasons to learn math for Machine/Deep Learning
Math For Data Science | Practical reasons to learn math for Machine/Deep Learning
Harshit Tyagi
11 Linear Algebra Ep 1 | Introduction to Vectors, Matrices and Tensors using NumPy
Linear Algebra Ep 1 | Introduction to Vectors, Matrices and Tensors using NumPy
Harshit Tyagi
12 Linear Algebra Ep 2 | Dot Product in Linear Algebra for Data Science
Linear Algebra Ep 2 | Dot Product in Linear Algebra for Data Science
Harshit Tyagi
13 Python vs R | The BEST programming language for your Data Science Project
Python vs R | The BEST programming language for your Data Science Project
Harshit Tyagi
14 Linear Algebra for Data Science Ep3 | Identity and Inverse Matrices | NumPy
Linear Algebra for Data Science Ep3 | Identity and Inverse Matrices | NumPy
Harshit Tyagi
15 The Data Show Ep1 | Elucidating Data Science in Drug Discovery - A CTO's Account
The Data Show Ep1 | Elucidating Data Science in Drug Discovery - A CTO's Account
Harshit Tyagi
16 Google Certified TensorFlow Developer | Learning Plan, Tips, FAQs & my Journey
Google Certified TensorFlow Developer | Learning Plan, Tips, FAQs & my Journey
Harshit Tyagi
17 Speeding up your Data Analysis | Hacks & Libraries
Speeding up your Data Analysis | Hacks & Libraries
Harshit Tyagi
18 How to build an Effective Data Science Portfolio
How to build an Effective Data Science Portfolio
Harshit Tyagi
19 End-to-End Machine Learning Project Tutorial - Part 1
End-to-End Machine Learning Project Tutorial - Part 1
Harshit Tyagi
20 Data Preparation with Sci-kit learn and Pandas | End-to-End ML Project Tutorial - Part 2
Data Preparation with Sci-kit learn and Pandas | End-to-End ML Project Tutorial - Part 2
Harshit Tyagi
21 Training and Fine-Tuning ML Models with Sklearn | End-to-End ML Project Tutorial - Part 3
Training and Fine-Tuning ML Models with Sklearn | End-to-End ML Project Tutorial - Part 3
Harshit Tyagi
22 Deploying a Trained ML model via Flask on Heroku | End-to-End ML Project Tutorial - Part 4
Deploying a Trained ML model via Flask on Heroku | End-to-End ML Project Tutorial - Part 4
Harshit Tyagi
23 Three Decades of Practising Data Science | Interview with Dean Abbott
Three Decades of Practising Data Science | Interview with Dean Abbott
Harshit Tyagi
24 Calculating Vector Norms - Linear Algebra for Data Science - IV
Calculating Vector Norms - Linear Algebra for Data Science - IV
Harshit Tyagi
25 Ep1 - Getting Started | Zero to Hero in Computer Vision with TensorFlow
Ep1 - Getting Started | Zero to Hero in Computer Vision with TensorFlow
Harshit Tyagi
26 Ep3 - Designing Data Experiments to enhance your Product | Rapido's Data Science Lead, Pramod N
Ep3 - Designing Data Experiments to enhance your Product | Rapido's Data Science Lead, Pramod N
Harshit Tyagi
27 Building projects with fastai - From Model Training to Deployment
Building projects with fastai - From Model Training to Deployment
Harshit Tyagi
28 October AI - Video Calling with One-Tenth of Internet Bandwidth
October AI - Video Calling with One-Tenth of Internet Bandwidth
Harshit Tyagi
29 November AI - Breakthrough in biology after 50 years | Datasets, books, research papers and more...
November AI - Breakthrough in biology after 50 years | Datasets, books, research papers and more...
Harshit Tyagi
30 Data Science learning roadmap for 2021
Data Science learning roadmap for 2021
Harshit Tyagi
31 Talk is cheap, BUILD - Microsoft Software Engineer | Interview with Abhirath Batra
Talk is cheap, BUILD - Microsoft Software Engineer | Interview with Abhirath Batra
Harshit Tyagi
32 Building a Habit of Reading Research Papers | Ft. Anurag Ghosh(Microsoft Researcher)
Building a Habit of Reading Research Papers | Ft. Anurag Ghosh(Microsoft Researcher)
Harshit Tyagi
33 Tableau vs Python - Building a COVID tracker dashboard
Tableau vs Python - Building a COVID tracker dashboard
Harshit Tyagi
34 [Explained] What is MLOps | Getting started with ML Engineering
[Explained] What is MLOps | Getting started with ML Engineering
Harshit Tyagi
35 Dmitry Petrov - Creator of DVC | ML Systems, Teams, Scaling challenges, and Learning Data Science
Dmitry Petrov - Creator of DVC | ML Systems, Teams, Scaling challenges, and Learning Data Science
Harshit Tyagi
36 Five hard truths about building a career in Data Science
Five hard truths about building a career in Data Science
Harshit Tyagi
Computing gradients using TensorFlow | Training a Linear Regression model from scratch.
Computing gradients using TensorFlow | Training a Linear Regression model from scratch.
Harshit Tyagi
38 Foundations for Data Science & ML - First steps for every beginner!
Foundations for Data Science & ML - First steps for every beginner!
Harshit Tyagi
39 Course Outline - Foundations for Data Science & ML
Course Outline - Foundations for Data Science & ML
Harshit Tyagi
40 How Machine Learning uses Linear Algebra to solve data problems
How Machine Learning uses Linear Algebra to solve data problems
Harshit Tyagi
41 Calculus for ML - How much you should know to get started
Calculus for ML - How much you should know to get started
Harshit Tyagi
42 Building a buzzing stocks news feed using NLP and Streamlit | Named Entity Recognition & Linking
Building a buzzing stocks news feed using NLP and Streamlit | Named Entity Recognition & Linking
Harshit Tyagi
43 AI Engineer - The next big tech role!
AI Engineer - The next big tech role!
Harshit Tyagi
44 AI researcher vs AI engineer | The next big tech role!
AI researcher vs AI engineer | The next big tech role!
Harshit Tyagi
45 Reviewing LLMs for content creation
Reviewing LLMs for content creation
Harshit Tyagi
46 Building a chatGPT-like bot on WhatsApp #coding  #chatgpt #engineering
Building a chatGPT-like bot on WhatsApp #coding #chatgpt #engineering
Harshit Tyagi
47 High Signal AI - the most action-oriented newsletter on the web! #ai
High Signal AI - the most action-oriented newsletter on the web! #ai
Harshit Tyagi
48 Building an AI-powered Discord Chatbot Locally for FREE using Ollama
Building an AI-powered Discord Chatbot Locally for FREE using Ollama
Harshit Tyagi
49 Build a second brain with Khoj 🧠  #ai #obsidian #plugins #productivity #engineering #notes
Build a second brain with Khoj 🧠 #ai #obsidian #plugins #productivity #engineering #notes
Harshit Tyagi
50 Summarising YouTube Videos using Ollama on Discord | Becoming an AI Engineer - Ep 2
Summarising YouTube Videos using Ollama on Discord | Becoming an AI Engineer - Ep 2
Harshit Tyagi
51 Watch the full video on my channel - Roadmap to become an AI Engineer.
Watch the full video on my channel - Roadmap to become an AI Engineer.
Harshit Tyagi
52 Mesop - Python-based UI framework from Google!
Mesop - Python-based UI framework from Google!
Harshit Tyagi
53 How I automated my YouTube | Gumloop tutorial | No Code
How I automated my YouTube | Gumloop tutorial | No Code
Harshit Tyagi
54 ARC PRIZE - Win $1Million to Beat the ARC-AGI benchmark
ARC PRIZE - Win $1Million to Beat the ARC-AGI benchmark
Harshit Tyagi
55 Microsoft's Autogen vs CrewAI - tested on a diverse range of use cases
Microsoft's Autogen vs CrewAI - tested on a diverse range of use cases
Harshit Tyagi
56 Claude #AI artifacts are just amazing!
Claude #AI artifacts are just amazing!
Harshit Tyagi
57 OpenAI releases CriticGPT to correct GPT-4's mistakes | Read the paper with me
OpenAI releases CriticGPT to correct GPT-4's mistakes | Read the paper with me
Harshit Tyagi
58 Day in my life | Vlog #1
Day in my life | Vlog #1
Harshit Tyagi
59 How to add AI Copilot to your application using CopilotKit | Tutorial
How to add AI Copilot to your application using CopilotKit | Tutorial
Harshit Tyagi
60 Quick Questions with an AI Founder - Anudeep Yegireddi
Quick Questions with an AI Founder - Anudeep Yegireddi
Harshit Tyagi

This video teaches how to train a linear regression model from scratch using TensorFlow and compute gradients using Gradient Tape. It covers key concepts such as linear regression, gradient descent, and automatic differentiation, and provides a practical example of how to implement these concepts in code.

Key Takeaways
  1. Create a simple linear regression model using TensorFlow
  2. Define a training loop to optimize model parameters
  3. Compute gradients using TensorFlow's Gradient Tape feature
  4. Perform partial derivatives to optimize model parameters
  5. Update the values of model parameters using the learning rate
  6. Print the loss and values of model parameters at regular intervals
💡 The video demonstrates how to use TensorFlow's Gradient Tape feature to compute gradients and perform partial derivatives to optimize model parameters, which is a key concept in machine learning.

Related AI Lessons

Mastering TypeScript — Understanding the TypeScript Compiler (tsc) from Scratch — Lesson 2
Learn the basics of the TypeScript compiler to write better JavaScript code
Medium · JavaScript
Stop Overfitting With Basically One Line of Code
Learn to prevent overfitting with a simple code tweak and understand the difference between Ridge and Lasso regression
Medium · AI
Stop Overfitting With Basically One Line of Code
Learn to prevent overfitting in machine learning models with a simple code tweak and understand the difference between Ridge and Lasso regression
Medium · Machine Learning
Stop Overfitting With Basically One Line of Code
Prevent overfitting in models with a simple code tweak, understanding the difference between Ridge and Lasso regression
Medium · Data Science
Up next
Learn Deep Learning by Hand (Beginner's Guide - Part 1)
Thu Vu
Watch →