【发布时间】:2017-07-30 23:46:08
【问题描述】:
我有以下代码:
x1 = np.random.randn(100)
y1 = np.random.randn(100) + 3
x2 = np.random.randn(100) + 3
y2 = np.random.randn(100)
plt.plot(x1, y1, "+", x2, y2, "x")
plt.axis('equal')
plt.show()
结果如下图
我已经实现了自己的逻辑回归,这会返回一个 theta,我想使用这个 theta 来绘制决策边界,但我不知道该怎么做。
X = np.matrix(np.vstack((np.hstack((x1,x2)), np.hstack((y1,y2)))).T)
X = np.concatenate((np.ones((X.shape[0], 1)), X), axis=1)
Y = np.matrix(1.0 * np.hstack((np.zeros(100), np.ones(100)))).T
learning_rate = 0.0001
iterations = 3000
theta = np.matrix([[0.5], [0.5], [0.5]])
theta = logistic_regression(theta, X, Y, learning_rate, iterations)
这给了theta =
[[ 0.40377942]
[ 0.53696461]
[ 0.1398419 ]]
例如。如何使用它来绘制决策边界?
【问题讨论】:
-
解释你的
logistic_regression函数返回值的含义。 -
@WarrenWeckesser this video 中看到的 theta 值
标签: python numpy logistic-regression