逻辑回归中的错误情节

时间:2016-12-09 17:11:41

标签: python scikit-learn

我正在尝试实施逻辑回归,但收到错误的情节。

ax.plot(x_test,logistic_regr.predict(x_test), label='Logistic regr')

我收到以下情节:

enter image description here

如果我使用:

{{1}}

我收到了:

enter image description here

1 个答案:

答案 0 :(得分:1)

嗯,您将无法获得特定数据选择的sigmoid函数图。您的随机输入使算法找到类之间的某些分隔,这些分离将根据输入的随机性预测接近0.5的概率。你可以通过使用均匀分割的值范围获得sigmoid,其中一半属于第一类,后半部分属于第二类。这样,您的predict_proba()函数将输出一系列从0到1的特定类的概率(我假设其余代码将保持不变):

x = np.linspace(-2, 2, 400).reshape((400,1))
y = np.vstack((np.zeros(200), np.ones(200))).reshape((400,1))

然后生成图表:

ax.plot(x_test, logistic_regr.predict_proba(x_test)[:,1], '.', label='Logistic regr')    

您将得到一个S形状的图,描述预测其中一个类的概率: enter image description here