Challenge

Supervised Learning - Prediction Week 3 Challenge

Q1. Perform Gradient Descent in Python with any loss function

Answer: In machine learning, the goal is to predict the target variable as close to the ground truth as possible. Thus, the model we adopt for prediction should have reasonable accuracy. As the input values are fixed, to improve the quality of the model, all we can do is tune its parameters such that the deviation of the predicted value from the actual value is highly minimized.

The variation of the expected value from the actual value on a single training example is called the loss function.

The loss function to be used is the mean square error which is defined as

where n = total number of data points

= Actual outcome

= predictive outcome

Linear Regression - Gradient Descent

let's write prediction y as mx+b

Q2.Difference between L1 & L2 Gradient descent method

Answer: The two major loss functions are:

. Mean Absolute Error

n = total number of data points
= predicted outcome
= actual outcome
The gradient descent performed using MAE is known as the L1 norm whereas the gradient descent using MSE is known as the L2 norm.
. L12 vs L2 differences
. AS L1 involves error, the error obtained for outlier data points is smaller as compared to the mean square error. As the aim of the gradient descent method is to reduce/lose function, MAE or L1 norm is preferred for datasets with outliers.
Q3.What are the different loss functions for regression?
Answer: The different loss functions are:
....... Mean Absolute Error
......Mean square error
...... Root mean square error
Q4.) What is the importance of the learning rate
Answer: Learning rate is a hyper-parameter that controls how much we are adjusting the weights of our network with respect to the loss gradient. The lower the value, the slower we travel along the downward slope. While this might be a good idea (using a low learning rate) in terms of making sure that we do not miss any local minima, it could also mean that we’ll be taking a long time to converge — especially if we get stuck on a plateau region.

The following formula shows the relationship.

new_weight = existing_weight — learning_rate * gradient



Gradient descent with small (top) and large (bottom) learning rates


Typically learning rates are configured naively at random by the user. At best, the user would leverage on past experiences (or other types of learning material) to gain the intuition on what is the best value to use in setting learning rates.

As such, it’s often hard to get it right. The below diagram demonstrates the different scenarios one can fall into when configuring the learning rate.



Furthermore, the learning rate affects how quickly our model can converge to a local minima (aka arrive at the best accuracy). Thus getting it right from the get go would mean lesser time for us to train the model.

Less training time, lesser money spent on GPU cloud compute. :)

Q5. How to evaluate linear regression
Model evaluation is very important in data science. It helps you to understand the performance of your model and makes it easy to present your model to other people. There are many different evaluation metrics out there but only some of them are suitable to be used for regression.

There are 3 main metrics for model evaluation in regression:

1. R Square/Adjusted R Square

2. Mean Square Error(MSE)/Root Mean Square Error(RMSE)

3. Mean Absolute Error(MAE)

R Square/Adjusted R Square

R Square measures how much variability in dependent variable can be explained by the model. It is the square of the Correlation Coefficient(R) and that is why it is called R Square.


Mean Square Error(MSE)/Root Mean Square Error(RMSE)

While R Square is a relative measure of how well the model fits dependent variables, Mean Square Error is an absolute measure of the goodness for the fit.


Mean Absolute Error(MAE)

Mean Absolute Error(MAE) is similar to Mean Square Error(MSE). However, instead of the sum of the square of error in MSE, MAE is taking the sum of the absolute value of error.


Q6. What is the difference between multiple and adjusted coefficient of determination
Answer:When the linear regression involves one dependent variable and one independent variable , the regression model is evaluated by or coefficient of determination.
In case of data set with one dependentvariable and several independent variable. the model is evaluated using multiple coefficient of determination.

when the regression model is not influenced by some of the independent variables, we opt for adjusted coefficient of determination.
Any addition of data point where the independent variable can be ignored does not affect the value of


n = number of data points
k = number of independent variables



Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.