Question: Part 1: Defining cost functions We need to define cost functions before creating a linear regression model to calculate the error between our prediction and

Part 1: Defining cost functions

We need to define cost functions before creating a linear regression model to calculate the error between our prediction and the true values. We will define two cost functions: Mean Squared Error (MSE) and Mean Absolute Error (MAE).

Task 1.1: Mean Squared Error (MSE)

Write the function mean_squared_error(y_true, y_pred) that returns a number representing the mean squared error of the predictions.

The formula for Mean Squared Error is as follows:

Part 1: Defining cost functions We need to define cost functions before

Hint: Consider using np.square or np.power.

The formula for Mean Squared Error is as follows: MSE(y,y^)=2m1i=1m(y^iyi)2 where y is the vector with actual values, y^ is the prediction vector, and m is the number of samples in the training data

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!