2024-06-06 04:09:28 发布
网友
如何在plotly express中找到趋势线的系数
例如,我使用下面的代码绘制趋势线,但现在我想知道系数
import plotly.express as px px.scatter(df, x='x_data', y='y_data', trendline="ols")
在这里,您需要查看plotly和statsmodels中的plotlydoc。我认为plotly示例中的示例应该是固定的。反正
plotly
import plotly.express as px df = px.data.tips() fig = px.scatter(df, x="total_bill", y="tip", trendline="ols") fig.show()
对于结果,您应该运行
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 ==============================================================================
而对于系数
results.iloc[0]["px_fit_results"].params
array([0.92026961, 0.10502452])
其中第一个是常数,第二个是斜率
在这里,您需要查看
plotly
和statsmodels中的plotlydoc。我认为plotly示例中的示例应该是固定的。反正对于结果,您应该运行
而对于系数
其中第一个是常数,第二个是斜率
相关问题 更多 >
编程相关推荐