Marzie Gh
Marzie Gh

Reputation: 181

How to extract R-squared from plotly px.scatter trendline result?

how can I extract R-squared value from the following summary():

import plotly.express as px
df = ...
fig = px.scatter(df, x="...", y="...", trendline="ols") 
a = px.get_trendline_results(fig).px_fit_results.iloc[0].summary()

I know how to extract coefficients of trendline with params:coef in the picture

print(fit_results.params)

but I need to extract R-squared value from the results to annotate it in static saved figs.

Upvotes: 4

Views: 3594

Answers (1)

Marzie Gh
Marzie Gh

Reputation: 181

I found it :)

a = px.get_trendline_results(fig).px_fit_results.iloc[0].rsquared

that's it.

Upvotes: 14

Related Questions