Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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:
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 dataStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started