import matplotlib.pyplot as plt
import numpy as np
# Data points
distance = np.array([5, 13, 27, 18, 8, 22, 45])
cost = np.array([1500, 600, 1200, 800, 1350, 950, 1000])
# Regression parameters
intercept = 1184.1996
slope = -6.4449
# Create scatter plot for data points
plt.figure(figsize=(8, 6))
plt.scatter(distance, cost, color='blue', label='Data Points')
# Generate x values for the regression line
x_line = np.linspace(min(distance), max(distance), 100)
y_line = intercept + slope * x_line
# Plot the regression line
plt.plot(x_line, y_line, color='red', label=f'Regression Line: y = {intercept:.4f} - {abs(slope):.4f}x')
# Label the axes and add a title
plt.xlabel('Distance from School (miles)')
plt.ylabel('Cost of Supplies ($)')
plt.title('Distance vs. Cost of Supplies')
plt.legend()
plt.grid(True)
plt.show()