code: def fit(self, X, y):
          
  
          # initial sums
          n = float(len(X))
          sum_x = X.sum()
          sum_y = y.sum()
          sum_xy = (X * y).sum()
          sum_xx = (X**2).sum()
  
          # formula for w0
          self.slope = (sum_xy - (sum_x * sum_y) / n) / (sum_xx - (sum_x * sum_x) / n)
  
          # formula for w1
          self.intercept = sum_y / n - self.slope * (sum_x / n)
  
          return self
docs: Compute average slope and intercept for all X, y pairs
  
          Arguments:
            X (np.array): model input (independent variable)
            y (np.array): model output (dependent variable)
  
          Returns:
            Linear Regression instance with `slope` and `intercept` attributes
  
          References:
            Based on: https://github.com/justmarkham/DAT4/blob/master/notebooks/08_linear_regression.ipynb
  
          >>> n_samples = 100
          >>> X = np.arange(100).reshape((n_samples, 1))
          >>> slope, intercept = 3.14159, -4.242
          >>> y = 3.14 * X + np.random.randn(*X.shape) + intercept
          >>> line = LinearRegressor()
          >>> line.fit(X, y)
          <nlpia.models.LinearRegressor object ...
          >>> abs(line.slope - slope) < abs(0.02 * (slope + 1))
          True
          >>> abs(line.intercept - intercept) < 0.2 * (abs(intercept) + 1)
          True