linear-regression - 拟合回归后如何使用Seaborn的residplot?
问题描述
我在 Python 中有一个简单的线性多元回归,如下所示:
X_train,X_test,y_train,y_test=train_test_split(x_cols,df['Volume'],test_size=0.15)
regr = LinearRegression()
regr.fit(X_train, y_train)
y_pred = regr.predict(X_test)
如何绘制该模型的残差?
起初我试过这个:
sns.residplot(y_pred, y_test)
但我不确定这是否真的显示了线性回归的残差。我是否将正确的参数传递给了 residplot?
解决方案
不,您需要将 x 和 y 作为参数传递,然后residplot
运行回归并绘制残差。您可以在此处
阅读更多信息:residplot
df = pd.DataFrame({
'X':np.random.randn(60),
'Y':np.random.randn(60),
})
sns.residplot('X','Y',data=df)
推荐阅读
- reactjs - 传递的道具在功能组件中未定义
- oracle - oracle apex 分支 - 页面重定向
- mongodb - 附近的 MongoDB 查询
- python - 我的一些数据框值包括字典,而另一些则包含值。如何删除字典?
- c - 为什么我在这个 c 代码上遇到分段错误?
- angular - 访问对象数组中的对象属性Angular 9
- python - 错误:blog.Post:(models.E015)“排序”是指不存在的字段、相关字段或查找“发布”。我该如何解决?
- python - IOError: [Errno 2] 移动文件后
- ruby-on-rails - Rails 测试预期 NIL
- swift - 单击另一个文本字段时禁用交互式文本字段