2022-10-25

How to apply 1/σ^2 weight matrix to find Weighted Least Squares Solution

I am trying to solve a Weighted Least Squares problem on Python (using numpy) but I am unsure on how to apply the following weight

enter image description here

on enter image description here

This is what i have done so far

import numpy as np
import matplotlib.pyplot as plt

X = np.random.rand(50) #Generate X values 
Y = 2 + 3*X + np.random.rand(50) #Y Values
plt.plot(X,Y,'o')
plt.xlabel('X')
plt.ylabel('Y')
W = ?? 
X_b = np.c_[np.ones((50,1)), X] #generate [1,x]
beta = np.linalg.inv(X_b.T.dot(W).dot(X_b)).dot(X_b.T).dot(W).dot(Y)


No comments:

Post a Comment