Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Now it's time to use the functions defined above to make a prediction using our housing dataset. For this question, define two empty NumPy arrays,

Now it's time to use the functions defined above to make a prediction using our housing dataset. For this question, define two empty NumPy arrays, mu and big_sig. Next, define the y target by using the variable "SalePrice" and the input X by using the variables "GrLivArea" and "YearBuilt" as predictors. NOTE: For grading purposes, keep "GrLivArea" and "YearBuild", in that order and use all the observations in data by using the function .values. Set =0.1 = 0.1 Compute the wMAP vector and assign the result to the variable mu. Finally, compute the matrix and assign the result to big_sig. HINT: Note that, for this question, you will have to use all the functions you have defined in the previous questions exept for the one you have defined in Question 8.

###From Prior questions

def calculate_map_coefficients(input_x, output_y, lambda_param, sigma_squared):

xT = np.transpose(aug_x) lambda_mul_singma = lambda_param * sigma_squared; fist_inv = np.linalg.inv(lambda_mul_singma + np.matmul(xT, aug_x)) mu = np.matmul(np.matmul(fist_inv, xT), output_y) return coef

def estimate_data_noise(aug_x, output_y, weights):

n = len(aug_x[:, 0]) d = len(aug_x[0, :]) diff = [] for element in range(len(output_y)): print(element) diff.append((output_y[element] - aug_x[element] @ weights) ** 2) return sum(diff) / (n - d)

def calc_post_cov_mtx(aug_x, sigma_squared, lambda_param):

xT=np.transpose(aug_x) sigmaroot=1/sigma_squared I = np.identity(len(aug_x[0,:])) big_sigma = np.linalg.inv(lambda_param*I + sigmaroot*(np.matmul(xT, aug_x))) return big_sigma

### GRADED ### YOUR ANSWER BELOW

""" Example: input_x = data[['GrLivArea','YearBuilt']].head(100).values output_y = data['SalePrice'].head(100).values lambda_param = .1 < --- CODE BLOCK ---> print(mu) #--> np.array([2.10423243e-02, 4.10449281e+01, 4.22635006e+01]) print(big_sig) #--> np.array([[ 9.99999861e+00, -1.75179751e-03, -2.74204060e-03], [-1.75179751e-03, 6.50420674e+00, -3.47271893e+00], [-2.74204060e-03, -3.47271893e+00, 4.60297584e+00]]) """

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

Relational Database Technology

Authors: Suad Alagic

1st Edition

354096276X, 978-3540962762

More Books

Students also viewed these Databases questions