luke14free / pm-prophet Goto Github PK
View Code? Open in Web Editor NEWGAM timeseries modeling with auto-changepoint detection. Inspired by Facebook Prophet and implemented in PyMC3
GAM timeseries modeling with auto-changepoint detection. Inspired by Facebook Prophet and implemented in PyMC3
hey there! could you attach a license to this repo? Am I free to fork it and use it? (https://help.github.com/articles/licensing-a-repository/) Thanks!
As it is, it is hard to gain a sense of where this project is going, or what needs to still be done (and what exactly has been accomplished), which an updated readme would solve.
Not only would this improve readability, but help others help out with contributions as well.
Hi!
I am trying to use the pm-prophet feature auto_changepoints to detect changepoints in a dataset. It gives seemingly good results, but when running the script on the same dataset twice, the inferred changepoints are located different places. How can i make the auto_changepoints more accurate? does this have to do with my sample size?
I've been reading through the code and I met this line at model.py, line 293:
additive_seasonality *= self.data.y.max()
and in a few other places around the code. Could anyone comment on its exact purpose?
This seems to me to be related to data standartisation, but data standartisation is also done later, in the model specification:
observed=(self.data['y'] - self.data['y'].mean()) / self.data['y'].std()
At the very least, shouldn't it be
additive_seasonality *= self.data.y.abs().max()
to account for the possiblity that, say, range of y is [-1,0] and thus y.max()==0 ?
Hi,
PyMC3 has been renamed PyMC. If this affects you and you have questions, or you want someone to direct your rage at I'm available! Do let me know how i, or any of the PyMC devs can help.
Ravin
Trying to run the same simple model with version 0.2.1, I get the error below.
m = PMProphet(df_city, name='model')
# Fit the model (using NUTS)
m.fit(method='NUTS')
~/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pmprophet/model.py in fit(self, draws, chains, trace_size, method, map_initialization, finalize, step_kwargs, sample_kwargs)
610 if draws:
611 if method != Sampler.ADVI:
--> 612 step_method = method.value(**step_kwargs)
613 self.trace = pm.sample(
614 draws,
AttributeError: 'str' object has no attribute 'value'
Currently we specify one prior distribution for all the regressors. Is it possible to customize each regressor's prior?
Can the prior definition for each regressor be moved within the add_regressor() method by passing the distribution object as a parameter?
Can a regressor_coefficients() method be created similar to what Prophet has to get the distribution of coefficients?
Hi!
I have been working with the source code to pm-prophet for a while, and I am wondering about how the fourier-series and the accompanying coefficients a1,b1,a2,b2,....,an,bn in the standard fourier series are sampled. As far as I can tell, the fourier_series() function returns both sine and cosine series with length of input data t, but self.data["f%s_%s"%(seasonality,order_idx)]_ only uses the sine series. As an example, a fourier_series of order 4 should have 8 self.priors["seasonality"] -RVs but has only 4.
How is this fourier series modelled?
Thank you in advance!
Hi,
Great package. I was considering attempting something similar, but was very grateful to find your implementation!
I'm modelling data that is generally periodic and trending but is heteroskedastic and rather than transform the heteroskedasticity out of the data as is usually recommended, I would like to model it specifically. My sense is that the GAM approach used by Prophet could model the data very well if I could model the varying variance explicitly.
My initial desire is to try to model the variance itself, as opposed to the original timeseries, and see if I can identify the points where the variance changes.
To that end, I'm trying to better understand how the truncated dirichlet process used herein and copied below accomplishes this. In particular, I don't understand the use of tt.extra_ops.cumprod(1 - beta)[:-1]
is this the stickbreaking function?
Also, how does the switch work exactly at tt.switch(tt.gt(x, 1e-4), x, 0)
k = self.n_changepoints
alpha = pm.Gamma("alpha_%s" % self.name, 1.0, 1.0)
beta = pm.Beta("beta_%s" % self.name, 1.0, alpha, shape=k)
w1 = pm.Deterministic(
"w1_%s" % self.name,
tt.concatenate([[1], tt.extra_ops.cumprod(1 - beta)[:-1]])
* beta,
)
w, _ = theano.map(
fn=lambda x: tt.switch(tt.gt(x, 1e-4), x, 0), sequences=[w1]
)
self.w = pm.Deterministic("w_%s" % self.name, w)
can I access the probabilities for a given time-step being a changepoint after sampling?
Thanks in advance
can you package work with multivariate categorical time series and multivariate time series when some features are categorical and some some features are continues
Hi and thank you for this very useful project! It's been a while since I wanted to give it a try and I finally found a use case :)
However, trying to get started, I couldn't run the model you have in the examples: when hitting m.fit(method='NUTS')
I encountered:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-f9eeec8c375f> in <module>
1 # Fit the model (using NUTS)
----> 2 m.fit(method='NUTS')
~/opt/anaconda3/envs/fund/lib/python3.7/site-packages/pmprophet/model.py in fit(self, draws, chains, trace_size, method, map_initialization, finalize, step_kwargs, sample_kwargs)
610 if draws:
611 if method != Sampler.ADVI:
--> 612 step_method = method.value(**step_kwargs)
613 self.trace = pm.sample(
614 draws,
AttributeError: 'str' object has no attribute 'value'
I also tried on the dataframe I'm trying to fit and it has the same behavior. Does it look like an issue? Or could it come from my installation? I'm running on pm-prophet 0.2.8, PyMC3 master and theano 1.0.4.
Thanks in advance for your help, and thanks again for your work!
As per title! ๐ I like a lot of what's going on here, and would love to see a few things happen:
cc: @Emaasit, creator of pymc-learn, and @parsing-science, creator of pymc_models.
Hello Developers of this wonderful repository,
I have tried samples. It looks good. But I haven't got any settings for the usage of GPU. It works with the CPU only. What if I am willing to go with the GPUs in my system for the training?
Can you help and guide me?
When running the examples from model.py and readme I get the following error:
ValueError: Of the three parameters: start, end, and periods, exactly two must be specified
Unit tests are needed to guard the code from bugs.
Could you please provide an update?
do you have example to use your code like prophet with multiple regressores ?
or
y(t) = trend(t) + seasonality(t) + beta1 * regressor1(t) + beta2 * regressor2(t) + ...
Would be nice to just do pip install pmprophet
:)
Hello,
I use PMProphet with several features. Since I don't know the future value of the features, I generate a lot of scenarios. Is there any way to pass all these scenarios to model so that the uncertainty of the result consists of two (uncertainty of the model coefficients and uncertainty of the features)? Or is there any way to introduce such functionality using the capabilities of pymc3 (without making a loop through the scenarios) ?
Hi-- first off. thank you for making this. i have been looking for a pymc3 based prophet alternative for a while (not a fan of the installation process for pystan)..
I am trying to run this peyton manning example from the read me, and the underlying module is using the deprecated ix function. Any way we could upgrade the module for the latest version of pandas? Ive never submitted a pull requests but I can potentially help.
I tried to run a very simple model with weekly data from a pandas dataframe and get the below error. I'm not sure how to troubleshoot this. I get the same error if I add more explicit params for changepoints etc.
FYI, this exact dataset has been fit with fbprophet successfully.
Version: pmprophet-0.2
Python: Python 3.6.7
m = PMProphet(df_city, name='model')
m.fit(method='NUTS')
~/.pyenv/versions/3.6.7/lib/python3.6/site-packages/pmprophet/model.py in generate_priors(self)
243 else:
244 k = len(self.changepoints)
--> 245 cgpt = pm.Deterministic('cgpt', w * pm.Laplace('cgpt_inner', 0, self.changepoints_prior_scale, shape=k))
246 self.priors['changepoints'] = pm.Deterministic('changepoints_%s' % self.name, cgpt)
247 if self.intercept and 'intercept' not in self.priors:
UnboundLocalError: local variable 'w' referenced before assignment
Hi,
I am trying to use pm-prophet to forecast data with little seasonality. When using the predict function, I would assume that the forecast gets less and less certain over time, some kind of diverging confidence interval. It however seems to me there is only a linear forecast being performed. Does the pm-prophet support what I am looking for?
Here is my code for convenience:
sd = .1
N = 200
deltas = np.random.normal(scale=sd, size=N)
y = np.cumsum(deltas)
x = np.arange(N)
df = pd.DataFrame() ## label
df["ds"] = pd.date_range(start="2018-01-01", periods=200)
df["y"] = y
print(df)
m = PMProphet(df, auto_changepoints=True, growth=True, name="model")
m.fit(method=Sampler.METROPOLIS, chains=1, draws=2000)
pm.traceplot(m.trace)
plt.show()
m.predict(50, alpha=0.2, include_history=True, plot=True)
m.plot_components(intercept=False)
plt.show()
Hi
How is this different from FBProphet?
Is there some reference document available for this? Thanks
Hi,
Could the datapoints df["y"] in a time-series analysis be distributed random variables. For example df["y"] = [pm.Normal(mu=10, sd=1), pm.Normal(mu=4, sd=1,....]?
I am trying to reproduce the example using example_wp_log_peyton_manning.csv with Python 2.7. I have all of the correct dependencies from the requirements file, but I keep getting the error
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `intercept_model`.ravel()[0] is zero.
The derivative of RV `changepoints_model`.ravel()[0] is zero.
The derivative of RV `seasonality_model`.ravel()[2] is zero.
The derivative of RV `seasonality_model`.ravel()[3] is zero.
The derivative of RV `seasonality_model`.ravel()[4] is zero.
The derivative of RV `seasonality_model`.ravel()[5] is zero.
The derivative of RV `sigma_model_log__`.ravel()[0] is zero.
The code I used is attached with references to matplotlib removed
test.txt
with versions:
theano == 1.0.3
numpy == 1.15.3
pandas == 0.23.4
pymc3 == 3.5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.