This project serves as a step-by-step introduction to the PyTorch deep learning workflow, demonstrating how a simple neural network learns the pattern of a straight line (y = weight * x + bias).
It implements the full cycle of data preparation, model construction, training, evaluation, and saving/loading, following a device-agnostic approach (works on both CPU and GPU).
A deep learning workflow typically involves these steps:
- Data Preparation: Create and split the dataset (training, testing).
- Model Building: Define the neural network architecture.
- Loss Function & Optimizer: Define how the model measures errors (Loss) and how it updates its parameters to reduce those errors (Optimizer).
- Training Loop: The iterative process of Forward Pass, Loss Calculation, Backpropagation, and Optimizer Step.
- Inference: Using the trained model to make predictions.
- Saving/Loading: Persisting the learned parameters.
linear_regression_pytorch.py: The main, self-contained Python script implementing the entire workflow.requirements.txt: Lists necessary Python libraries.
You need Python (3.8+) and the following libraries:
torch
matplotlib
-
Clone the repository:
git clone https://github.com/Rahmat-ML/PyTorch-Linear-DNN-Fundamentals cd PyTorch-Linear-DNN-Fundamentals -
Install dependencies:
pip install -r requirements.txt -
Run the script:
python linear_regression_pytorch.pyThe script will print training progress, model parameters, and save plots/the final model state.