scikit-learn 中实现的 LogisticRegression 似乎无法学习简单的布尔函数 AND 或 OR。我会理解 XOR 给出不好的结果,但 AND 和 OR 应该没问题。难道我做错了什么?
from sklearn.linear_model import LogisticRegression, LinearRegression
import numpy as np
bool_and = np.array([0., 0., 0., 1.])
bool_or = np.array([0., 1., 1., 1.])
bool_xor = np.array([0., 1., 1., 0.])
x = np.array([[0., 0.],
[0., 1.],
[1., 0.],
[1., 1.]])
y = bool_and
logit = LogisticRegression()
logit.fit(x,y)
#linear = LinearRegression()
#linear.fit(x, y)
print "expected: ", y
print "predicted:", logit.predict(x)
#print linear.predict(x)
给出以下输出:
expected: [0 0 0 1]
predicted: [0 0 0 0]