mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 18:38:39 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
61945d03c6
commit
a2d07af8c1
@ -62,7 +62,9 @@ class RidgeRegression:
|
|||||||
>>> rr.theta is not None
|
>>> rr.theta is not None
|
||||||
True
|
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
|
m, n = features_scaled.shape
|
||||||
self.theta = np.zeros(n) # Initialize weights to zeros
|
self.theta = np.zeros(n) # Initialize weights to zeros
|
||||||
|
|
||||||
@ -90,7 +92,9 @@ class RidgeRegression:
|
|||||||
>>> predictions.shape == target.shape
|
>>> predictions.shape == target.shape
|
||||||
True
|
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)
|
return features_scaled.dot(self.theta)
|
||||||
|
|
||||||
def compute_cost(self, features: np.ndarray, target: np.ndarray) -> float:
|
def compute_cost(self, features: np.ndarray, target: np.ndarray) -> float:
|
||||||
@ -110,7 +114,9 @@ class RidgeRegression:
|
|||||||
>>> isinstance(cost, float)
|
>>> isinstance(cost, float)
|
||||||
True
|
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)
|
m = len(target)
|
||||||
predictions = features_scaled.dot(self.theta)
|
predictions = features_scaled.dot(self.theta)
|
||||||
cost = (1 / (2 * m)) * np.sum((predictions - target) ** 2) + (
|
cost = (1 / (2 * m)) * np.sum((predictions - target) ** 2) + (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user