RuntimeError: (NameError("name 'dist' is not defined")
Closed this issue · 1 comments
Hi,
Thank you so much for building this awesome library. I was following along on your blogs' notebook about probabilistic model. At the second to the last cell:
"df[-400:].model.backtest(
fit_vv.model,
PriceSampledSummary.with_reconstructor(
label_returns=lambda y: np.exp(y) - 1,
label_reconstruction=lambda y: y.ta.cumlogret(),
sampler=wrap_applyable(lambda params, samples: dist((params[...,0], params[...,1])).sample([int(samples.item())]), nr_args=2),
samples=100,
confidence=0.8,
)
)"
I encountered a run time error on dist. Would you mind helping me on finding out what went wrong here? I followed the install instructions and run the notebook as it is,. Please find full error log as below:
NameError Traceback (most recent call last)
~/.local/lib/python3.7/site-packages/pandas_ml_common/utils/callable_utils.py in call_callable_dynamic_args(func, *args, **kwargs)
30 try:
---> 31 return func(*callable_args.args, **callable_args.kwargs)
32 except StopIteration as s:
~/.local/lib/python3.7/site-packages/pandas_ml_quant/model/summary/price_prediction_summary.py in (df, model, **kwargs2)
155 sampler,
--> 156 **{**kwargs, **kwargs2}
157 )
~/.local/lib/python3.7/site-packages/pandas_ml_quant/model/summary/price_prediction_summary.py in init(self, df, model, label_returns, label_reconstruction, sampler, confidence, forecast_period, samples, bins, figsize, **kwargs)
196
--> 197 self.cdf = self._estimate_ecdf()
198
~/.local/lib/python3.7/site-packages/pandas_ml_quant/model/summary/price_prediction_summary.py in _estimate_ecdf(self)
202
--> 203 return params.apply(lambda r: ECDF(self.sampler(r)), axis=1, result_type='expand')
204
~/.local/lib/python3.7/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwargs)
8735 )
-> 8736 return op.apply()
8737
~/.local/lib/python3.7/site-packages/pandas/core/apply.py in apply(self)
687
--> 688 return self.apply_standard()
689
~/.local/lib/python3.7/site-packages/pandas/core/apply.py in apply_standard(self)
811 def apply_standard(self):
--> 812 results, res_index = self.apply_series_generator()
813
~/.local/lib/python3.7/site-packages/pandas/core/apply.py in apply_series_generator(self)
827 # ignore SettingWithCopy here in case the user mutates
--> 828 results[i] = self.f(v)
829 if isinstance(results[i], ABCSeries):
~/.local/lib/python3.7/site-packages/pandas_ml_quant/model/summary/price_prediction_summary.py in (r)
202
--> 203 return params.apply(lambda r: ECDF(self.sampler(r)), axis=1, result_type='expand')
204
~/.local/lib/python3.7/site-packages/pandas_ml_utils_torch/utils.py in wrapped(cells)
47
---> 48 x = func(*x)
49 return (x.numpy() if sum(x.shape) > 1 else x.item()) if return_numpy else x
in (params, samples)
5 label_reconstruction=lambda y: y.ta.cumlogret(),
----> 6 sampler=wrap_applyable(lambda params, samples: dist((params[...,0], params[...,1])).sample([int(samples.item())]), nr_args=2),
7 samples=100,
NameError: name 'dist' is not defined
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
in
6 sampler=wrap_applyable(lambda params, samples: dist((params[...,0], params[...,1])).sample([int(samples.item())]), nr_args=2),
7 samples=100,
----> 8 confidence=0.8,
9 )
10 )
~/.local/lib/python3.7/site-packages/pandas_ml_utils/df_patching/model_patch.py in backtest(self, model, summary_provider, tail, **kwargs)
179 frames.sample_weights, frames.features)
180
--> 181 return call_callable_dynamic_args(summary_provider or model.summary_provider, df_backtest, model, **kwargs)
182
183 def predict(self,
~/.local/lib/python3.7/site-packages/pandas_ml_common/utils/callable_utils.py in call_callable_dynamic_args(func, *args, **kwargs)
44 source = "eval"
45
---> 46 raise RuntimeError(e, f"error while calling {func}({inspect.getfullargspec(func)})\n{source}\nwith arguments:\n{callable_args}, {kwargs}")
47
48
it is actually not very important and exxentially the same piece of code as in the cell above just zooming into the most recent 400 timesteps.
from torch.distributions import Normal
df[-400:].model.backtest(
fit_vv.model,
PriceSampledSummary.with_reconstructor(
label_returns=lambda y: np.exp(y) - 1,
label_reconstruction=lambda y: y.ta.cumlogret(),
sampler=wrap_applyable(lambda params, samples: Normal(params[...,0], params[...,1]).sample([int(samples.item())]), nr_args=2),
samples=100,
confidence=0.8,
)
)
I will push a fix eventually ...
PS or cherrypick the commit hash 31c50a3