import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import statsmodels.formula.api as smf
sns.set_theme()# 设置风格
%config InlineBackend.figure_format = 'retina' # 让图片更清晰
df = pd.read_excel('/content/data.xlsx')# 导入数据
print(df)
sns.regplot(x='x', y='y',data=df)
plt.savefig("回归.png", dpi = 600, bbox_inches = 'tight')
plt.show()

results = smf.ols(formula='y ~ x',data=df).fit()
print(results.summary())
OLS Regression Results
Dep. Variable: |
y |
R-squared: |
0.771 |
Model: |
OLS |
Adj. R-squared: |
0.758 |