提问人:Anu_Wilson 提问时间:11/4/2023 最后编辑:Paul HAnu_Wilson 更新时间:11/4/2023 访问量:22
model=smf.ols(“员工工资~工作年限”,data=Salary).fit() 语法错误:语法无效
model=smf.ols("Employee Salary~Years Experience",data=Salary).fit() SyntaxError: invalid syntax
问:
我尝试运行此代码来拟合简单线性回归的模型
model=smf.ols("Employee Salary~Years Experience",data=Salary).fit()
但我收到一个错误:
File "/usr/local/lib/python3.10/dist-packages/IPython/core/interactiveshell.py", line 3553, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-38-5f905976ebf4>", line 1, in <cell line: 1>
model=smf.ols("Employee Salary~Years Experience",data=Salary).fit()
File "/usr/local/lib/python3.10/dist-packages/statsmodels/base/model.py", line 203, in from_formula
tmp = handle_formula_data(data, None, formula, depth=eval_env,
File "/usr/local/lib/python3.10/dist-packages/statsmodels/formula/formulatools.py", line 63, in handle_formula_data
result = dmatrices(formula, Y, depth, return_type='dataframe',
File "/usr/local/lib/python3.10/dist-packages/patsy/highlevel.py", line 309, in dmatrices
(lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
File "/usr/local/lib/python3.10/dist-packages/patsy/highlevel.py", line 164, in _do_highlevel_design
design_infos = _try_incr_builders(formula_like, data_iter_maker, eval_env,
File "/usr/local/lib/python3.10/dist-packages/patsy/highlevel.py", line 66, in _try_incr_builders
return design_matrix_builders([formula_like.lhs_termlist,
File "/usr/local/lib/python3.10/dist-packages/patsy/build.py", line 689, in design_matrix_builders
factor_states = _factors_memorize(all_factors, data_iter_maker, eval_env)
File "/usr/local/lib/python3.10/dist-packages/patsy/build.py", line 354, in _factors_memorize
which_pass = factor.memorize_passes_needed(state, eval_env)
File "/usr/local/lib/python3.10/dist-packages/patsy/eval.py", line 478, in memorize_passes_needed
subset_names = [name for name in ast_names(self.code)
File "/usr/local/lib/python3.10/dist-packages/patsy/eval.py", line 478, in <listcomp>
subset_names = [name for name in ast_names(self.code)
File "/usr/local/lib/python3.10/dist-packages/patsy/eval.py", line 109, in ast_names
for node in ast.walk(ast.parse(code)):
File "/usr/lib/python3.10/ast.py", line 50, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 1
Employee Salary
^
SyntaxError: invalid syntax
如何解决这个问题?
答: 暂无答案
评论