我正在嘗試在 JupyterLab 上的 ipynb 筆記本上使用 patsy 包創(chuàng)建 B 樣條線:from patsy import dmatrixbs = dmatrix("bs(x, df=50, degree=1) - 1", {"x": x})axes[0].plot(x, bs)axes[0].set_title("Basis functions")plt.show()我第一次運行它時效果很好。但是當(dāng)我嘗試再次重新運行此單元時,它失敗并出現(xiàn)以下錯誤:-----------------------------------------------------TypeError Traceback (most recent call last)/opt/conda/lib/python3.8/site-packages/patsy/compat.py in call_and_wrap_exc(msg, origin, f, *args, **kwargs) 35 try:---> 36 return f(*args, **kwargs) 37 except Exception as e:/opt/conda/lib/python3.8/site-packages/patsy/eval.py in eval(self, expr, source_name, inner_namespace) 16 code = compile(expr, source_name, "eval", self.flags, False)--> 165 return eval(code, {}, VarLookupDict([inner_namespace] 166 + self._namespaces))<string> in <module>TypeError: 'DesignMatrix' object is not callableThe above exception was the direct cause of the following exception:PatsyError Traceback (most recent call last)<ipython-input-6-6ed4ba95a384> in <module> 2 3 _, axes = plt.subplots(2, figsize=(16, 16))----> 4 bs = dmatrix("bs(x, df=50, degree=1) - 1", {"x": x}) 5 axes[0].plot(x, bs) 6 axes[0].set_title("Basis functions")/opt/conda/lib/python3.8/site-packages/patsy/highlevel.py in dmatrix(formula_like, data, eval_env, NA_action, return_type) 288 """ 289 eval_env = EvalEnvironment.capture(eval_env, reference=1)--> 290 (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env, 291 NA_action, return_type) 292 if lhs.shape[1] != 0:
1 回答

FFIVE
TA貢獻(xiàn)1797條經(jīng)驗 獲得超6個贊
最終這是因為我自己覆蓋了變量bs
,因此覆蓋了bs
patsy 字符串內(nèi)的函數(shù)。
這就是為什么 eval 像往常一樣是反模式......
添加回答
舉報
0/150
提交
取消