Advertisement
brainuser5705

plotting a linear regression

Jul 4th, 2022
721
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2.  
  3. def plot_lin_reg(regressor, X, y, resolution=100):
  4.    
  5.     max_x = X.max()
  6.     steps = math.ceil(max_x)/resolution
  7.    
  8.     # calculate points for linear regression
  9.     # could also just use lin_reg.predict to get the x values
  10.     x_points = np.arange(0, max_x + steps, steps)
  11.     c, m = regressor.intercept_, regressor.coef_
  12.     y_points = (m * x_points) + c
  13.    
  14.     plt.plot(x_points, y_points, 'c', linewidth=2)
  15.     plot_data(X, y)
Advertisement
RAW Paste Data Copied
Advertisement