GithubHelp home page GithubHelp logo

lavinei / pybats Goto Github PK

View Code? Open in Web Editor NEW
105.0 105.0 24.0 15.01 MB

Bayesian time series forecasting and decision analysis

Home Page: https://lavinei.github.io/pybats/

License: Apache License 2.0

Python 17.08% Makefile 0.03% Jupyter Notebook 82.89%

pybats's People

Contributors

bking124 avatar dependabot[bot] avatar lavinei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pybats's Issues

DCMM with No Regressors Not Possible

Dear Isaac,

First off, I'm so glad this package exists and it has lots of cool features. I am currently looking at univariate count data with lots of zeroes and wanted to compare the Poisson DGLM forecasting performance with that of a DCMM. However, it seems that currently the analysis_dcmm function requires some input for the covariates X, and inputting None (like the default in the regular analysis function) throws an error of 'NoneType object not subscriptable'. I was able to 'monkey patch' a few of the functions in the package to get it to work for my case, but I think this is a capability that would probably be desirable for others.

I can create a reproducible example of the error if needed! Thanks!

Sincerely,
Brian

Reference for initialization procedure (define_?_params routines)

It would be helpful if a reference to, or how, the define_glm_params (and the others) get their parameters.

For large prior_length the linear regression looks natural and the small size correction g/(1+g) is very close to 1, but I am not sure why g=int(n/2) (t-student moments suggest g=n).

Also, the returned "n" is - except the case of degeneracy in regressors - the number of degrees of freedom (number of observations minus the number of covariates) in the linear regression, while a naïve approach, applying a constant DLM model suggests the number of observations or that plus one.

If the reference are given, probably these objections are responded there.

Wrong graphical output?

It seems that there is some issue with the plots. When I run the 1-day example in the docs, I found the graph attached. I think that the forecast and observation labels have been swapped (wrongly), isn't it? It is like the confindence interval has been plot for the observations.

In the docs the labels seem to be properly placed. What is the source of this difference? I am running exactly the same code.

Regards
Figure_1

Creating a model and forecasting with a single time series

Is it possible to use pybats to forecast with only univariate time series data? It seems like X needs to be populated when making a model. I was thinking that you could just put the time index or just put a lagged version of Y in for X.

Separately, I saw other questions asking how to forecast for Y_{t+k} given only information of X_{t}. It wasn't clear to me how you could do this without keeping a separate forecaster for X. It would be nice to be able to make forecasts without data until the next observation (usually when you get access to both X_{t+k} and Y_{t+k}.

How to actually forecast?

When tested with the examples it works beautifully but whenever asked to forecast more data than available it doesn't do anything.

Am I missing something or should i use the generated model for that.

`forecast_path` does not work when using holidays

I'm unable to generate a forecast_path on a model with holiday regressors. The example below uses slightly modified code fro the order forecast example.

test_df = data.loc[forecast_start:forecast_end]

model = analysis(
    train_df.Sales.values, 
    X=None, 
    family='poisson',
    seasPeriods=[7], 
    seasHarmComponents=[[1,2,3]],
    prior_length=prior_length, 
    dates=train_df.index, 
    holidays=USFederalHolidayCalendar.rules,
    rho=rho,
    ret = ['model']
)

model.forecast_path(k=10)

This results in the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-f1091b7e298d> in <module>
     15 )
     16 
---> 17 model.forecast_path(k=10)

/jupyter/packages/pybats/dglm.py in forecast_path(self, k, X, nsamps, copula, phi_mu, phi_sigma, phi_psi, analytic, phi_samps, **kwargs)
    287         else:
    288             if copula:
--> 289                 return forecast_path_copula(self, k, X, nsamps, **kwargs)
    290             else:
    291                 return forecast_path(self, k, X, nsamps)

/jupyter/packages/pybats/forecast.py in forecast_path_copula(mod, k, X, nsamps, t_dist, y, nu, return_cov)
    185         # Plug in the correct F values
    186         if mod.nregn > 0:
--> 187             F = update_F(mod, X[i, :], F=F)
    188         # if mod.nregn > 0:
    189         #     F[mod.iregn] = X[i,:].reshape(mod.nregn,1)

TypeError: 'NoneType' object is not subscriptable

Update and Forecast Model - ValueError: p < 0, p > 1 or p contains NaNs

Hello, Lavinei,

I've decided to apply your approach to my own data and had no success with the error above:

/usr/local/lib/python3.6/dist-packages/pybats/dglm.py in simulate_from_sampling_model(self, p, nsamps)
415
416 def simulate_from_sampling_model(self, p, nsamps):
--> 417 return np.random.binomial(1, p, [nsamps])
418
419 def simulate_from_prior(self, alpha, beta, nsamps):

mtrand.pyx in numpy.random.mtrand.RandomState.binomial()

_common.pyx in numpy.random._common.check_array_constraint()

ValueError: p < 0, p > 1 or p contains NaNs

Link to the code: https://colab.research.google.com/drive/1_5LHVy1_EHRoohPhk8Dk26xTnVLooCRS?usp=sharing
I could send you the data by email, if it is possible.

Thanks!

Regards,
Nikita

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.