14
14
import numpy as np
15
15
from ridge_regression import RidgeRegression
16
16
17
+
17
18
def test_feature_scaling ():
18
19
"""
19
- Tests the feature_scaling function of RidgeRegression.
20
- --------
21
- >>> model = RidgeRegression()
22
- >>> X = np.array([[1, 2], [2, 3], [3, 4]])
23
- >>> X_scaled, mean, std = model.feature_scaling(X)
24
- >>> np.round(X_scaled, 2)
25
- array([[-1.22, -1.22],
26
- [ 0. , 0. ],
27
- [ 1.22, 1.22]])
28
- >>> np.round(mean, 2)
29
- array([2., 3.])
30
- >>> np.round(std, 2)
31
- array([0.82, 0.82])
20
+ Tests the feature_scaling function of RidgeRegression.
21
+ --------
22
+ >>> model = RidgeRegression()
23
+ >>> X = np.array([[1, 2], [2, 3], [3, 4]])
24
+ >>> X_scaled, mean, std = model.feature_scaling(X)
25
+ >>> np.round(X_scaled, 2)
26
+ array([[-1.22, -1.22],
27
+ [ 0. , 0. ],
28
+ [ 1.22, 1.22]])
29
+ >>> np.round(mean, 2)
30
+ array([2., 3.])
31
+ >>> np.round(std, 2)
32
+ array([0.82, 0.82])
32
33
"""
33
34
pass
34
35
36
+
35
37
def test_fit ():
36
38
"""
37
39
Tests the fit function of RidgeRegression
38
40
--------
39
41
>>> model = RidgeRegression(alpha=0.01, regularization_param=0.1, num_iterations=1000)
40
42
>>> X = np.array([[1], [2], [3]])
41
43
>>> y = np.array([2, 3, 4])
42
-
44
+
43
45
# Adding a bias term
44
46
>>> X = np.c_[np.ones(X.shape[0]), X]
45
-
47
+
46
48
# Fit the model
47
49
>>> model.fit(X, y)
48
-
50
+
49
51
# Check if the weights have been updated
50
52
>>> np.round(model.theta, decimals=2)
51
53
array([0. , 0.79])
52
54
"""
53
55
pass
54
56
57
+
55
58
def test_predict ():
56
59
"""
57
60
Tests the predict function of RidgeRegression
58
61
--------
59
62
>>> model = RidgeRegression(alpha=0.01, regularization_param=0.1, num_iterations=1000)
60
63
>>> X = np.array([[1], [2], [3]])
61
64
>>> y = np.array([2, 3, 4])
62
-
65
+
63
66
# Adding a bias term
64
67
>>> X = np.c_[np.ones(X.shape[0]), X]
65
-
68
+
66
69
# Fit the model
67
70
>>> model.fit(X, y)
68
-
71
+
69
72
# Predict with the model
70
73
>>> predictions = model.predict(X)
71
74
>>> np.round(predictions, decimals=2)
72
75
array([-0.97, 0. , 0.97])
73
76
"""
74
77
pass
75
78
79
+
76
80
def test_mean_absolute_error ():
77
81
"""
78
82
Tests the mean_absolute_error function of RidgeRegression
@@ -86,6 +90,8 @@ def test_mean_absolute_error():
86
90
"""
87
91
pass
88
92
93
+
89
94
if __name__ == "__main__" :
90
95
import doctest
91
- doctest .testmod ()
96
+
97
+ doctest .testmod ()
0 commit comments