trendpy2 package¶
It is recommended to use the Trend
object from the trendpy2.models, the methods from trendpy2.methods are contained as attributes
of that objects.
However, you can also use the methods from trendpy2.methods in a standalone way ;)
trendpy2.models module¶
- class trendpy2.models.Trend(x, y, ansatz, deg=None, freeRegAnsatz=None)[source]¶
Bases:
object
Trends Class. Initialization of Trend with training input, training output, ansatz (string) and deg (if polynomial ansatz). The following ansatz are supported ‘linReg’, ‘polReg’, ‘expReg’, ‘trigReg’, ‘freeReg’.
>>> from trendpy2 import models as tpm >>> x = np.array([1, 2, 3]) >>> y = np.array([1, 1.5, 3.5]) >>> lin = tpm.Trend(x, y, 'linReg')
trendpy2.methods module¶
- trendpy2.methods.expReg(x_in, y)[source]¶
Time series exponential regression.
>>> from trendpy2 import methods as tm >>> import numpy as np >>> x = np.array([0, 1, 2]) >>> y = 2*np.exp(x) >>> tm.expReg(x, y) >>> array([2., 1.])
- trendpy2.methods.freeReg(x_in, y_out, ansatz)[source]¶
Regression with user ansatz. The ansatz is expected to depend on three parameters, a, b, and c. The ansatz is expected to be a string with a symbolic formulation. for instance: ‘a*arctan(b*x_in+c)’.
>>> from trendpy2 import methods as tm >>> import numpy as np >>> x = np.array([0, 1, 2, 3]) >>> y = 2*(1-3*np.exp(-x)) >>> tm.freeReg(x, y, ansatz='a*(1-b*exp(-c*x))') >>> array([2., 3., 1.])
- trendpy2.methods.linReg(x_in, y)[source]¶
Time series linear regression. Returns coefs in polynomial descending order. Coefs computed analytically.
>>> from trendpy2 import methods as tm >>> import numpy as np >>> x = np.array([1, 2, 3]) >>> y = np.array([1, 1.5, 3.5]) >>> tm.linReg(x, y) >>> [1.25, -0.5]
- trendpy2.methods.polReg(x_in, y, deg)[source]¶
Time series polynomial regression. Returns coefs in polynomial descending order. Coefs computed numerically.
>>> from trendpy2 import methods as tm >>> import numpy as np >>> x = np.array([0, 1, 2]) >>> y = np.array([0, 2, 4]) >>> tm.polReg(x, y, 2) >>> array([ 8.96585976e-17, 2.00000000e+00, -9.55246329e-17])