← 返回题库
中级

OLS回归:一线房价对汇率

未完成
中级参考 代码结构已给出,请填写 ____ 处
sm.add_constant(____)).fit()。

示例

输入
import pandas as pd
import statsmodels.api as sm

def solve():
    url = 'https://liangdaima.com/static/data/aec/hourse.xlsx'
    df = pd.read_excel(url)
    X = sm.add_constant(df['e'])
    y = df['f1']
    model = sm.OLS(y, X).fit()
    print(f'{model.params[0]:.4f},{model.params[1]:.4f},{model.rsquared:.4f}')
期望输出
solve()
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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