HUX布斯
model.predict是一种预测值的方法,因此您可以为其提供一个看不见的数据集:import statsmodels.formula.api as smfimport pandas as pdimport numpy as npdf = pd.DataFrame(np.random.randn(100,2),columns=['X','Y'])model = smf.ols('Y ~ X',data=df).fit()model.predict(exog=pd.DataFrame({'X':[1,2,3]}))如果您不提供 exog 参数,它会通过调用存储在对象下的数据返回预测,您可以在源代码下看到:def predict(self, params, exog=None): """ Return linear predicted values from a design matrix. Parameters ---------- params : array_like Parameters of a linear model. exog : array_like, optional Design / exogenous data. Model exog is used if None. Returns ------- array_like An array of fitted values. Notes ----- If the model has not yet been fit, params is not optional. """ # JP: this does not look correct for GLMAR # SS: it needs its own predict method if exog is None: exog = self.exog return np.dot(exog, params)另一方面,model.fittedvalues是一个属性,它是存储的拟合值。由于上面解释的原因,它将与 model.predict() 完全相同。您也可以查看此类型的方法。