Linear Regression in 2 Minutes (using PyTorch)

Sanyam Bhutani
HackerNoon.com
Published in
2 min readJan 14, 2018

--

You can find all the accompanying code in this Github repo

This is Part 2 of the PyTorch Primer Series.

Linear Regression is linear approach for modeling the relationship between inputs and the predictions

Source: Wikipedia

We find a ‘Linear fit’ to the data.

Fit: We are trying to predict a variable y, by fitting a curve (line here) to the data. The curve in linear regression follows a linear relationship between the scalar (x) and dependent variable.

Creating Models in PyTorch

  1. Create a Class
  2. Declare your Forward Pass
  3. Tune the HyperParameters

Steps

  1. Create instance of model
  2. Select Loss Criterion
  3. Choose Hyper Parameters

Training The Model

Finally, Print the Predicted Values

If you want to read about Week 2 in my Self Driving Journey, here is the blog post

The Next Part in the Series will discuss about Linear Regression.

You can find me on Twitter @bhutanisanyam1, connect with me on Linkedin here

Subscribe to my Newsletter for a weekly curated list of Deep Learning and Computer Vision Reads

--

--

Sanyam Bhutani
HackerNoon.com

Machine Learning Engineer and AI Content Creator at H2O.ai, Fast.ai Fellow, Kaggle x3 Expert (Ranked in Top 1%), Twitter: https://twitter.com/bhutanisanyam1