Skip to content

Commit 1fe676a

Browse files
committed
fix(ci): ruff/mypy issues — lower-case doctest vars, assert weights before enumerate
1 parent f61c33f commit 1fe676a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

machine_learning/ridge_regression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
Examples
1414
--------
1515
>>> import numpy as np
16-
>>> X = np.array([[1.0], [2.0], [3.0]])
16+
>>> x = np.array([[1.0], [2.0], [3.0]])
1717
>>> y = np.array([2.0, 4.0, 6.0])
1818
>>> model = RidgeRegression(learning_rate=0.1, lambda_=0.0, epochs=2000)
19-
>>> model.fit(X, y)
19+
>>> model.fit(x, y)
2020
>>> np.allclose(model.weights, [0.0, 2.0], atol=1e-2)
2121
True
2222
>>> model.predict(np.array([[4.0], [5.0]]))
@@ -27,7 +27,6 @@
2727

2828
from dataclasses import dataclass
2929

30-
3130
import httpx
3231
import numpy as np
3332

@@ -165,6 +164,7 @@ def main() -> None:
165164
mae = mean_absolute_error(preds, y)
166165

167166
print("Learned weights:")
167+
assert model.weights is not None
168168
for i, w in enumerate(model.weights):
169169
print(f"w[{i}] = {w:.6f}")
170170
print(f"MAE on training data: {mae:.6f}")

machine_learning/tests/test_ridge_regression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ def test_accepts_numpy_matrix():
5555
from machine_learning.ridge_regression import collect_dataset
5656

5757
data = collect_dataset()
58-
X = np.c_[data[:, 0].astype(float)] # numpy.matrix
58+
x = np.c_[data[:, 0].astype(float)] # numpy.matrix
5959
y = np.ravel(data[:, 1].astype(float))
6060

6161
model = RidgeRegression(learning_rate=0.0002, lambda_=0.01, epochs=500)
62-
model.fit(X, y)
63-
preds = model.predict(X)
62+
model.fit(x, y)
63+
preds = model.predict(x)
6464
assert preds.shape == (y.shape[0],)
6565
assert mean_absolute_error(preds, y) >= 0.0

0 commit comments

Comments
 (0)