From 2454e557a14730ec753b923a3ff977818581bfbf Mon Sep 17 00:00:00 2001 From: priya-sundaram-dev Date: Sun, 30 Aug 2026 06:26:23 +0000 Subject: [PATCH 1/2] ci: un-ignore local_weighted_learning doctests in build.yml machine_learning/local_weighted_learning/local_weighted_learning.py only imports numpy and matplotlib (both already project dependencies) and its 5 doctests pass headlessly. Removing it from the pytest --ignore list so the module is covered by CI again. --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4ed88a88f2bb..40e6a0515cd0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,6 @@ jobs: --ignore=computer_vision/cnn_classification.py --ignore=docs/conf.py --ignore=dynamic_programming/k_means_clustering_tensorflow.py - --ignore=machine_learning/local_weighted_learning/local_weighted_learning.py --ignore=machine_learning/lstm/lstm_prediction.py --ignore=neural_network/input_data.py --ignore=project_euler/ From b271dbb2fcd9304731ef178668f3b8cb909cfb07 Mon Sep 17 00:00:00 2001 From: Priya Sundaram Date: Sun, 30 Aug 2026 06:57:23 +0000 Subject: [PATCH 2/2] fix(local_weighted_learning): use a well-conditioned bandwidth in doctests The doctests used tau=0.6 on data with feature values ~17-25, so the Gaussian weights underflowed to ~0 (e.g. 8e-118, 1e-177). That made X\u1d40WX numerically singular (cond ~5.6e18), so its inverse - and the resulting predictions - were nondeterministic across numpy/BLAS builds. That is why the module was on the pytest --ignore list; on the CI numpy the first prediction came out 0.0 instead of the documented 1.07. Switch the doctests to tau=5 (cond ~2e2), matching the bandwidth the module's own main() already uses, and round the outputs so they are stable across platforms. Deterministic now; removed from --ignore. --- .../local_weighted_learning.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/machine_learning/local_weighted_learning/local_weighted_learning.py b/machine_learning/local_weighted_learning/local_weighted_learning.py index f3056da40e24..a3c0e55d964d 100644 --- a/machine_learning/local_weighted_learning/local_weighted_learning.py +++ b/machine_learning/local_weighted_learning/local_weighted_learning.py @@ -50,13 +50,13 @@ def weight_matrix(point: np.ndarray, x_train: np.ndarray, tau: float) -> np.ndar m x m weight matrix around the prediction point, where m is the size of the training set >>> weight_matrix( - ... np.array([1., 1.]), - ... np.array([[16.99, 10.34], [21.01,23.68], [24.59,25.69]]), - ... 0.6 - ... ) - array([[1.43807972e-207, 0.00000000e+000, 0.00000000e+000], - [0.00000000e+000, 0.00000000e+000, 0.00000000e+000], - [0.00000000e+000, 0.00000000e+000, 0.00000000e+000]]) + ... np.array([16.99, 10.34]), + ... np.array([[16.99, 10.34], [21.01, 23.68], [24.59, 25.69]]), + ... 5, + ... ).round(4) + array([[1. , 0. , 0. ], + [0. , 0.0206, 0. ], + [0. , 0. , 0.0028]]) """ m = len(x_train) # Number of training samples weights = np.eye(m) # Initialize weights as identity matrix @@ -83,13 +83,13 @@ def local_weight( Returns: ndarray of local weights >>> local_weight( - ... np.array([1., 1.]), - ... np.array([[16.99, 10.34], [21.01,23.68], [24.59,25.69]]), + ... np.array([16.99, 10.34]), + ... np.array([[16.99, 10.34], [21.01, 23.68], [24.59, 25.69]]), ... np.array([[1.01, 1.66, 3.5]]), - ... 0.6 - ... ) - array([[0.00873174], - [0.08272556]]) + ... 5, + ... ).round(5) + array([[0.02572], + [0.05552]]) """ weight_mat = weight_matrix(point, x_train, tau) weight = np.linalg.inv(x_train.T @ weight_mat @ x_train) @ ( @@ -116,9 +116,9 @@ def local_weight_regression( >>> local_weight_regression( ... np.array([[16.99, 10.34], [21.01, 23.68], [24.59, 25.69]]), ... np.array([[1.01, 1.66, 3.5]]), - ... 0.6 - ... ) - array([1.07173261, 1.65970737, 3.50160179]) + ... 5, + ... ).round(5) + array([1.01094, 1.98589, 3.42233]) """ y_pred = np.zeros(len(x_train)) # Initialize array of predictions for i, item in enumerate(x_train):