Skip to content

Commit 30d76e9

Browse files
committed
Added_Error_Handling_for_linear_regression
1 parent 38324a8 commit 30d76e9

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

machine_learning/linear_regression.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,28 @@ 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:
21+
response = requests.get(
2122
"https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/"
2223
"master/Week1/ADRvsRating.csv",
2324
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
25+
)
26+
27+
lines = response.text.splitlines()
28+
data = []
29+
for item in lines:
30+
item = item.split(",")
31+
data.append(item)
32+
data.pop(0) # This is for removing the labels from the list
33+
dataset = np.matrix(data)
34+
return dataset
35+
36+
except requests.exceptions.RequestException as e:
37+
print(f"Error fetching the dataset: {e}")
38+
return None
39+
except Exception as e:
40+
print(f"Unexpected error: {e}")
41+
return None
3342

3443

3544
def run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta):

0 commit comments

Comments
 (0)