我在提高用python编码的前馈神经网络的准确性方面有问题。我不确定这是一个真正的错误,还是我的数学函数不能胜任,但是我得到了不明确的输出(比如0.5),不管我增加了多少iterations....my代码:-
from numpy import exp, array, random, dot
class NeuralNetwork():
def __init__(self):
random.seed(1)
self.synaptic_weights = 2 * random.random((3, 1)) - 1 # MM reuslt = 3 (3 * 1)
def Sigmoid(self, x):
return 1 / (1 + exp(-x))
def Sigmoid_Derivative(self, x):
return x * (1 - x)
def train(self, Training_inputs, Training_outputs, iterations):
output = self.think(Training_inputs)
print ("THe outputs are: -", output)
erorr = Training_outputs - output
adjustment = dot(Training_inputs.T, erorr * self.Sigmoid_Derivative(output))
print ("The adjustments are:-", adjustment)
self.synaptic_weights += output
def think(self, inputs):
Training_inputs = array(inputs)
return self.Sigmoid(dot(inputs, self.synaptic_weights))
# phew! the class ends..
if __name__ == "__main__":
neural_network = NeuralNetwork()
print("Random startin weights", neural_network.synaptic_weights)
Training_inputs = array([[1, 1, 1],
[0, 0, 0],
[1, 0, 1],]) # 3 rows * 3 columns???
Training_outputs = array([[1, 1, 0]]).T
neural_network.train(Training_inputs, Training_outputs, 0)
print ("New synaptic weights after training: ")
print (neural_network.synaptic_weights)
# Test the neural network with a new situation.
print ("Considering new situation [1, 0, 0] -> ?: ")
print (neural_network.think(array([1, 0, 0])))
而这些是我的outputs:=>
[Running] python -u "/home/neel/Documents/VS-Code_Projects/Machine_Lrn(PY)/test.py"
Random startin weights [[-0.16595599]
[ 0.44064899]
[-0.99977125]]
THe outputs are: - [[0.3262757 ]
[0.5 ]
[0.23762817]]
The adjustments are:- [[0.10504902]
[0.14809799]
[0.10504902]]
New synaptic weights after training:
[[ 0.16031971]
[ 0.94064899]
[-0.76214308]]
Considering new situation [1, 0, 0] -> ?:
[0.5399943]
[Done] exited with code=0 in 0.348 seconds
[Running] python -u "/home/neel/Documents/VS-Code_Projects/Machine_Lrn(PY)/tempCodeRunnerFile.py"
Random startin weights [[-0.16595599]
[ 0.44064899]
[-0.99977125]]
THe outputs are: - [[0.3262757 ]
[0.5 ]
[0.23762817]]
The adjustments are:- [[0.10504902]
[0.14809799]
[0.10504902]]
New synaptic weights after training:
[[ 0.16031971]
[ 0.94064899]
[-0.76214308]]
Considering new situation [1, 0, 0] -> ?:
[0.5399943]
[Done] exited with code=0 in 3.985 seconds
我尝试过更改迭代,但差别很小。我想问题可能在我的数学(Sigmoid)函数中。除此之外,我认为第20行的点乘可能是个问题,因为调整对我来说很狡猾.
另外,0.5不表示我的网络不是在学习,因为它只是一个随机猜测?
P.S:-,我认为我的问题不是重复的问题,因为它涉及到所述模型的“准确性”,而将问题与“不想要的输出”联系起来
https://stackoverflow.com/questions/58102038
复制相似问题