Skip to content

Commit 8f1f091

Browse files
committed
Resolved ruff checks
1 parent a2d07af commit 8f1f091

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

machine_learning/ridge_regression.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def fit(self, features: np.ndarray, target: np.ndarray) -> None:
6868
m, n = features_scaled.shape
6969
self.theta = np.zeros(n) # Initialize weights to zeros
7070

71-
for i in range(self.iterations):
71+
for _ in range(self.iterations):
7272
predictions = features_scaled.dot(self.theta)
7373
error = predictions - target
7474

@@ -149,21 +149,21 @@ def mean_absolute_error(self, y_true: np.ndarray, y_pred: np.ndarray) -> float:
149149
data = pd.read_csv(
150150
"https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/master/Week1/ADRvsRating.csv"
151151
)
152-
x = data[["Rating"]].to_numpy() # Feature: Rating
153-
y = data["ADR"].to_numpy() # Target: ADR
154-
y = (y - np.mean(y)) / np.std(y)
152+
data_x = data[["Rating"]].to_numpy() # Feature: Rating
153+
data_y = data["ADR"].to_numpy() # Target: ADR
154+
data_y = (data_y - np.mean(data_y)) / np.std(data_y)
155155

156156
# Add bias term (intercept) to the feature matrix
157-
x = np.c_[np.ones(X.shape[0]), x] # Add intercept term
157+
data_x = np.c_[np.ones(data_x.shape[0]), data_x] # Add intercept term
158158

159159
# Initialize and train the Ridge Regression model
160160
model = RidgeRegression(alpha=0.01, lambda_=0.1, iterations=1000)
161-
model.fit(x, y)
161+
model.fit(data_x, data_y)
162162

163163
# Predictions
164-
predictions = model.predict(x)
164+
predictions = model.predict(data_x)
165165

166166
# Results
167167
print("Optimized Weights:", model.theta)
168-
print("Cost:", model.compute_cost(x, y))
169-
print("Mean Absolute Error:", model.mean_absolute_error(y, predictions))
168+
print("Cost:", model.compute_cost(data_x, data_y))
169+
print("Mean Absolute Error:", model.mean_absolute_error(data_y, predictions))

0 commit comments

Comments
 (0)