Comments (3)
I did some simple test with 2-segment piecewise linear regression (unspecified breakpoints). I could output the breakpoints, which looked correct, and then I obtained yHat[0], (yHat[breakpointidx] - yHat[0]) / breakpointidx, (yHat[-1] - yHat[breakpointidx]) / (len(yHat) - breakpointidx)
, which should be expected to be very close to beta[0], beta[1], beta[2]
. However, I could see the value of beta[-1]
was different from (yHat[-1] - yHat[breakpointidx]) / (len(yHat) - breakpointidx)
even by the sign.
from piecewise_linear_fit_py.
The source code appears all solid to me. I used fitfast
but tested fit
too -- both called fit_with_breaks
, which altered beta
via lstsq
, seemingly a wrapper for scipy.linalg.lstsq
.
I guess the issue is probably not a bug in the code, but in my interpretation. Any comments would be appreciated.
from piecewise_linear_fit_py.
beta[-1]
can be negative! You just haven't had a curve with a steep enough slope yet at the end. The final slope needs to cancel out the accumulation of all previous slopes. Slopes on the right are the accumulation of all previous beta values (except the y-intercept aka. beta[0]).
See
import numpy as np
import matplotlib.pyplot as plt
import pwlf
# generate sin wave data
x = np.linspace(0, 11, num=100)
y = np.sin(x * np.pi / 2)
# add noise to the data
y = np.random.normal(0, 0.05, 100) + y
my_pwlf_1 = pwlf.PiecewiseLinFit(x, y, degree=1)
# fit the data for four line segments
res1 = my_pwlf_1.fitfast(5, pop=50)
# predict for the determined points
xHat = np.linspace(min(x), max(x), num=10000)
yHat1 = my_pwlf_1.predict(xHat)
print('beta', my_pwlf_1.beta)
# plot the results
plt.figure()
plt.plot(x, y, 'o', label='Data')
plt.plot(xHat, yHat1, '--', label='degree=1')
plt.legend()
plt.show()
beta [ 1.06781215 -0.5918096 1.87834207 -2.49662666 2.37475738 -2.42097531]
from piecewise_linear_fit_py.
Related Issues (20)
- p values does not seem accurate HOT 3
- Error for coefficients of linear equations HOT 7
- pwlf with unknown line segments HOT 9
- assure the slopes to be lower and lower HOT 1
- divide by zero error in calc slopes if two break points are the same, or if a breakpoint is on the boundary HOT 2
- Issue using .fit() HOT 5
- How to plot segments with fit_breaks information HOT 4
- support random seed on init
- How to calculate prediction intervals? HOT 1
- .fit() fails with 1 segment HOT 5
- How to force the fit process to have a fixed Intercept? HOT 1
- Can I get y_values if I have only x and slopes values? HOT 1
- Limit the slope of each segment of the curve HOT 1
- Re-constructing Piecewise PWLF HOT 2
- Set Slope of Segment to 0 HOT 2
- How to fit multiple functions simultaneously HOT 3
- Hi, i want to make sure that there are no fitted lines between points that are too far apart i.e. set a min value( fragment optimization) how to achieve this? HOT 1
- How to prevent poor fitting HOT 4
- Forcing the segments to be integers and not float
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from piecewise_linear_fit_py.