segreg.model.alt.fit_one_bkpt

fit_one_bkpt(indep, dep, num_end_to_skip=2, verbose=False, optimize=True)

Estimate one-bkpt segmented regression model.

This method is limited to univariate, continuous, linear, one-bkpt segmented regression problems. Estimates the parameters:

[u, v, m1, m2]

where

(u,v) is the breakpoint (in x-y plane)

m1 is the slope of the left-hand segment

m2 is the slope of the right-hand segment

Parameters
  • indep (numpy array of shape (num_data,)) – The independent data. Also called predictor, explanatory variable, regressor, or exogenous variable.

  • dep (numpy array of shape (num_data,)) – The dependent data. Also called response, regressand, or endogenous variable.

  • 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 and right segments in the returned fit. If None, defaults to the underlying implementation. TODO: explain

  • verbose (bool) –

  • optimize (bool) – If True, will implement a few optimizations in the algorithm when appropriate.

Examples

>>> import numpy as np
>>> from segreg.model.alt import fit_one_bkpt
>>> indep = np.array([1,2,3,4,5,6,7,8,9])
>>> dep = np.array([1,2,3,4,5,4,3,2,1])
>>> fit_one_bkpt(indep, dep)
(array([ 5.,  5.,  1., -1.]), 0.0)
Returns

  • params (array of shape (num_params,)) – The estimated parameters. The returned parameters are, in order, [u, v, m1, m2].

  • rss (float) – Residual sum of squares of the fit.