python - 我想制作收入与教育的散点图,但显示错误
问题描述
我正在尝试为我的统计模型类创建收入与教育的散点图,但它显示“标识符中的字符无效”但是当我检查 txt 文件时,字符“收入”和“教育”都存在。请问你能帮帮我吗?
mod = smf.ols(formula=’education~earnings, data=mydata)
res = mod.fit()
res.summary()
beta=res.params
matplotlib.pyplot.scatter(mydata["education"],mydata["earnings"],color="black")
matplotlib.pyplot.plot(mydata["education"], res.fittedvalues, "r")
matplotlib.pyplot.ylabel("earnings")
matplotlib.pyplot.xlabel("education")
matplotlib.pyplot.title("Scatterplot earnings versus education")
matplotlib.pyplot.show()
解决方案
我认为问题在于这一行后面的引号=
:
mod = smf.ols(formula=’education~earnings, data=mydata)
这让 Python 很困惑,因为它不是一个有效的变量名。公式应作为字符串传递,并带有单/双引号。
mod = smf.ols(formula='education~earnings', data=mydata)
也许在复制粘贴时有些东西混淆了?
推荐阅读
- pytorch - 如何计算邻接矩阵平方的高阶导数?
- python - 列表中项目的列表理解
- c# - 从包含特定列值的数据表中删除一行
- python - 在bash上运行python脚本时如何抑制KeyboardInterrupt输出?
- java - java spring 中的注解@Repository 是如何工作的?
- autodesk-forge - Autodesk Forge 令牌重新授权命令无法识别参数
- javascript - 通过 AJAX 将字典从 JS 发送到 Flask
- c# - 我遇到了这个错误
- css - 我可以使用两个溢出属性吗?
- php - 登录 codeigniter 后显示活动用户的详细信息