Python 如何从数学上找到感知器:权重1、权重2和偏差

Python 如何从数学上找到感知器:权重1、权重2和偏差,python,pandas,perceptron,bias-neuron,Python,Pandas,Perceptron,Bias Neuron,如何找到权重1、权重2和偏差的值?对于任何问题,找到这三个值的广义数学方法是什么 import pandas as pd weight1 = 0.0 weight2 = 0.0 bias = 0.0 test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)] correct_outputs = [False, False, False, True] outputs = [] for test_input, correct_output in zip(te

如何找到权重1、权重2和偏差的值?对于任何问题,找到这三个值的广义数学方法是什么

import pandas as pd


weight1 = 0.0
weight2 = 0.0
bias = 0.0

test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)]
correct_outputs = [False, False, False, True]
outputs = []

for test_input, correct_output in zip(test_inputs, correct_outputs):
    linear_combination = weight1 * test_input[0] + weight2 * test_input[1] + bias
    output = int(linear_combination >= 0)
    is_correct_string = 'Yes' if output == correct_output else 'No'
    outputs.append([test_input[0], test_input[1], linear_combination, output, is_correct_string])


num_wrong = len([output[4] for output in outputs if output[4] == 'No'])
output_frame = pd.DataFrame(outputs, columns=['Input 1', '  Input 2', '  Linear Combination', '  Activation Output', '  Is Correct'])
if not num_wrong:
    print('Nice!  You got it all correct.\n')
else:
    print('You got {} wrong.  Keep trying!\n'.format(num_wrong))
print(output_frame.to_string(index=False))

在正态方程的情况下,你不需要偏置单位。因此,这可能就是您所追求的(请记住,我已将您的
True
False
值分别重新设置为
1
0
):

收益率:

[[ 0.33333333]
 [ 0.33333333]]

关于这个解的更多细节已经给出了。

在正态方程的情况下,你不需要偏置单位。因此,这可能就是您所追求的(请记住,我已将您的
True
False
值分别重新设置为
1
0
):

收益率:

[[ 0.33333333]
 [ 0.33333333]]

有关解决方案的更多详细信息,请参见。

以下内容对我有用:

weight1 = 1.5
weight2 = 1.5
bias = -2

当我更好地理解为什么以下内容对我有效时,将更新:

weight1 = 1.5
weight2 = 1.5
bias = -2

当我更好地理解为什么问题要求您在输入为[(0,0),(0,1),(1,0),(1,1)]时评估权重1、权重2和偏差,以产生[假、假、假、真]时,将更新。 在此上下文中,“False”将是一个负数的结果。相反,“True”将是一个正数。 因此,您需要评估以下内容:

x1*weight1+x2*weight2+bias'为正或负

例如,设置weight1=1、weight2=1和bias=-1.1(可能的解决方案) 对于第一个输入,您将获得:

0*1+0*1+(-1.1)=-1.1为负值,表示其计算结果为False

对于下一个输入:

0*1+1*1+(-1.1)=-0.1为负值,表示其计算结果为False

对于下一个输入:

1*1+0*1+(-1.1)=-0.1为负值,表示其计算结果为False

对于最后的输入:

1*1+1*1+(-1.1)=+0.9,为正,表示其计算结果为True


问题要求您在输入为[(0,0),(0,1),(1,0),(1,1)]时评估权重1、权重2和偏差,以产生[假、假、假、真]。 在此上下文中,“False”将是一个负数的结果。相反,“True”将是一个正数。 因此,您需要评估以下内容:

x1*weight1+x2*weight2+bias'为正或负

例如,设置weight1=1、weight2=1和bias=-1.1(可能的解决方案) 对于第一个输入,您将获得:

0*1+0*1+(-1.1)=-1.1为负值,表示其计算结果为False

对于下一个输入:

0*1+1*1+(-1.1)=-0.1为负值,表示其计算结果为False

对于下一个输入:

1*1+0*1+(-1.1)=-0.1为负值,表示其计算结果为False

对于最后的输入:

1*1+1*1+(-1.1)=+0.9,为正,表示其计算结果为True


以下几点对我也很有用:

weight1 = 1.5
weight2 = 1.5
bias = -2

以下几点对我也很有用:

weight1 = 1.5
weight2 = 1.5
bias = -2
X1w1+X2W2+偏压 测试是:

linear_combination >= 0
根据给定的输入值:

test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)]
AND值在测试中仅计算一次为真,因此典型AND操作的输出应如下所示:

1   1   True 
1   0   False
0   1   False
0   0   False
给定,当我们在方程中输入测试输入:X1w1+X2W2+偏差时,应该只有一个真实结果。如上所述,我们的测试是方程的线性组合应大于或等于零。我相信问题是这个输出是否为真只有一个,从测试运行中可以看出。 因此,要获得假值,输出应该是负数计算。 最简单的方法是用较小的值和负偏差测试方程。 我试过了

weight1 = 1
weight2 = 1
bias = -2
X1w1+X2W2+偏压 测试是:

linear_combination >= 0
根据给定的输入值:

test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)]
AND值在测试中仅计算一次为真,因此典型AND操作的输出应如下所示:

1   1   True 
1   0   False
0   1   False
0   0   False
给定,当我们在方程中输入测试输入:X1w1+X2W2+偏差时,应该只有一个真实结果。如上所述,我们的测试是方程的线性组合应大于或等于零。我相信问题是这个输出是否为真只有一个,从测试运行中可以看出。 因此,要获得假值,输出应该是负数计算。 最简单的方法是用较小的值和负偏差测试方程。 我试过了

weight1 = 1
weight2 = 1
bias = -2