Main Boostrap Functions¶
- pyqt_fit.bootstrap.bootstrap(fit, xdata, ydata, CI, shuffle_method=<function bootstrap_residuals at 0x2b87d5d48c08>, shuffle_args=(), shuffle_kwrds={}, repeats=3000, eval_points=None, full_results=False, nb_workers=None, extra_attrs=(), fit_args=(), fit_kwrds={})[source]¶
This function implement the bootstrap algorithm for a regression algorithm. It is capable of spreading the load across many threads using shared memory and the multiprocess module.
Parameters: - fit (callable) –
Method used to compute regression. The call is:
f = fit(xdata, ydata, *fit_args, **fit_kwrds)
Fit should return an object that would evaluate the regression on a set of points. The next call will be:
f(eval_points)
- xdata (ndarray of shape (N,) or (k,N) for function with k predictors) – The independent variable where the data is measured
- ydata (ndarray) – The dependant data
- CI (tuple of float) – List of percentiles to extract
- shuffle_method (callable) –
Create shuffled dataset. The call is:
shuffle_method(xdata, ydata, y_est, repeat=repeats, *shuffle_args, **shuffle_kwrds)
where y_est is the estimated dependant variable on the xdata.
- shuffle_args (tuple) – List of arguments for the shuffle method
- shuffle_kwrds (dict) – Dictionnary of arguments for the shuffle method
- repeats (int) – Number of repeats for the bootstraping
- eval_points (ndarray or None) – List of points to evaluate. If None, eval_point is xdata.
- full_results (bool) – if True, output also the whole set of evaluations
- nb_worders – Number of worker threads. If None, the number of detected CPUs will be used. And if 1 or less, a single thread will be used.
- extra_attrs (tuple of str) – List of attributes of the fitting method to extract on top of the y values for confidence intervals
- fit_args (tuple) – List of extra arguments for the fit callable
- fit_kwrds (dict) – Dictionnary of extra named arguments for the fit callable
Return type: Returns: Estimated y on the data, on the evaluation points, the requested confidence intervals and, if requested, the shuffled X, Y and the full estimated distributions.
- fit (callable) –
- class pyqt_fit.bootstrap.BootstrapResult(y_fit, y_est, y_eval, CIs, shuffled_xs, shuffled_ys, full_results)¶
Note
This is a class created with pyqt_fit.utils.namedtuple().
- y_fit¶
Estimator object, fitted on the original data :type: fun(xs) -> ys
- y_est¶
Y estimated on xdata :type: ndarray
- eval_points¶
Points on which the confidence interval are evaluated
- y_eval¶
Y estimated on eval_points
- CIs_val¶
Tuple containing the list of percentiles extracted (i.e. this is a copy of the CIs argument of the bootstrap function.
- CIs¶
List of confidence intervals. The first element is for the estimated values on eval_points. The others are for the extra attributes specified in extra_attrs. Each array is a 3-dimensional array (Q,2,N), where Q is the number of confidence interval (e.g. the length of CIs_val) and N is the number of data points. Values (x,0,y) give the lower bounds and (x,1,y) the upper bounds of the confidence intervals.
- shuffled_xs¶
if full_results is True, the shuffled x’s used for the bootstrapping
- shuffled_ys¶
if full_results is True, the shuffled y’s used for the bootstrapping
- full_results¶
if full_results is True, the estimated y’s for each shuffled_ys