sibylhe / mmm_stan

Python/STAN Implementation of Multiplicative Marketing Mix Model, with deep dive into Adstock (carry-over effect), ROAS, and mROAS
MIT License
343 stars 160 forks source link

Struggled with -> RuntimeError: Initialization failed #2

Closed CGDINHA closed 3 years ago

CGDINHA commented 3 years ago

Hi Sibyl,

First, let me thank you in advance for both your post (which is pretty good) and for your help!

I wanted to use your approach in an example but I can not fix the "RuntimeError: Initialization failed" when I do the ".sampling" and I really do not know what else to do. Could you give me any little advice?

Here it goes the data I provide to "sampling", and the error messagge:

Model data:

Error message:

"RuntimeError Traceback (most recent call last)

in ----> 1 fit2 = sm2.sampling(data=model_data2, iter=2000, chains=4, verbose=True, n_jobs=1) C:\ProgramData\Anaconda3\lib\site-packages\pystan\model.py in sampling(self, data, pars, chains, iter, warmup, thin, seed, init, sample_file, diagnostic_file, verbose, algorithm, control, n_jobs, **kwargs) 811 call_sampler_args = izip(itertools.repeat(data), args_list, itertools.repeat(pars)) 812 call_sampler_star = self.module._call_sampler_star --> 813 ret_and_samples = _map_parallel(call_sampler_star, call_sampler_args, n_jobs) 814 samples = [smpl for _, smpl in ret_and_samples] 815 C:\ProgramData\Anaconda3\lib\site-packages\pystan\model.py in _map_parallel(function, args, n_jobs) 88 pool.join() 89 else: ---> 90 map_result = list(map(function, args)) 91 return map_result 92 stanfit4anon_model_c6677ffefdee0513f144508ee1783d0c_6434600101167848.pyx in stanfit4anon_model_c6677ffefdee0513f144508ee1783d0c_6434600101167848._call_sampler_star() stanfit4anon_model_c6677ffefdee0513f144508ee1783d0c_6434600101167848.pyx in stanfit4anon_model_c6677ffefdee0513f144508ee1783d0c_6434600101167848._call_sampler() RuntimeError: Initialization failed." I hope you might help me, Once again, thank you so much. Best regards.
sibylhe commented 3 years ago

Hello!

One of my readers had "RuntimeError: Initialization failed" whiling running my code with her data, and here's her solution: "I realized the issue is with Y variable. I made sure there were no missing data and all positive in Y. But there are good amount of Y which are 0. upon imputing them with mean, I could build the model."

I think errors at the sampling stage are highly likely to be related to the input data. You may want to check your data quality or if the data meet the constraints specified in the model code "data" section (e.g., specified x, but the actual data 'x' has negative values).

CGDINHA commented 3 years ago

Hi Sibyl,

Thanks for you quick response, I could fix it, I hope I will not have to disturb you any more in the future.

Once again, thank you so much. Best regards.