codecamp

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

感知器是人工神经网络的构建块。

以下是构建基于感知器的简单神经网络分类器的 Python 代码的分步执行过程:

导入必要的包,如下所示:

import matplotlib.pyplot as plt
import 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('迭代次数')
plt.ylabel('训练误差')
plt.grid()
plt.show()

您可以看到以下图表,显示了使用误差指标的训练进度:

AI人工智能 构建神经网络
AI人工智能 单层神经网络
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

AI人工智能监督学习(回归)

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }