From a1643975ba4c92707a59ec0da6375e609fc23e7b Mon Sep 17 00:00:00 2001 From: JaredTritt Date: Wed, 17 Sep 2025 15:03:21 -0400 Subject: [PATCH] Updated linear regression --- linear-regression-parkinsons.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/linear-regression-parkinsons.py b/linear-regression-parkinsons.py index e8c6f1e..bcb6f7e 100644 --- a/linear-regression-parkinsons.py +++ b/linear-regression-parkinsons.py @@ -1,2 +1,26 @@ import pandas as pd +import matplotlib.pyplot as plt + + +class LinearRegression: + def __init__(self, add_bias = True) + self.add_bias = add_bias + pass + + def fit(self,x,y): + if x.dim == 1: + x = x[:,None] + N = x.shape[0] + if self.add_bias: + x = np.column_stack ([x,np.ones(N)]) + self.w = np.linalg.lstsq(x,y)[0] + return self + + def predict(self,x) + if self.add_bias: + x = np.column_stack ([x,np.ones(N)]) + yh = x@self.w + return yh + +