Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8c78df0

Browse files
committedSep 3, 2024·
added-handling-function-to-linear-regression
1 parent 38324a8 commit 8c78df0

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed
 

‎machine_learning/linear_regression.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,26 @@ def collect_dataset():
1717
The dataset contains ADR vs Rating of a Player
1818
:return : dataset obtained from the link, as matrix
1919
"""
20-
response = requests.get(
20+
try:response = requests.get(
2121
"https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/"
2222
"master/Week1/ADRvsRating.csv",
2323
timeout=10,
24-
)
25-
lines = response.text.splitlines()
26-
data = []
27-
for item in lines:
28-
item = item.split(",")
29-
data.append(item)
30-
data.pop(0) # This is for removing the labels from the list
31-
dataset = np.matrix(data)
32-
return dataset
33-
24+
)
25+
lines = response.text.splitlines()
26+
data = []
27+
for item in lines:
28+
item = item.split(",")
29+
data.append(item)
30+
data.pop(0) # This is for removing the labels from the list
31+
dataset = np.matrix(data)
32+
return dataset
33+
34+
except requests.exceptions.RequestException as e:
35+
print(f"Error fetching the dataset: {e}")
36+
return None
37+
except Exception as e:
38+
print(f"Unexpected error: {e}")
39+
return None
3440

3541
def run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta):
3642
"""Run steep gradient descent and updates the Feature vector accordingly_
@@ -112,6 +118,10 @@ def main():
112118
for i in range(len_result):
113119
print(f"{theta[0, i]:.5f}")
114120

115-
121+
import doctest
116122
if __name__ == "__main__":
117123
main()
124+
doctest.testmod()
125+
126+
127+

0 commit comments

Comments
 (0)
Please sign in to comment.