Python statsmodel.api逻辑回归(Logit) [英] Python statsmodel.api logistic regression (Logit)
问题描述
因此,我尝试使用python的statsmodels.api进行预测,以对二进制结果进行逻辑回归.我正在按照教程使用Logit.当我尝试对测试数据集进行预测时,每个记录的输出都是0到1之间的小数.它不应该给我零和一吗?或者我是否必须使用圆形函数或其他东西来转换这些.
So I'm trying to do a prediction using python's statsmodels.api to do logistic regression on a binary outcome. I'm using Logit as per the tutorials. When I try to do a prediction on a test dataset, the output is in decimals between 0 and 1 for each of the records. Shouldn't it be giving me zero and one? or do I have to convert these using a round function or something.
不好意思,这个问题.我盯着我的旅程.
Excuse the noobiness of this question. I am staring my journey.
推荐答案
预测值是给定解释变量的概率,更准确地说是观察到1的概率.
The predicted values are the probabilies given the explanatory variables, more precisely the probability of observing 1.
要获得0、1的预测,您需要选择一个阈值,例如0.5表示相等的阈值,然后将1分配给阈值以上的概率.
To get a 0, 1 prediction, you need to pick a threshold, like 0.5 for equal thresholding, and assign 1 to the probabilities above the threshold.
以numpy为例,
predicted = results.predict(x_for_prediction)
predicted_choice = (predicted > threshold).astype(int)
这篇关于Python statsmodel.api逻辑回归(Logit)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!