Created
July 23, 2020 10:30
-
-
Save SaraM92/e7818756dceb94949b9715d2e7922782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Import needed libraries | |
import matplotlib.pyplot as plt | |
#Set data | |
x = list(range(1,6)) #data points | |
y = [1,1,2,2,4] #original values | |
y_bar = [0.6,1.29,1.99,2.69,3.4] #predicted values | |
summation = 0 | |
n = len(y) | |
for i in range(0, n): | |
# finding the difference between observed and predicted value | |
difference = y[i] - y_bar[i] | |
abs_difference = abs(difference) # taking square of the differene | |
# taking a sum of all the differences | |
summation = summation + abs_difference | |
MSA = summation/n # get the average of all | |
print("The Mean Absolute Error is: ", MSA) | |
#Plot relationship | |
plt.scatter(x, y, color='#06AED5') | |
plt.plot(x, y_bar, color='#1D3557', linewidth=2) | |
plt.xlabel('Data Points', fontsize=12) | |
plt.ylabel('Output', fontsize=12) | |
plt.title("MSA") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment