Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model fit works when running on shell, but runs into error when executing as script #87

Open
tyjchen opened this issue May 18, 2020 · 0 comments

Comments

@tyjchen
Copy link

tyjchen commented May 18, 2020

i'm trying to build a bayes model object using the survivalstan package, the model object compiles properly when the script below is executed directly on a python shell (copy + paste method into the interpreter). however, when I execute the entire script at once using the command line format, I get a variable error (see below)

File "C:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\thomasc\Documents\WeibullMethod\weibull_bayes_demo.py", line 117, in
model = main()
File "C:\Users\thomasc\Documents\WeibullMethod\weibull_bayes_demo.py", line 112, in main
make_inits = survivalstan.make_weibull_survival_model_inits)
File "C:\ProgramData\Anaconda3\lib\site-packages\survivalstan-0.1.2.8-py3.7.egg\survivalstan\survivalstan.py", line 167, in fit_stan_survival_model
File "C:\ProgramData\Anaconda3\lib\site-packages\stanity-0.1.4-py3.7.egg\stanity\fit.py", line 37, in fit
File "C:\ProgramData\Anaconda3\lib\site-packages\pystan\api.py", line 447, in stan
n_jobs=n_jobs, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\pystan\model.py", line 813, in sampling
ret_and_samples = _map_parallel(call_sampler_star, call_sampler_args, n_jobs)
File "C:\ProgramData\Anaconda3\lib\site-packages\pystan\model.py", line 87, in _map_parallel
pool.close()

how can I prevent this error? I do not wish to have to interact with a python shell directly to train a model.
code below to train model, directly same as the example code for this package
this compiles if copy and pasted directly into a shell, but fails if saved as a .py script and executed from command line as python <script name>

import survivalstan
import stanity
import seaborn as sb
import matplotlib.pyplot as plt
import statsmodels
dataset = statsmodels.datasets.get_rdataset(package = 'survival', dataname = 'flchain' )
d = dataset.data.query('futime > 7')
d.reset_index(level = 0, inplace = True)
testfit_wei = survivalstan.fit_stan_survival_model(model_cohort = 'Weibull model', model_code = survivalstan.models.weibull_survival_model, df = d, time_col = 'futime', event_col = 'death', formula = 'age + sex', iter = 3000, chains = 4, make_inits = survivalstan.make_weibull_survival_model_inits)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant