From 4ac7250c38fabc53bf2d779c296fb46977509050 Mon Sep 17 00:00:00 2001 From: cozek Date: Tue, 8 Oct 2019 00:21:42 +0530 Subject: [PATCH 1/2] added doctests to scoring_functions.py --- machine_learning/scoring_functions.py | 60 +++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/machine_learning/scoring_functions.py b/machine_learning/scoring_functions.py index 2b24287b3726..0097c5f851b5 100755 --- a/machine_learning/scoring_functions.py +++ b/machine_learning/scoring_functions.py @@ -16,6 +16,16 @@ # Mean Absolute Error 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) actual = np.array(actual) @@ -27,6 +37,16 @@ def mae(predict, actual): # Mean Squared Error 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) actual = np.array(actual) @@ -39,6 +59,16 @@ def mse(predict, actual): # Root Mean Squared Error 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) actual = np.array(actual) @@ -51,6 +81,16 @@ def rmse(predict, actual): # Root Mean Square Logarithmic Error 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) actual = np.array(actual) @@ -68,15 +108,29 @@ def rmsle(predict, actual): # Mean Bias Deviation 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) actual = np.array(actual) difference = predict - actual numerator = np.sum(difference) / len(predict) denumerator = np.sum(actual) / len(predict) - print(numerator) - print(denumerator) - + # print(numerator, denumerator) score = float(numerator) / denumerator * 100 return score From a80a4cb74eed034778d4bc6100c9d8472aeeb352 Mon Sep 17 00:00:00 2001 From: cozek Date: Tue, 8 Oct 2019 09:04:33 +0530 Subject: [PATCH 2/2] dedented lines --- machine_learning/scoring_functions.py | 86 +++++++++++++-------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/machine_learning/scoring_functions.py b/machine_learning/scoring_functions.py index 0097c5f851b5..5c84f7026e74 100755 --- a/machine_learning/scoring_functions.py +++ b/machine_learning/scoring_functions.py @@ -17,14 +17,14 @@ # Mean Absolute Error 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 + 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) actual = np.array(actual) @@ -38,14 +38,14 @@ def mae(predict, actual): # Mean Squared Error 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 + 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) actual = np.array(actual) @@ -60,14 +60,14 @@ def mse(predict, actual): # Root Mean Squared Error 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 + 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) actual = np.array(actual) @@ -82,14 +82,14 @@ def rmse(predict, actual): # Root Mean Square Logarithmic Error 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 + 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) actual = np.array(actual) @@ -109,20 +109,20 @@ def rmsle(predict, actual): # Mean Bias Deviation def mbd(predict, actual): """ - This value is Negative, if the model underpredicts, - positive, if it overpredicts. + This value is Negative, if the model underpredicts, + positive, if it overpredicts. - Example(rounded for precision): + 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 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 + 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) actual = np.array(actual)