"""Lesson 12 starter: regression metrics and a residual plot."""
import numpy as np
import matplotlib.pyplot as plt

y = np.array([10., 12., 15., 18., 20.])
y_pred = np.array([11., 11., 14., 20., 19.])

residuals = y_pred - y

# TODO: complete these formulas.
mse = np.mean(residuals**2)
rmse = np.sqrt(mse)
mae = np.mean(np.abs(residuals))
sse = np.sum(residuals**2)
sst = np.sum((y - np.mean(y))**2)
r_squared = 1 - sse / sst

print("MSE =", mse)
print("RMSE =", rmse)
print("MAE =", mae)
print("R^2 =", r_squared)

plt.scatter(y_pred, residuals)
plt.axhline(0)
plt.xlabel("Predicted value")
plt.ylabel("Residual")
plt.title("Residual plot")
plt.show()
