Skip to content

Fixes: #12108: Add Ridge regression implementation to machine_learning #12251

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

Closed
wants to merge 22 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 23, 2024
commit d5963b2da7fff2b1883d8868d61127b62bac165e
18 changes: 9 additions & 9 deletions machine_learning/ridge_regression/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@


class RidgeRegression:
def __init__(self,
alpha: float = 0.001,
regularization_param: float = 0.1,
num_iterations: int = 1000,
) -> None:
def __init__(
self,
alpha: float = 0.001,
regularization_param: float = 0.1,
num_iterations: int = 1000,
) -> None:
self.alpha: float = alpha
self.regularization_param: float = regularization_param
self.num_iterations: int = num_iterations
Expand Down Expand Up @@ -49,10 +50,9 @@ def compute_cost(self, x: np.ndarray, y: np.ndarray) -> float:
m = len(y)

predictions = x_scaled.dot(self.theta)
cost = (
1 / (2 * m)) * np.sum((predictions - y) ** 2) + (
self.regularization_param / (2 * m)
) * np.sum(self.theta**2)
cost = (1 / (2 * m)) * np.sum((predictions - y) ** 2) + (
self.regularization_param / (2 * m)
) * np.sum(self.theta**2)
return cost

def mean_absolute_error(self, y_true: np.ndarray, y_pred: np.ndarray) -> float:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file machine_learning/ridge_regression/model.py, please provide doctest for the function mean_absolute_error

Expand Down