Python:statsmodels-.predict(X)实际预测了什么?

问题描述 投票:-1回答:1

我对model.predict(X)行的实际预测有些困惑。我用Google搜索找不到任何东西。

import statsmodels.api as sm

# Step 1) Load data into dataframe 
df = pd.read_csv('my_data.csv')

# Step 2) Separate dependent and independent variables 

X = df['independent_variable']
y = df["dependent_variable"]

# Step 3) using OLS -fit a linear regression
model = sm.OLS(y, X).fit()
predictions = model.predict(X) # make predictions
predictions

我不确定predictions显示什么?它是在预测下一个x行的数量吗?我不只是传入我的自变量吗?

python statsmodels
1个回答
0
投票

您正在从数据中拟合OLS模型,这很可能会解释为数组。 predict方法将返回给定训练模型的拟合值数组。

换句话说,来自statsmodels documentation

从设计矩阵返回线性预测值。

© www.soinside.com 2019 - 2024. All rights reserved.