使用 statsmodels pythton 的 OLS 中的语法无效
我想尝试对某些数据进行回归。
country_scores=country_scores.rename(columns={"Median Math Score (TIMSS Scale, 4th Grade)": "Median Math Score"})
country_scores_log2 = country_scores.copy()
country_scores_log2['GDP Per Capita'] = np.log2(country_scores_log2['GDP Per Capita'].astype(float))
mod = smf.ols(formula="GDP Per Capita ~ Median Math Score", data=country_scores_log2)
res = mod.fit()
print(res.summary())
当我尝试此操作时,我总是会出现一个错误:
File "C:\ProgramData\Anaconda3\lib\ast.py", line 50, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 1
Median Math Score
^
SyntaxError: invalid syntax
I want to try regression on some data.
country_scores=country_scores.rename(columns={"Median Math Score (TIMSS Scale, 4th Grade)": "Median Math Score"})
country_scores_log2 = country_scores.copy()
country_scores_log2['GDP Per Capita'] = np.log2(country_scores_log2['GDP Per Capita'].astype(float))
mod = smf.ols(formula="GDP Per Capita ~ Median Math Score", data=country_scores_log2)
res = mod.fit()
print(res.summary())
When I try this, I always get an error saying:
File "C:\ProgramData\Anaconda3\lib\ast.py", line 50, in parse
return compile(source, filename, mode, flags,
File "<unknown>", line 1
Median Math Score
^
SyntaxError: invalid syntax
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,在我使用的包装中,模型拟合的模型拟合语法将采用不同的模型语法。尝试以下操作:
通常,我使用的语法是格式:
y是您的目标变量,x是一个或多个输入变量的矩阵/数据表。
我个人写的方式将是:
如果您想使用一个或多个其他变量弄乱不同的输入,则可以将“中值数学得分”替换为列表。
Typically, the syntax for model fits in python across the packages I have used will take a different model syntax. Try this:
In general, the syntax that I use is of the format:
y being your target variable and X being a matrix/data table of one or more input variables.
The way I would personally write it would be:
Where you could replace "Median Math Score" with a list if you wanted to mess around with different inputs using one or more of your other variables.