Question: Please follow the instracions and implement codes Now we want to test our coefficients and see how well we predict the answer. To do with
Please follow the instracions and implement codes
Now we want to test our coefficients and see how well we predict the answer. To do with we will need to use the weight vector we just learned. Use np.dotto calculate:
Y =XY^=X
We will then calculate the residual the error that remains between our true times in Y and the calculated times in Yhat.
resid=YY resid=YY^
We will then use these residuals to come up with a single number that tells us how well we did. For this, we will be using the Root Mean Squared Error (RMSE)
RMSE=1N(yy)^2RMSE=1N(yy^)2
To use, this we will use the elementwise multiplication (a*b not np.dot(a,b)), the square root (np.sqrt), and mean (np.mean) functions
#TODO: Calculate Yhat, the residuals and RMSE for both the training and validation sets
def calculate_yhat(X: np.array, B: np.array) -> np.array: return None
def calculate_residuals(Y: np.array, Yhat: np.array) -> np.array: return None
def calculate_rmse(residuals: np.array) -> float: return 0
Yhat = calculate_yhat(X, B_raw) Yhat_validation = calculate_yhat(X_validation, B_raw)
residuals = calculate_residuals(Y, Yhat) residuals_validation = calculate_residuals(Y_validation, Yhat_validation)
rmse = calculate_rmse(residuals) rmse_validation = calculate_rmse(residuals_validation)
print('RMSE:',rmse) print('RMSE Validation:',rmse_validation)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
