Python - 逻辑(Logit)回归 - 为什么我会收到 Endog 错误?

数据挖掘 Python 逻辑回归 错误处理
2022-02-21 15:39:33

我正在运行以下代码:

X = dataset[['X1 transaction date', 'X2 house age', 'X3 distance to the nearest MRT station', 'X4 number of convenience stores', 'X5 latitude', 'X6 longitude', 'X7 distance to Xindian Ditsrict Office', 'X8 distance to Cardinal Tien Hospital', 'X9 distance to Shih Hsin University']]

y = dataset['Y house price of unit area']

model = sm.Logit(y, X).fit()
print(model.summary())

我正在使用 CSV 数据框,其中包含有关台湾新店区 414 处不同住宅物业的信息。我的目标是使用逻辑回归来确定哪些属性对房产价格的影响最大。

运行我的逻辑回归时,我得到一个 Endog 错误,如下所示:

ValueError Traceback (last last call last) in () 2 y = dataset['Y 单位面积房价'] 3 ----> 4 model = sm.Logit(y, X).fit() 5 print(model 。概括())

//anaconda/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py init (self, endog, exog, **kwargs) 402 if ( self.class.name ! = 'MNLogit' and 403 not np.all((self.endog>= 0) & (self.endog <= 1))): --> 404 raise ValueError("endog must be in the unit interval.") 405 406

ValueError: endog 必须在单位区间内。

有谁知道我为什么会收到 endog 错误,以及如何纠正这个问题?我的结果变量是一个连续整数。

谢谢你。

1个回答

错误来自试图在回归问题上拟合分类器(逻辑回归)。如果您尝试预测价格(连续结果),则应使用线性回归