tau-2020-pytorch-tutorial/pytorch3.py
2020-12-09 10:12:35 +01:00

28 lines
521 B
Python
Executable File

#!/usr/bin/python3
import torch
import pandas
data = pandas.read_csv('mieszkania.tsv', sep='\t')
x = torch.tensor(data['powierzchnia'], dtype=torch.float)
y = torch.tensor(data['cena'], dtype=torch.float)
w = torch.rand(1, requires_grad=True)
learning_rate = torch.tensor(0.0000001)
for _ in range(100):
ypredicted = w * x
cost = torch.sum((ypredicted - y) ** 2)
print(w, " => ", cost)
cost.backward()
with torch.no_grad():
w = w - learning_rate * w.grad
w.requires_grad_(True)