Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/added error handling to linear regression #11550

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@
* [Min Heap](data_structures/heap/min_heap.py)
* [Randomized Heap](data_structures/heap/randomized_heap.py)
* [Skew Heap](data_structures/heap/skew_heap.py)
* Kd Tree
* [Build Kdtree](data_structures/kd_tree/build_kdtree.py)
* Example
* [Example Usage](data_structures/kd_tree/example/example_usage.py)
* [Hypercube Points](data_structures/kd_tree/example/hypercube_points.py)
* [Kd Node](data_structures/kd_tree/kd_node.py)
* [Nearest Neighbour Search](data_structures/kd_tree/nearest_neighbour_search.py)
* Tests
* [Test Kdtree](data_structures/kd_tree/tests/test_kdtree.py)
* Linked List
* [Circular Linked List](data_structures/linked_list/circular_linked_list.py)
* [Deque Doubly](data_structures/linked_list/deque_doubly.py)
Expand Down Expand Up @@ -285,12 +294,6 @@
* Trie
* [Radix Tree](data_structures/trie/radix_tree.py)
* [Trie](data_structures/trie/trie.py)
* KD Tree
* [KD Tree Node](data_structures/kd_tree/kd_node.py)
* [Build KD Tree](data_structures/kd_tree/build_kdtree.py)
* [Nearest Neighbour Search](data_structures/kd_tree/nearest_neighbour_search.py)
* [Hypercibe Points](data_structures/kd_tree/example/hypercube_points.py)
* [Example Usage](data_structures/kd_tree/example/example_usage.py)

## Digital Image Processing
* [Change Brightness](digital_image_processing/change_brightness.py)
Expand Down
37 changes: 24 additions & 13 deletions machine_learning/linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,27 @@
The dataset contains ADR vs Rating of a Player
:return : dataset obtained from the link, as matrix
"""
response = requests.get(
"https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/"
"master/Week1/ADRvsRating.csv",
timeout=10,
)
lines = response.text.splitlines()
data = []
for item in lines:
item = item.split(",")
data.append(item)
data.pop(0) # This is for removing the labels from the list
dataset = np.matrix(data)
return dataset
try:
response = requests.get(
"https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/"
"master/Week1/ADRvsRating.csv",
timeout=10,
)
lines = response.text.splitlines()
data = []
for item in lines:
item = item.split(",")
data.append(item)
data.pop(0) # This is for removing the labels from the list
dataset = np.matrix(data)
return dataset

except requests.exceptions.RequestException as e:
print(f"Error fetching the dataset: {e}")
return None
except Exception as e:

Check failure on line 38 in machine_learning/linear_regression.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (BLE001)

machine_learning/linear_regression.py:38:12: BLE001 Do not catch blind exception: `Exception`
print(f"Unexpected error: {e}")
return None


def run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta):
Expand Down Expand Up @@ -113,5 +121,8 @@
print(f"{theta[0, i]:.5f}")


import doctest

Check failure on line 124 in machine_learning/linear_regression.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E402)

machine_learning/linear_regression.py:124:1: E402 Module level import not at top of file

if __name__ == "__main__":
main()
doctest.testmod()
Loading