From 5582d27997cf47d61ea8b2175eb92eccf296e7db Mon Sep 17 00:00:00 2001 From: Krzysztof Rudnicki Date: Sat, 13 May 2023 12:55:04 +0200 Subject: [PATCH] feat: comment before class --- lab5/code/main.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lab5/code/main.py b/lab5/code/main.py index 734a86a0..bb0f262a 100644 --- a/lab5/code/main.py +++ b/lab5/code/main.py @@ -1,14 +1,28 @@ +# numpy for loading dataset import numpy as np +# pytorch for deep learning models import torch import torch.nn as nn import torch.optim as optim -# load the dataset, split into input (X) and output (y) variables +# Pima indians describes pateitn medical data and whether they had diabetes for last 5 years +# It is binary classification (they could either have diabetes 1 or not 0) +# load the file as a matrix of numbers, dataset = np.loadtxt('pima-indians-diabetes.csv', delimiter=',') +# split into input (X) -> in this case everything beside info whether patient had diabetes or not is input +# We are spliting data into two subsets by using NumPy slie operator : and choose first 8 columns using 0:8 slice X = dataset[:,0:8] +# and output (y) variables -> in this case we are only interested whether patient had diabetes or not as an output +# you can simplify that y = f(X) +# We are spliting the data by using slice operator : and choosing last column y = dataset[:,8] +# we need to convert this data to pytorch tensors +# Pyutoarch usually operates on 32-bit floating point and NumPy by default uses 64 bit floating point X = torch.tensor(X, dtype=torch.float32) +# We can also correct the shape to fit what PyTorch would expect (here we are converting n vectors to n x 1 matrix) +# This simplifies handling matrix multiplication operations (which are the basis of deep learning models) +# reshape is converting the output variable y from a 1-dimensional NumPy array to a 2-dimensional PyTorch tensor with a shape of (n, 1), where n is the number of samples in the dataset. y = torch.tensor(y, dtype=torch.float32).reshape(-1, 1) # define the model