From 5a30fec66255a93f1ae5abba692bf790e5521703 Mon Sep 17 00:00:00 2001 From: Kushagra Makharia Date: Tue, 11 Oct 2022 21:35:42 +0530 Subject: [PATCH 1/7] Added mean absolute error in linear regression --- machine_learning/linear_regression.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/machine_learning/linear_regression.py b/machine_learning/linear_regression.py index 85fdfb0005ac..0b5b22161ad5 100644 --- a/machine_learning/linear_regression.py +++ b/machine_learning/linear_regression.py @@ -86,6 +86,18 @@ def run_linear_regression(data_x, data_y): return theta +def mean_absolute_error(pred_X, org_X): + """Return sum of square error for error calculation + :param pred_X : contains the output (result vector) + :param org_X : contains our dataset + :return : mean absolute error computed from given feature's + """ + total = 0 + for i in range(len(org_X)): + total += abs(org_X[i] - pred_X[i]) + error = sum/len(org_X) + return error + def main(): """Driver function""" From ba8e5ca4a4744d726eff547c90f9580b64e7a12a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 Oct 2022 16:11:53 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/linear_regression.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/machine_learning/linear_regression.py b/machine_learning/linear_regression.py index 0b5b22161ad5..0ba094748d2e 100644 --- a/machine_learning/linear_regression.py +++ b/machine_learning/linear_regression.py @@ -86,6 +86,7 @@ def run_linear_regression(data_x, data_y): return theta + def mean_absolute_error(pred_X, org_X): """Return sum of square error for error calculation :param pred_X : contains the output (result vector) @@ -95,7 +96,7 @@ def mean_absolute_error(pred_X, org_X): total = 0 for i in range(len(org_X)): total += abs(org_X[i] - pred_X[i]) - error = sum/len(org_X) + error = sum / len(org_X) return error From 9396bac65bb8e2eed9bc7451086a5632c62b540d Mon Sep 17 00:00:00 2001 From: Kushagra Makharia Date: Thu, 13 Oct 2022 06:50:20 +0530 Subject: [PATCH 3/7] Code feedback changes --- machine_learning/linear_regression.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/machine_learning/linear_regression.py b/machine_learning/linear_regression.py index 0ba094748d2e..2fea0eb3d77d 100644 --- a/machine_learning/linear_regression.py +++ b/machine_learning/linear_regression.py @@ -87,16 +87,16 @@ def run_linear_regression(data_x, data_y): return theta -def mean_absolute_error(pred_X, org_X): +def mean_absolute_error(predicted_y, original_y): """Return sum of square error for error calculation - :param pred_X : contains the output (result vector) - :param org_X : contains our dataset + :param predicted_y : contains the output of prediction (result vector) + :param original_y : contains values of expected outcome :return : mean absolute error computed from given feature's """ total = 0 - for i in range(len(org_X)): - total += abs(org_X[i] - pred_X[i]) - error = sum / len(org_X) + for i in range(len(original_y)): + total += abs(original_y[i] - predicted_y[i]) + error = total/len(original_y) return error From a8c7f235e36e12f04367e13cae5483b271cfec64 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 13 Oct 2022 01:22:10 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/linear_regression.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine_learning/linear_regression.py b/machine_learning/linear_regression.py index 2fea0eb3d77d..7969bac60c32 100644 --- a/machine_learning/linear_regression.py +++ b/machine_learning/linear_regression.py @@ -96,7 +96,7 @@ def mean_absolute_error(predicted_y, original_y): total = 0 for i in range(len(original_y)): total += abs(original_y[i] - predicted_y[i]) - error = total/len(original_y) + error = total / len(original_y) return error From b26c1ca9b178aecac8b309a9809b6531a80a783c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 30 Oct 2022 12:48:28 +0100 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Caeden Perelli-Harris --- machine_learning/linear_regression.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/machine_learning/linear_regression.py b/machine_learning/linear_regression.py index 7969bac60c32..c8b1f827865b 100644 --- a/machine_learning/linear_regression.py +++ b/machine_learning/linear_regression.py @@ -93,11 +93,8 @@ def mean_absolute_error(predicted_y, original_y): :param original_y : contains values of expected outcome :return : mean absolute error computed from given feature's """ - total = 0 - for i in range(len(original_y)): - total += abs(original_y[i] - predicted_y[i]) - error = total / len(original_y) - return error + total = sum(abs(original_y[i] - predicted_y[i]) for i in range(len(original_y))) + return total / len(original_y) def main(): From 0c4487bfe5a6a4a06fef494d943f371d2bd35374 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 30 Oct 2022 12:50:01 +0100 Subject: [PATCH 6/7] Apply suggestions from code review --- machine_learning/linear_regression.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/machine_learning/linear_regression.py b/machine_learning/linear_regression.py index c8b1f827865b..6e4d55e45c6f 100644 --- a/machine_learning/linear_regression.py +++ b/machine_learning/linear_regression.py @@ -93,7 +93,7 @@ def mean_absolute_error(predicted_y, original_y): :param original_y : contains values of expected outcome :return : mean absolute error computed from given feature's """ - total = sum(abs(original_y[i] - predicted_y[i]) for i in range(len(original_y))) + total = sum(abs(y - predicted_y[i]) for i, y in enumerate(original_y)) return total / len(original_y) From aa0b4b776009aad15224a293b1a8ebe3a4ec762b Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 30 Oct 2022 13:05:28 +0100 Subject: [PATCH 7/7] Update linear_regression.py --- machine_learning/linear_regression.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/machine_learning/linear_regression.py b/machine_learning/linear_regression.py index 6e4d55e45c6f..afa49fc3313e 100644 --- a/machine_learning/linear_regression.py +++ b/machine_learning/linear_regression.py @@ -17,9 +17,8 @@ def collect_dataset(): :return : dataset obtained from the link, as matrix """ response = requests.get( - "https://raw.githubusercontent.com/yashLadha/" - + "The_Math_of_Intelligence/master/Week1/ADRvs" - + "Rating.csv" + "https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/" + "master/Week1/ADRvsRating.csv" ) lines = response.text.splitlines() data = []