【发布时间】:2018-11-08 11:11:59
【问题描述】:
我目前为如下所示的决策边界训练了一个逻辑模型:
使用我上网的以下代码:
x_min, x_max = xbatch[:, 0].min() - .5, xbatch[:, 0].max() + .5
y_min, y_max = xbatch[:, 1].min() - .5, xbatch[:, 1].max() + .5
h = 0.05
# Generate a grid of points with distance h between them
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
X = np.vstack( ( xx.reshape(1, np.product(xx.shape)), yy.reshape(1, np.product(yy.shape)) ) ).T
# Predict the function value for the whole grid
z1 = np.dot(X, w1_pred)+b1_pred
h1 = 1 / (1 + np.exp(-z1))
z2 = np.dot(h1, w2_pred)+b2_pred
y_hat = 1 / (1 + np.exp(-z2))
pred = np.round(y_hat)
Z = pred.reshape(xx.shape)
# Plot the contour and training examples
plt.contourf(xx, yy, Z)
plt.scatter(xbatch[:, 0], xbatch[:, 1], c=ybatch, s=40, edgecolors="grey", alpha=0.9)
我的问题是这样的:
有没有办法在没有网格或轮廓的情况下绘制决策线?
【问题讨论】:
-
您能提供一个minimal example 吗?如果您提供一些可以使用的工作代码,则可以更轻松地为您提供帮助
-
"wave sigmoid 函数"从何而来?你想适应那个功能吗?
-
顺便说一句,这只是一个绘图样式问题,还是您希望决策边界有某种参数形式,并想要一种方法来找到这些参数,以便您以后可以绘制它?对于前者,您也许可以将
contour用于单个级别?
标签: python numpy matplotlib tensorflow logistic-regression