Skip to content

Commit 69d04ff

Browse files
KushagraMakhariapre-commit-ci[bot]cclaussCaedenPH
authored
Added mean absolute error in linear regression (TheAlgorithms#7003)
* Added mean absolute error in linear regression * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Code feedback changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestions from code review Co-authored-by: Caeden Perelli-Harris <[email protected]> * Apply suggestions from code review * Update linear_regression.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: Caeden Perelli-Harris <[email protected]>
1 parent 94b51f6 commit 69d04ff

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

machine_learning/linear_regression.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ def collect_dataset():
1717
:return : dataset obtained from the link, as matrix
1818
"""
1919
response = requests.get(
20-
"https://raw.githubusercontent.com/yashLadha/"
21-
+ "The_Math_of_Intelligence/master/Week1/ADRvs"
22-
+ "Rating.csv"
20+
"https://raw.githubusercontent.com/yashLadha/The_Math_of_Intelligence/"
21+
"master/Week1/ADRvsRating.csv"
2322
)
2423
lines = response.text.splitlines()
2524
data = []
@@ -87,6 +86,16 @@ def run_linear_regression(data_x, data_y):
8786
return theta
8887

8988

89+
def mean_absolute_error(predicted_y, original_y):
90+
"""Return sum of square error for error calculation
91+
:param predicted_y : contains the output of prediction (result vector)
92+
:param original_y : contains values of expected outcome
93+
:return : mean absolute error computed from given feature's
94+
"""
95+
total = sum(abs(y - predicted_y[i]) for i, y in enumerate(original_y))
96+
return total / len(original_y)
97+
98+
9099
def main():
91100
"""Driver function"""
92101
data = collect_dataset()

0 commit comments

Comments
 (0)