← 返回题库
初级

Auto数据集多元线性回归

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
import pandas as pd
import statsmodels.formula.api as smf
auto = pd.read_csv('https://liangdaima.com/static/data/statistics/Auto.csv')
auto['horsepower'] = pd.to_numeric(auto['horsepower'], errors='coerce')
auto = auto.dropna()
model = smf.ols('mpg ~ horsepower + weight + acceleration', data=auto).fit()
print('R-squared:', model.rsquared)
print('回归系数:')
print(model.params)

示例

输入
solve()
期望输出
R-squared: 0.7063754859981903
回归系数:
Intercept       45.678293
horsepower      -0.047496
weight          -0.005789
acceleration    -0.002066
dtype: float64
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码