Skip to content

Commit 25701a9

Browse files
cozekcclauss
authored andcommitted
added doctests to scoring_functions.py (TheAlgorithms#1300)
* added doctests to scoring_functions.py * dedented lines
1 parent 3a06aba commit 25701a9

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

machine_learning/scoring_functions.py

+57-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616

1717
# Mean Absolute Error
1818
def mae(predict, actual):
19+
"""
20+
Examples(rounded for precision):
21+
>>> actual = [1,2,3];predict = [1,4,3]
22+
>>> np.around(mae(predict,actual),decimals = 2)
23+
0.67
24+
25+
>>> actual = [1,1,1];predict = [1,1,1]
26+
>>> mae(predict,actual)
27+
0.0
28+
"""
1929
predict = np.array(predict)
2030
actual = np.array(actual)
2131

@@ -27,6 +37,16 @@ def mae(predict, actual):
2737

2838
# Mean Squared Error
2939
def mse(predict, actual):
40+
"""
41+
Examples(rounded for precision):
42+
>>> actual = [1,2,3];predict = [1,4,3]
43+
>>> np.around(mse(predict,actual),decimals = 2)
44+
1.33
45+
46+
>>> actual = [1,1,1];predict = [1,1,1]
47+
>>> mse(predict,actual)
48+
0.0
49+
"""
3050
predict = np.array(predict)
3151
actual = np.array(actual)
3252

@@ -39,6 +59,16 @@ def mse(predict, actual):
3959

4060
# Root Mean Squared Error
4161
def rmse(predict, actual):
62+
"""
63+
Examples(rounded for precision):
64+
>>> actual = [1,2,3];predict = [1,4,3]
65+
>>> np.around(rmse(predict,actual),decimals = 2)
66+
1.15
67+
68+
>>> actual = [1,1,1];predict = [1,1,1]
69+
>>> rmse(predict,actual)
70+
0.0
71+
"""
4272
predict = np.array(predict)
4373
actual = np.array(actual)
4474

@@ -51,6 +81,16 @@ def rmse(predict, actual):
5181

5282
# Root Mean Square Logarithmic Error
5383
def rmsle(predict, actual):
84+
"""
85+
Examples(rounded for precision):
86+
>>> actual = [10,10,30];predict = [10,2,30]
87+
>>> np.around(rmsle(predict,actual),decimals = 2)
88+
0.75
89+
90+
>>> actual = [1,1,1];predict = [1,1,1]
91+
>>> rmsle(predict,actual)
92+
0.0
93+
"""
5494
predict = np.array(predict)
5595
actual = np.array(actual)
5696

@@ -68,15 +108,29 @@ def rmsle(predict, actual):
68108

69109
# Mean Bias Deviation
70110
def mbd(predict, actual):
111+
"""
112+
This value is Negative, if the model underpredicts,
113+
positive, if it overpredicts.
114+
115+
Example(rounded for precision):
116+
117+
Here the model overpredicts
118+
>>> actual = [1,2,3];predict = [2,3,4]
119+
>>> np.around(mbd(predict,actual),decimals = 2)
120+
50.0
121+
122+
Here the model underpredicts
123+
>>> actual = [1,2,3];predict = [0,1,1]
124+
>>> np.around(mbd(predict,actual),decimals = 2)
125+
-66.67
126+
"""
71127
predict = np.array(predict)
72128
actual = np.array(actual)
73129

74130
difference = predict - actual
75131
numerator = np.sum(difference) / len(predict)
76132
denumerator = np.sum(actual) / len(predict)
77-
print(numerator)
78-
print(denumerator)
79-
133+
# print(numerator, denumerator)
80134
score = float(numerator) / denumerator * 100
81135

82136
return score

0 commit comments

Comments
 (0)