psy_reg.utils module
Utility functions for psy-reg
- class psy_reg.utils.GenericModel(*params, **attrs)[source]
Bases:
object
An abstract model for least-squares regression
This abstract base class implements a fit and predict and can be subclassed to provide a model for a function that is fitted with the
scipy.optimize.curve_fit()
function.- property func_kwargs
The arguments for the fit function if the
method
is ‘curve_fit’
- abstract static function(x, *params, **kwargs)[source]
The function that is responsible for the fit
- property pcov
The covariance matrix
- property rsquared
The coefficient of determination, $R^2$
- psy_reg.utils.rsquared(sim, obs)[source]
Calculate the R-squared (coefficient of determination, $R^2$)
$R^2$ is defined as
\[R^2 = 1 - \frac{\sum\,(obs - sim)^2}{\sum(obs - \widebar{obs})^2}\]- Parameters
sim (np.ndarray) – Simulated values
obs (np.ndarray) – Observed values (broadcastable to sim)
- Returns
The R squared
- Return type