0% found this document useful (0 votes)
11 views1 page

Linear Regression Assignment Overview

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Linear Regression Assignment Overview

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Programming Assignment 1

Linear Regression using numpy


We will be using ipython notebooks for most of our assignments. You can refer
[Link] for installing the required software for working with
ipython notebooks and getting started with it. We will be using python ​2.7, ​so, please make sure
that the version you are using aligns with the that.
This assignment consist of a python notebook that depicts the outline of using linear regression
to learn a linear mapping function to map input data to the output. The function should be
learned with the objective to minimize the Mean Square Error (MSE) loss between the predicted
output and the ground truth data. The dataset for training and testing is being generated
randomly using a fixed seed. You have to fill all the missing parts which is indicated using
question marks (?) and hints wherever required (Use numpy operations wherever possible).
Please don't declare any function other than given in the notebook. The functions have their
usual meanings and is described below in brief. Some of the functions are partially implemented
and some of them are left for you to complete it.
● generate_dataset()​: It generates the dataset on the fly, to be used for training and
testing purposes.
● LinearRegression::forward()​: It computes the output using parameters of the network
and the input data. This is also called a forward pass of the linear regression network.
● LinearRegression::backward()​: It computes the gradients for every parameter of the
network and update the corresponding parameter using gradient descent step. This is
also called a backward pass as a prediction has been made and now the network is
updated accordingly, so as to minimize the loss function.
● MSELoss()​: It computes the Mean Squared Loss between the predicted output and
ground truth data. The formula for calculating the same has been discussed in the
lecture.
The algorithm to implement is mentioned in the comments, you have to use ​only ​numpy and
basic python functions and ​no​ other imports are allowed.

Submission: ​You have to submit a ipython notebook with the ​.ipynb​ extension. Please make
sure that all the cells are running. Please use the given ​Assignment_1.ipynb​ as a starting point
by uploading it to the jupyter notebook. You can complete the assignment gradually by
completing every cell and execute it in the order given. After completing the assignment, please
make sure that you are able to:
● visualize a plot between the loss function and training epochs.
● get training and test loss.
● visualize a learned function on the test data. This will be a plot where the test data will be
plotted as blue points and the red line indicates the learned function.
Outline of the results mentioned above has been implemented in the notebook, you just have to
complete the blanks. Please submit the completed file named as '​Assignment1_<Roll
No>.ipynb​'.

Common questions

Powered by AI

The primary objective of using linear regression in the programming assignment is to learn a linear mapping function that maps input data to the output, specifically with the goal of minimizing the Mean Square Error (MSE) loss between predicted outputs and ground truth data. This is achieved using several functions outlined in the assignment. The 'generate_dataset()' function creates training and testing datasets. The 'LinearRegression::forward()' computes outputs based on input data and model parameters. The 'LinearRegression::backward()' computes gradients for each model parameter and updates them through gradient descent to reduce the loss function, thereby refining the model to achieve the objective .

The final assignment file should be named following the format 'Assignment1_<Roll No>.ipynb' for submission. Adhering to this detail is important to ensure that submissions are easily identifiable and organized effectively by the instructor or automated systems processing the assignments. A standardized naming convention prevents confusion and facilitates easy reference and assessment, ensuring that each student's work is attributed correctly .

The expected outcomes after completing the programming assignment on linear regression include being able to visualize a plot between the loss function and training epochs, obtaining training and test loss values, and visualizing the learned function on the test data. The latter involves plotting the test data as blue points and the learned function as a red line. These outcomes are crucial for understanding and evaluating the performance of the linear regression model concerning its ability to predict outcomes accurately .

Visualizing the plot between the loss function and training epochs is important as it provides insight into the training process's convergence behavior. This plot helps identify whether the model is learning effectively by observing the decrease in loss over time. It can highlight issues such as underfitting or overfitting and guide adjustments to model parameters and training duration for optimal performance. Such visual feedback is crucial for refining and validating the machine learning model .

It is crucial to use numpy operations specifically because numpy is optimized for efficient numerical computations, which are core to implementing linear regression. Numpy offers powerful array operations that provide both speed and ease of use compared to raw Python loops, enabling efficient data handling and manipulation. This efficiency is vital when performing matrix operations required in gradient computation and backpropagation, which are computationally expensive tasks in machine learning models .

Plotting the test data and learned function is significant because it visually demonstrates how well the model has learned to predict outputs from unseen input data. By showing the test data as points and the learned function as a line, it allows for an intuitive assessment of predictive alignment. If the red line (the learned function) closely follows the trend of the test data points, it indicates good model generalization. This visualization helps in understanding where the model excels or where discrepancies occur, aiding in performance evaluation and further model optimization .

Using a fixed seed for generating the dataset ensures that the same set of random numbers is produced each time, providing consistency and reproducibility in the dataset across different executions. This consistency is crucial for comparing different implementations or modifications to the model, as it allows for direct performance comparisons under identical conditions, removing the variability that could mislead analysis or evaluation outcomes .

The constraint to use only numpy and basic python functions affects the approach by limiting the use of external libraries or built-in advanced features that could simplify implementation. This requirement encourages deeper understanding and manual implementation of fundamental operations such as matrix multiplications, loss calculations, and gradient descent updates. It fosters a better grasp of the underlying mechanics of linear regression and promotes learning through simplicity, ensuring comprehension of each computational step involved .

The 'generate_dataset()' function plays the role of dynamically creating datasets that are used for both training and testing the linear regression model. This function generates random data using a fixed seed, ensuring the reproducibility of the dataset across different runs. Having a consistent dataset is essential for effectively evaluating the performance and adjustments of the linear regression model throughout the training process .

The backward pass in linear regression minimizes the Mean Square Error (MSE) loss by computing the gradients of the loss with respect to each parameter in the model. These gradients indicate how changes in each parameter affect the overall loss. By applying the gradient descent algorithm, parameters are iteratively updated in the direction that reduces the loss, eventually leading to a minimized MSE. This systematic update of parameters ensures the model's predictions become more accurate over time .

You might also like