def fit_lsq(self, x, y_obs, params_start=None):
<EOL>x = np.atleast_1d(x)<EOL>y_obs = np.atleast_1d(y_obs)<EOL>if not params_start:<EOL><INDENT>params_start = np.ones(self.n_parameters)<EOL><DEDENT>if len(x) != len(y_obs):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(params_start) != self.n_parameters:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>def residuals(params, x, y_obs):<EOL><INDENT>y_pred = self.vals(x, *params)<EOL>return y_obs - y_pred<EOL><DEDENT>params_fit, _, _, msg, ier = optimize.leastsq(residuals, params_start,<EOL>args=(x, y_obs), full_output=True)<EOL>if ier > <NUM_LIT:4>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" % msg)<EOL><DEDENT>return tuple(params_fit)<EOL>
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.