Linear Regression in 2 Minutes (using PyTorch)
Sanyam Bhutani
3992

I’m glad I came across your example to get started with a simple regression, but after looking at the torch code, I realize it drove me down a much more complex solution than is really necessary:

You don’t need to create your own class, torch has one out of the box: nn.Linear

Per the docs example:

>>> m = nn.Linear(20, 30)
>>> input = torch.randn(128, 20)
>>> output = m(input)

Also, you’re training and testing the same set, of course it will look right.

Finally, you’re not including `bias` which is available in the nn.Linear class

I’m glad I came across this that pointed me to nn.Linear, but just use that and it’s not Linear Regression in 2minutes but rather 20sec…