Linear Regression (PyTorch) Exercise

Programming for Data Science is a subject we’ve designed to explore the various programming components of data science.
Author

Juma Shafara

Published

August 29, 2024

Keywords

data science, data analysis, programming, dataidea

Photo by DATAIDEA

Week 3: Linear Regression in PyTorch (4 Questions)

1. Stochastic Gradient Descent

  • Exercise: Implement a linear regression model using stochastic gradient descent (SGD) on a synthetic dataset. Plot the loss curve to show convergence over iterations.

2. Mini-Batch Gradient Descent

  • Exercise: Modify your SGD implementation to use mini-batch gradient descent. Train the model on a dataset with mini-batches and compare the performance with the full-batch SGD approach.

3. PyTorch Built-in Functions

  • Exercise: Use PyTorch’s built-in functions (torch.nn.Linear, torch.optim.SGD) to build and train a linear regression model. Compare the results with your previous implementations.

4. Training and Validation Sets

  • Exercise: Split your dataset into training and validation sets. Train a linear regression model on the training set and evaluate its performance on the validation set. Plot the training and validation loss over epochs.

What’s on your mind? Put it in the comments!

Back to top