From 59d3ceba272d97616e0f10fbeac69b07b8610777 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 24 Oct 2024 05:24:47 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../ridge_regression/test_ridge_regression.py | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/machine_learning/ridge_regression/test_ridge_regression.py b/machine_learning/ridge_regression/test_ridge_regression.py index 03c4218a5..a698c5445 100644 --- a/machine_learning/ridge_regression/test_ridge_regression.py +++ b/machine_learning/ridge_regression/test_ridge_regression.py @@ -14,24 +14,26 @@ To run these tests, use the following command: import numpy as np from ridge_regression import RidgeRegression + def test_feature_scaling(): """ - Tests the feature_scaling function of RidgeRegression. - -------- - >>> model = RidgeRegression() - >>> X = np.array([[1, 2], [2, 3], [3, 4]]) - >>> X_scaled, mean, std = model.feature_scaling(X) - >>> np.round(X_scaled, 2) - array([[-1.22, -1.22], - [ 0. , 0. ], - [ 1.22, 1.22]]) - >>> np.round(mean, 2) - array([2., 3.]) - >>> np.round(std, 2) - array([0.82, 0.82]) + Tests the feature_scaling function of RidgeRegression. + -------- + >>> model = RidgeRegression() + >>> X = np.array([[1, 2], [2, 3], [3, 4]]) + >>> X_scaled, mean, std = model.feature_scaling(X) + >>> np.round(X_scaled, 2) + array([[-1.22, -1.22], + [ 0. , 0. ], + [ 1.22, 1.22]]) + >>> np.round(mean, 2) + array([2., 3.]) + >>> np.round(std, 2) + array([0.82, 0.82]) """ pass + def test_fit(): """ Tests the fit function of RidgeRegression @@ -39,19 +41,20 @@ def test_fit(): >>> model = RidgeRegression(alpha=0.01, regularization_param=0.1, num_iterations=1000) >>> X = np.array([[1], [2], [3]]) >>> y = np.array([2, 3, 4]) - + # Adding a bias term >>> X = np.c_[np.ones(X.shape[0]), X] - + # Fit the model >>> model.fit(X, y) - + # Check if the weights have been updated >>> np.round(model.theta, decimals=2) array([0. , 0.79]) """ pass + def test_predict(): """ Tests the predict function of RidgeRegression @@ -59,13 +62,13 @@ def test_predict(): >>> model = RidgeRegression(alpha=0.01, regularization_param=0.1, num_iterations=1000) >>> X = np.array([[1], [2], [3]]) >>> y = np.array([2, 3, 4]) - + # Adding a bias term >>> X = np.c_[np.ones(X.shape[0]), X] - + # Fit the model >>> model.fit(X, y) - + # Predict with the model >>> predictions = model.predict(X) >>> np.round(predictions, decimals=2) @@ -73,6 +76,7 @@ def test_predict(): """ pass + def test_mean_absolute_error(): """ Tests the mean_absolute_error function of RidgeRegression @@ -86,6 +90,8 @@ def test_mean_absolute_error(): """ pass + if __name__ == "__main__": import doctest - doctest.testmod() \ No newline at end of file + + doctest.testmod()