import numpy as np
import matplotlib.pyplot as plt

x = np.array([0.55, 0.72, 0.6 , 0.54, 0.42,
    0.65, 0.44, 0.89, 0.96, 0.38,
    0.79, 0.53, 0.57, 0.93, 0.07,
    0.09, 0.02, 0.83, 0.78, 0.87])

y = np.array([6.9 , 7.58, 7.03, 6.61, 5.84,
    7.32, 6.29, 8.38, 9.03, 5.75,
    7.95, 6.63, 7.  , 8.8 , 4.37,
    4.49, 4.01, 7.95, 7.87, 8.37])

fhatx = np.array([
       6.74792024, 7.61454115, 7.00280875, 6.69694254, 6.08521014,
       7.25769725, 6.18716554, 8.48116205, 8.83800595, 5.88129934,
       7.97138505, 6.64596484, 6.84987564, 8.68507285, 4.30099064,
       4.40294604, 4.04610214, 8.17529585, 7.92040735, 8.37920665])

# Define function for mean squared error
def computeMSE(y, fhatx):
    # TODO Do something to compute mse
    return mse

print("MSE: ", computeMSE(y, fhatx))

# TODO Compute linear regression coefficients with function np.polyfit

# TODO Compute prediction of x by yourself, the values should coincide with those of fhatx (by at most 1e-8), you can use the function np.polyval

# Plot the dataset as well as the regression line
fig = plt.figure()

# TODO Plot data points
# -------------------------------------------------- 
# plt.plot( ..., 'k+', label='data points')
# -------------------------------------------------- 

# TODO Plot least squares line
# -------------------------------------------------- 
# xr = np.linspace(0,1,100)
# plt.plot( ..., 'b--', label='least squares line')
# -------------------------------------------------- 
plt.legend()
plt.show()
