Plotly: How to find coefficient of trendline in plotly express?(Plotly:如何在 plotly express 中找到趋势线的系数?)
本文介绍了Plotly:如何在 plotly express 中找到趋势线的系数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
How do you find the coefficient of the trend line in plotly express?
For example I used the code below to chart the trend line but now I want to know the coefficient.
import plotly.express as px
px.scatter(df, x='x_data', y='y_data', trendline="ols")
解决方案
Here you need to have a look at plotly doc in plotly
and statsmodels one. I think the example in the plotly example should be fixed. Anyway
import plotly.express as px
df = px.data.tips()
fig = px.scatter(df, x="total_bill", y="tip", trendline="ols")
fig.show()
For the results you should run
results = px.get_trendline_results(fig)
results = results.iloc[0]["px_fit_results"].summary()
print(results)
OLS Regression Results
==============================================================================
Dep. Variable: y R-squared: 0.457
Model: OLS Adj. R-squared: 0.454
Method: Least Squares F-statistic: 203.4
Date: Mon, 10 Aug 2020 Prob (F-statistic): 6.69e-34
Time: 12:28:52 Log-Likelihood: -350.54
No. Observations: 244 AIC: 705.1
Df Residuals: 242 BIC: 712.1
Df Model: 1
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------
const 0.9203 0.160 5.761 0.000 0.606 1.235
x1 0.1050 0.007 14.260 0.000 0.091 0.120
==============================================================================
Omnibus: 20.185 Durbin-Watson: 1.811
Prob(Omnibus): 0.000 Jarque-Bera (JB): 37.750
Skew: 0.443 Prob(JB): 6.35e-09
Kurtosis: 4.711 Cond. No. 53.0
==============================================================================
While for the coefficients
results.iloc[0]["px_fit_results"].params
array([0.92026961, 0.10502452])
Where the fist one is the constant while the second is the slope.
这篇关于Plotly:如何在 plotly express 中找到趋势线的系数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Plotly:如何在 plotly express 中找到趋势线的系数?
基础教程推荐
猜你喜欢
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01