AI人工智能 基于感知器的分类器

You are here:
← All Topics

感知器是 ANN 的基石。 如果您想了解更多关于 Perceptron 的信息,可以点击链接 - artificial_neural_network

以下是逐步执行 Python 代码,用于构建基于感知器的简单神经网络分类器 -

如下所示导入必要的软件包 -


import matplotlib.pyplot as pltimport neurolab as nl

请注意,这是一个监督学习的例子,因此您也必须提供目标值。


input = [[0, 0], [0, 1], [1, 0], [1, 1]]target = [[0], [0], [0], [1]]

用 2 个输入和 1 个神经元创建网络 -


net = nl.net.newp([[0, 1],[0, 1]], 1)

现在,训练网络。 在这里使用 Delta 规则进行训练。


error_progress = net.train(input, target, epochs=100, show=10, lr=0.1)

接下来,可视化输出并绘制图表 -


plt.figure()plt.plot(error_progress)plt.xlabel('Number of epochs')plt.ylabel('Training error')plt.grid()plt.show()

可以看到下图显示了使用错误度量标准的训练进度 -

img