Work in progress

This commit is contained in:
2025-09-29 08:59:47 +02:00
parent 8a2a9d1064
commit b93df4af0f
26 changed files with 22986 additions and 0 deletions

View File

@ -0,0 +1,46 @@
"""
Column Meaning
crim Per capita crime rate by town
zn Proportion of residential land zoned for lots over 25,000 sq.ft.
indus Proportion of non-retail business acres per town
chas Charles River dummy variable (1 if tract bounds river, 0 otherwise)
nox Nitric oxides concentration (parts per 10 million)
rm Average number of rooms per dwelling
age Proportion of owner-occupied units built prior to 1940
dis Weighted distances to five Boston employment centers
rad Index of accessibility to radial highways
tax Full-value property-tax rate per $10,000
ptratio Pupil-teacher ratio by town
black 1000(Bk - 0.63)^2, where Bk is the proportion of Black people by town
lstat % lower status of the population
medv Median value of owner-occupied homes in $1000s (target variable)
"""
import pandas as pd
import torch
import torch.nn as nn
df = pd.read_csv("./RegressionModels/BostonHousing/Boston.csv")
# print(df.iloc[:,0:14])
X = torch.tensor(df.iloc[:,0:14].values, dtype=torch.float32)
Y = torch.tensor(df["medv"].values, dtype=torch.float32)
model = torch.nn.Sequential(
torch.nn.Linear(14, 1)
)
loss_fn = torch.nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(), lr=5e-9)
for epoch in range(2000):
predict_y = model(X)
loss = loss_fn(predict_y, Y)
optimizer.zero_grad()
loss.backward()
optimizer.step()
if epoch % 99 ==0:
print(f'Epoch: {epoch}, Loss: {loss.item():.2f}')