ruff and minor checks

This commit is contained in:
jbsch 2024-10-24 12:03:41 +05:30
parent d8c0b7c7b3
commit 83d7252b3a

View File

@ -11,67 +11,71 @@ To run these tests, use the following command:
python -m doctest test_ridge_regression.py -v python -m doctest test_ridge_regression.py -v
""" """
import numpy as np # from ridge_regression import RidgeRegression
from ridge_regression import RidgeRegression
def test_feature_scaling(): def test_feature_scaling():
""" """
Tests the feature_scaling function of RidgeRegression. Tests the feature_scaling function of RidgeRegression.
-------- --------
>>> model = RidgeRegression() >>> model = RidgeRegression()
>>> X = np.array([[1, 2], [2, 3], [3, 4]]) >>> X = np.array([[1, 2], [2, 3], [3, 4]])
>>> X_scaled, mean, std = model.feature_scaling(X) >>> X_scaled, mean, std = model.feature_scaling(X)
>>> np.round(X_scaled, 2) >>> np.round(X_scaled, 2)
array([[-1.22, -1.22], array([[-1.22, -1.22],
[ 0. , 0. ], [ 0. , 0. ],
[ 1.22, 1.22]]) [ 1.22, 1.22]])
>>> np.round(mean, 2) >>> np.round(mean, 2)
array([2., 3.]) array([2., 3.])
>>> np.round(std, 2) >>> np.round(std, 2)
array([0.82, 0.82]) array([0.82, 0.82])
""" """
pass
def test_fit(): def test_fit():
""" """
Tests the fit function of RidgeRegression Tests the fit function of RidgeRegression
-------- --------
>>> model = RidgeRegression(alpha=0.01, regularization_param=0.1, num_iterations=1000) >>> model = RidgeRegression(alpha=0.01,
regularization_param=0.1,
num_iterations=1000)
>>> X = np.array([[1], [2], [3]]) >>> X = np.array([[1], [2], [3]])
>>> y = np.array([2, 3, 4]) >>> y = np.array([2, 3, 4])
# Adding a bias term # Adding a bias term
>>> X = np.c_[np.ones(X.shape[0]), X] >>> X = np.c_[np.ones(X.shape[0]), X]
# Fit the model # Fit the model
>>> model.fit(X, y) >>> model.fit(X, y)
# Check if the weights have been updated # Check if the weights have been updated
>>> np.round(model.theta, decimals=2) >>> np.round(model.theta, decimals=2)
array([0. , 0.79]) array([0. , 0.79])
""" """
pass
def test_predict(): def test_predict():
""" """
Tests the predict function of RidgeRegression Tests the predict function of RidgeRegression
-------- --------
>>> model = RidgeRegression(alpha=0.01, regularization_param=0.1, num_iterations=1000) >>> model = RidgeRegression(alpha=0.01,
regularization_param=0.1,
num_iterations=1000)
>>> X = np.array([[1], [2], [3]]) >>> X = np.array([[1], [2], [3]])
>>> y = np.array([2, 3, 4]) >>> y = np.array([2, 3, 4])
# Adding a bias term # Adding a bias term
>>> X = np.c_[np.ones(X.shape[0]), X] >>> X = np.c_[np.ones(X.shape[0]), X]
# Fit the model # Fit the model
>>> model.fit(X, y) >>> model.fit(X, y)
# Predict with the model # Predict with the model
>>> predictions = model.predict(X) >>> predictions = model.predict(X)
>>> np.round(predictions, decimals=2) >>> np.round(predictions, decimals=2)
array([-0.97, 0. , 0.97]) array([-0.97, 0. , 0.97])
""" """
pass
def test_mean_absolute_error(): def test_mean_absolute_error():
""" """
@ -84,8 +88,9 @@ def test_mean_absolute_error():
>>> float(np.round(mae, 2)) >>> float(np.round(mae, 2))
0.07 0.07
""" """
pass
if __name__ == "__main__": if __name__ == "__main__":
import doctest import doctest
doctest.testmod()
doctest.testmod()