segreg.model.TwoBkptSegRegEstimator¶
- class TwoBkptSegRegEstimator(num_end_to_skip=None, num_between_to_skip=None, no_bias_variance=False)[source]¶
Estimator for two-bkpt segmented regression.
This estimator is limited to univariate, continuous, linear, two-bkpt segmented regression problems. The model fitting estimates the parameters:
[u1, v1, u2, v2, m1, m2, sigma]
where
(u1,v1), (u2, v2)
are the breakpoints (in x-y plane), ordered such thatu1 < u2
m1
is the slope of the left-most segmentm2
is the slope of the right-most segmentsigma
is the standard deviation of the residualsNotes
The slope of the middle segment of the two-bkpt model does not appear as a parameter since it is implied by the parameters
(u1, v1)
and(u2, v2)
.- Parameters
num_end_to_skip (int) – Number of data points to skip at each end of the data when solving for the bkpts. As such, this determines a guaranteed minimum number of data points in the left-most and right-most segments in the returned fit. If None, defaults to the underlying implementation. TODO: explain
num_between_to_skip (int) – Number of data points to skip between the two bkpts (ie: the middle segment) when solving for the bkpts. Specifically, for each choice of left bkpt
u1
, will skip this many data points betweenu1
andu2
. As such, this determines a guaranteed minimum number of data points between the bkpts in the returned fit.
Examples
>>> from segreg.model import TwoBkptSegRegEstimator >>> indep = [1,2,3,4,5,6,7,8,9,10,11,12,13,14] >>> dep = [1,2,3,4,5,4,3,2,1,0,1,2,3,4] >>> estimator = TwoBkptSegRegEstimator() >>> estimator.fit(indep, dep) array([ 5., 5., 10., -0., 1., 1., 0.])
See also
Methods
fit
(indep, dep)Fit the model to the given data.
get_func_for_params
(params)Returns the regression model function defined by the given parameters.
Properties
Indices in the parameter array of the fitted parameters.
Whether there are any model parameters set to a fixed value.
Computes loglikelihood at the MLE (maximum likelihood estimate).
Returns the regression model function defined by the estimated parameters.
Number of model parameters.
Names of the parameters.
Returns the fitted parameters.
R-squared of the fit.
Returns the residuals from the fit.
Residual sum of squares of the fit.