How Linear Regression model works using Pytorch

Linear regression is the most important practice in data science. It is used to predict the relationship between the dependent and independent variables.

In this article, I am going to show you how a simple linear regression model works using easy PyTorch functions. I’ve used google-collab to run the notebooks and imported jovian files. Jovian is a great learning platform for data science and machine learning. Their platform is great for performing machine learning.

We'll create a simple model that predicts student scores that is related to the time they spent studying.

Data that we’ll use for training the model:

Our basic job is to find the weight(m) and biases(b). For our model, we can describe relation as

y=mx+b

let just first represent our data into two matrices input(X) and targets(y)

We have used x to store inputs and y to store the biases

For weights and biases, the basic idea is to randomize them and compare them with targets and adjust them accordingly. To gain the values of m and b we will use the gradient descent method. In it we generate predictions, calculate loss then find gradients concerning the weights and biases then adjust the parameters by subtracting a small part to the gradient Gradient will represent a change in the loss. 

The learning rate can be changed on the time you want your data to be trained. A low learning rate would  take time but will give us more precise  predictions 

After storing the values of m and b let's predict the values

 
Looking at our original dataset predictions are not precise but are pretty similar which shows our model works. 


.


References: 





Gatish Priyadarshi (2019-2023)

Computer Science Department
KIET Group of Institutions



Comments

Popular posts from this blog

QUANTUM STORAGE & MEMORY

QUANTUM COMPUTING: CAN FIGHT CLIMATE CHANGE

BLOCKCHAIN: HOW IT WORKS AND WHY SO POPULAR