code: def fit_lsq(self, x, y_obs, params_start=None):
          
  
          # Set up variables
          x = np.atleast_1d(x)
          y_obs = np.atleast_1d(y_obs)
          if not params_start:
              params_start = np.ones(self.n_parameters)
  
          # Error checking
          if len(x) != len(y_obs):
              raise ValueError, "x and y_obs must be the same length"
          if len(params_start) != self.n_parameters:
              raise ValueError, "Incorrect number of values in params_start"
  
          # Calculate fit
          def residuals(params, x, y_obs):
              y_pred = self.vals(x, *params)
              return y_obs - y_pred
  
          params_fit, _, _, msg, ier = optimize.leastsq(residuals, params_start,
                                               args=(x, y_obs), full_output=True)
  
          # Check for convergence
          if ier > 4:
              raise ValueError, ("Least squares fit did not converge with "
                                 "message %s" % msg)
  
          return tuple(params_fit)
docs: Fit curve by method of least squares.
  
          Parameters
          ----------
          x : iterable
              Independent variable
          y_obs : iterable
              Dependent variable (values observed at x)
          params_start : iterable
              Optional start values for all parameters. Default 1.
  
          Returns
          -------
          array
              Best fit values of parameters
  
          Notes
          -----
          If least squares fit does not converge, ValueError is raised with
          convergence message.