Open qingzma opened 6 years ago
Multivariate (or high dimensional) piecewise regression can get complicated quickly.
I don't have any current plan for expanding pwlf to higher dimensions, but the conversation has come up before. There are some physical problems with insight that might be better described by a segmented regression problem.
I'm fairly committed at the moment, but I could implement some methods from http://www3.stat.sinica.edu.tw/statistica/oldpdf/A7n213.pdf at some future time
This brings up another point, should pwlf support non-continuous piecewise linear regression?
I agree.... multivariate piecewise linear regression grow complicated very quickly, and I do not find any package to support this function yet. Anyway, thanks so much for the reply!
I'm considering adding multivariate support following the style of a general additive model.
Branch multivariate has an initial multivariate pwlf model.
The final function follows the style of a general additive model (GAM), where 1D piecewise continuous fits are performed for each univariate feature. The 1D models can be assembled in polynomial form, with default multivariate_degree=1
. Finally a least square solution provides the final parameters of the additive model.
I'm still working on the syntax, but the general idea will be something like this
"""
x : ndarray (2-D)
The x or independent data point as a 2 dimensional numpy array.
This should be of shape (n, m), for n number of data points, and m
number of features.
y : array_like
The y or dependent data point locations as list or 1 dimensional
numpy array.
"""
n_segments = 2 # number of line segments for each univariate
my_mv_model = pwlf.PiecewiseMultivariate(x, y, n_segments,
degree=1, # degree of each univariate
multivariate_degree=3 # degree of the GAM
)
my_mv_model.fit()
I believe these fits to the Branin-Hoo function shows some promise: https://github.com/cjekel/piecewise_linear_fit_py/blob/multivariate/examples/multivariate/braninhoo.py
Fits to the Adjiman function https://github.com/cjekel/piecewise_linear_fit_py/blob/multivariate/examples/multivariate/adjiman.py
What this need in order to be merged into master:
fitfast
, fit
, or fit_guess
)= b0 + b1*x1 + b2*x2 + b3*x1*x2 ...
)Feel free to chime in for features, or comments about the api.
Does this code support multivariate piecewise linear regression? Or is there any plan to support this?