Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To add a bias term, we will add a new column to our X matrix that is full of constants. Does it matter what constant

To add a bias term, we will add a new column to our X matrix that is full of constants.

Does it matter what constant term we choose?

The simplest way to do this is to use hstack which takes in a list of matrices and horizontally concatenates them (i.e. adds on new columns -- there exists a vstack that adds new rows). The simpleest way to construct a constant term is to use np.ones which takes in a list with the number of ones to make for each dimension.

e.g. np.ones([4,2]) will make

1 1

1 1

1 1

1 1

#TODO construct an X matrix with a bias term.

X_with_bias = np.zeros(10)

X_validation_with_bias = np.zeros(10)

#TODO replace the np.zeros() with the correct code

B_with_bias = calculate_weights_with_library(X_with_bias,Y)

Yhat_with_bias = calculate_yhat(X_with_bias, B_with_bias)

Yhat_validation_with_bias = calculate_yhat(X_validation_with_bias, B_with_bias)

residuals_with_bias = calculate_residuals(Y, Yhat_with_bias)

residuals_validation_with_bias = calculate_residuals(Y_validation, Yhat_validation_with_bias)

rmse_with_bias = calculate_rmse(residuals_with_bias)

rmse_validation_with_bias = calculate_rmse(residuals_validation_with_bias)

print('RMSE with bias term:',rmse_with_bias)

print('RMSE Validation with bias term:',rmse_validation_with_bias)

plt.plot(Y,residuals_with_bias,'x')

plt.plot(Y_validation,residuals_validation_with_bias,'ro')

plt.show()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

Students also viewed these Databases questions