From a2d07af8c1f005a60c31ff002c05a48d81d13ddf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:39:20 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/ridge_regression.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/machine_learning/ridge_regression.py b/machine_learning/ridge_regression.py index 02a48f360..0cd32caeb 100644 --- a/machine_learning/ridge_regression.py +++ b/machine_learning/ridge_regression.py @@ -62,7 +62,9 @@ class RidgeRegression: >>> rr.theta is not None True """ - features_scaled, mean, std = self.feature_scaling(features) # Normalize features + features_scaled, mean, std = self.feature_scaling( + features + ) # Normalize features m, n = features_scaled.shape self.theta = np.zeros(n) # Initialize weights to zeros @@ -90,9 +92,11 @@ class RidgeRegression: >>> predictions.shape == target.shape True """ - features_scaled, _, _ = self.feature_scaling(features) # Scale features using training data + features_scaled, _, _ = self.feature_scaling( + features + ) # Scale features using training data return features_scaled.dot(self.theta) - + def compute_cost(self, features: np.ndarray, target: np.ndarray) -> float: """ Compute the cost function with regularization. @@ -110,7 +114,9 @@ class RidgeRegression: >>> isinstance(cost, float) True """ - features_scaled, _, _ = self.feature_scaling(features) # Scale features using training data + features_scaled, _, _ = self.feature_scaling( + features + ) # Scale features using training data m = len(target) predictions = features_scaled.dot(self.theta) cost = (1 / (2 * m)) * np.sum((predictions - target) ** 2) + (