Skip to content

Commit c64f8cd

Browse files
Merge pull request #7 from codebygarrysingh/lin-regression-toolkit-py
Added regression toolkit util file and restructured branch
2 parents 626dc88 + 58a8555 commit c64f8cd

9 files changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# -- Sheet --
4+
5+
# **This is a toolkit lib file covering standard linear regression functions**
6+
7+
8+
# let's import all necessary libraries
9+
import numpy as np
10+
import matplotlib.pyplot as plt
11+
import math, copy
12+
13+
# let's define the first function for calculating y predict value
14+
15+
def compute_dep_var(x, w, b):
16+
17+
# an easier implementation would be to use a dot product np.dot(x, w) + b
18+
dot_prod = 0
19+
for i in range(x.shape[0]): # loop through all rows
20+
dot_prod += x[i] * w[i]
21+
22+
dep_var = dot_prod + b
23+
24+
return dep_var
25+
26+
def test_compute_dep_var():
27+
28+
# define sample x training data
29+
x_train = np.array([952,2,1,65])
30+
w_train = np.array([0.0005,1,1,1])
31+
b_train = 500
32+
33+
pred_val = compute_dep_var(x_train, w_train, b_train)
34+
35+
print(f"Predicted value is: {pred_val}")
36+
37+
38+
test_compute_dep_var()
39+
40+
41+

0 commit comments

Comments
 (0)