Skip to content

Instantly share code, notes, and snippets.

@SaraM92
Created July 23, 2020 10:14
Show Gist options
  • Save SaraM92/c5a647042365a45eb9f2e70e2de90c35 to your computer and use it in GitHub Desktop.
Save SaraM92/c5a647042365a45eb9f2e70e2de90c35 to your computer and use it in GitHub Desktop.
#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]
squared_difference = difference**2 # taking square of the differene
# taking a sum of all the differences
summation = summation + squared_difference
MSE = summation/n # get the average of all
print("The Mean Square Error is: ", MSE)
#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("MSE")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment