gpt4 book ai didi

python - Scikit LogisticRegression 无法学习 or,and bool 函数

转载 作者:太空宇宙 更新时间:2023-11-03 15:20:46 24 4
gpt4 key购买 nike

似乎在 scikit-learn 中实现的 LogisticRegression 无法学习简单的 bool 函数 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]

最佳答案

问题似乎与正则化有关。以下使分类器工作:

logit = LogisticRegression(C=100)

不幸的是,文档有点稀疏,所以我不确定 C 参数的范围是多少。

关于python - Scikit LogisticRegression 无法学习 or,and bool 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15438817/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com