从头开始创建神经网络 class(没有训练功能)但预测总是接近 1

Created a neural network class from scratch ( without training function ) but predictions are always near 1

我是 AI 和神经网络的新手。 我在 python 中阅读了一些关于如何从头开始构建神经网络的文章,所以我决定构建自己的神经网络。

我的代码由一个 NN class 组成,没有分层动态的训练函数。 但每次我用随机数测试它时,预测总是大于 0.7。

我做错了什么?

一点信息:layers_counts 是每层神经元计数的整数列表, 喜欢

(第 1 层:5 个神经元,第 2 层:3 个神经元。-> [5, 3])

import numpy as np


class NeuralNetwork:
    def __init__(self, inputs_count, layers_counts, bias=0):
        self.weights = []
        self.layer_schema = layers_counts
        self.bias = bias
        for lidx, litem in enumerate(layers_counts):
            if lidx == 0:
                self.weights.append(np.random.rand(inputs_count, layers_counts[0]).tolist())
                if len(layers_counts) == 1:
                    break
                else:
                    continue
            self.weights.append(np.random.rand(layers_counts[lidx-1], litem).tolist())

    def train(self, inputs, epochs=100, acc_threshold=0.9):
        todolist = 1

    def predict(self, inputs):
        last_result = 0.0
        last_inputs = inputs
        for layer_c in range(0, len(self.layer_schema)):
            last_inputs = np.dot(last_inputs, self.weights[layer_c])
            last_result = last_inputs + self.bias
        return 1 / (1 + np.exp(-last_result))


net = NeuralNetwork(4, [2, 1, 4], bias=5.3)
print(net.predict([-0.5, 0.3, 0.9, 1]))

示例结果:

[0.99845756 0.99601029 0.99808744 0.99788011]

[0.99716477 0.99547246 0.99525549 0.99702588]

好像是因为你给每一层加了5.3的偏差!这将导致输出趋向于 1.