mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-20 21:49:48 +00:00
added doctests to scoring_functions.py (#1300)
* added doctests to scoring_functions.py * dedented lines
This commit is contained in:
parent
3a06aba66a
commit
25701a9877
@ -16,6 +16,16 @@ import numpy as np
|
|||||||
|
|
||||||
# Mean Absolute Error
|
# Mean Absolute Error
|
||||||
def mae(predict, actual):
|
def mae(predict, actual):
|
||||||
|
"""
|
||||||
|
Examples(rounded for precision):
|
||||||
|
>>> actual = [1,2,3];predict = [1,4,3]
|
||||||
|
>>> np.around(mae(predict,actual),decimals = 2)
|
||||||
|
0.67
|
||||||
|
|
||||||
|
>>> actual = [1,1,1];predict = [1,1,1]
|
||||||
|
>>> mae(predict,actual)
|
||||||
|
0.0
|
||||||
|
"""
|
||||||
predict = np.array(predict)
|
predict = np.array(predict)
|
||||||
actual = np.array(actual)
|
actual = np.array(actual)
|
||||||
|
|
||||||
@ -27,6 +37,16 @@ def mae(predict, actual):
|
|||||||
|
|
||||||
# Mean Squared Error
|
# Mean Squared Error
|
||||||
def mse(predict, actual):
|
def mse(predict, actual):
|
||||||
|
"""
|
||||||
|
Examples(rounded for precision):
|
||||||
|
>>> actual = [1,2,3];predict = [1,4,3]
|
||||||
|
>>> np.around(mse(predict,actual),decimals = 2)
|
||||||
|
1.33
|
||||||
|
|
||||||
|
>>> actual = [1,1,1];predict = [1,1,1]
|
||||||
|
>>> mse(predict,actual)
|
||||||
|
0.0
|
||||||
|
"""
|
||||||
predict = np.array(predict)
|
predict = np.array(predict)
|
||||||
actual = np.array(actual)
|
actual = np.array(actual)
|
||||||
|
|
||||||
@ -39,6 +59,16 @@ def mse(predict, actual):
|
|||||||
|
|
||||||
# Root Mean Squared Error
|
# Root Mean Squared Error
|
||||||
def rmse(predict, actual):
|
def rmse(predict, actual):
|
||||||
|
"""
|
||||||
|
Examples(rounded for precision):
|
||||||
|
>>> actual = [1,2,3];predict = [1,4,3]
|
||||||
|
>>> np.around(rmse(predict,actual),decimals = 2)
|
||||||
|
1.15
|
||||||
|
|
||||||
|
>>> actual = [1,1,1];predict = [1,1,1]
|
||||||
|
>>> rmse(predict,actual)
|
||||||
|
0.0
|
||||||
|
"""
|
||||||
predict = np.array(predict)
|
predict = np.array(predict)
|
||||||
actual = np.array(actual)
|
actual = np.array(actual)
|
||||||
|
|
||||||
@ -51,6 +81,16 @@ def rmse(predict, actual):
|
|||||||
|
|
||||||
# Root Mean Square Logarithmic Error
|
# Root Mean Square Logarithmic Error
|
||||||
def rmsle(predict, actual):
|
def rmsle(predict, actual):
|
||||||
|
"""
|
||||||
|
Examples(rounded for precision):
|
||||||
|
>>> actual = [10,10,30];predict = [10,2,30]
|
||||||
|
>>> np.around(rmsle(predict,actual),decimals = 2)
|
||||||
|
0.75
|
||||||
|
|
||||||
|
>>> actual = [1,1,1];predict = [1,1,1]
|
||||||
|
>>> rmsle(predict,actual)
|
||||||
|
0.0
|
||||||
|
"""
|
||||||
predict = np.array(predict)
|
predict = np.array(predict)
|
||||||
actual = np.array(actual)
|
actual = np.array(actual)
|
||||||
|
|
||||||
@ -68,15 +108,29 @@ def rmsle(predict, actual):
|
|||||||
|
|
||||||
# Mean Bias Deviation
|
# Mean Bias Deviation
|
||||||
def mbd(predict, actual):
|
def mbd(predict, actual):
|
||||||
|
"""
|
||||||
|
This value is Negative, if the model underpredicts,
|
||||||
|
positive, if it overpredicts.
|
||||||
|
|
||||||
|
Example(rounded for precision):
|
||||||
|
|
||||||
|
Here the model overpredicts
|
||||||
|
>>> actual = [1,2,3];predict = [2,3,4]
|
||||||
|
>>> np.around(mbd(predict,actual),decimals = 2)
|
||||||
|
50.0
|
||||||
|
|
||||||
|
Here the model underpredicts
|
||||||
|
>>> actual = [1,2,3];predict = [0,1,1]
|
||||||
|
>>> np.around(mbd(predict,actual),decimals = 2)
|
||||||
|
-66.67
|
||||||
|
"""
|
||||||
predict = np.array(predict)
|
predict = np.array(predict)
|
||||||
actual = np.array(actual)
|
actual = np.array(actual)
|
||||||
|
|
||||||
difference = predict - actual
|
difference = predict - actual
|
||||||
numerator = np.sum(difference) / len(predict)
|
numerator = np.sum(difference) / len(predict)
|
||||||
denumerator = np.sum(actual) / len(predict)
|
denumerator = np.sum(actual) / len(predict)
|
||||||
print(numerator)
|
# print(numerator, denumerator)
|
||||||
print(denumerator)
|
|
||||||
|
|
||||||
score = float(numerator) / denumerator * 100
|
score = float(numerator) / denumerator * 100
|
||||||
|
|
||||||
return score
|
return score
|
||||||
|
Loading…
x
Reference in New Issue
Block a user