Created
October 16, 2019 06:19
-
-
Save tranductam2802/8d383f3e8bd3856392a6acb97284522b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# w = (A^T)^+b = ((X^T)X)^+(X^T)y | |
import numpy as np | |
import matplotlib.pyplot as plt | |
x = [0, 1, 2] | |
X = np.array([x]).T | |
y = [0, 1, 2] | |
Y = np.array([y]).T | |
# Building Xbar | |
one = np.ones((X.shape[0], 1)) | |
Xbar = np.concatenate((one, X), axis = 1) | |
# Calculating weights of the fitting line | |
A = np.dot(Xbar.T, Xbar) | |
b = np.dot(Xbar.T, y) | |
w = np.dot(np.linalg.pinv(A), b) | |
# Preparing the fitting line | |
w_0 = w[0][0] | |
w_1 = w[1][0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment