28 lines
521 B
Python
28 lines
521 B
Python
|
#!/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)
|