mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Added mean absolute error in linear regression (#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 <caedenperelliharris@gmail.com> * 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 <cclauss@me.com> Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
This commit is contained in:
parent
94b51f6a91
commit
69d04ff644
|
@ -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 = []
|
||||
|
@ -87,6 +86,16 @@ def run_linear_regression(data_x, data_y):
|
|||
return theta
|
||||
|
||||
|
||||
def mean_absolute_error(predicted_y, original_y):
|
||||
"""Return sum of square error for error calculation
|
||||
: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 = sum(abs(y - predicted_y[i]) for i, y in enumerate(original_y))
|
||||
return total / len(original_y)
|
||||
|
||||
|
||||
def main():
|
||||
"""Driver function"""
|
||||
data = collect_dataset()
|
||||
|
|
Loading…
Reference in New Issue
Block a user