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

2020-09-24 11:00 更新

感知器是 ANN 的基石。 如果您想了解更多關(guān)于 Perceptron 的信息,可以點(diǎn)擊鏈接 - artificial_neural_network

以下是逐步執(zhí)行 Python 代碼,用于構(gòu)建基于感知器的簡單神經(jīng)網(wǎng)絡(luò)分類器 -

如下所示導(dǎo)入必要的軟件包 -

import matplotlib.pyplot as plt
import neurolab as nl

請注意,這是一個監(jiān)督學(xué)習(xí)的例子,因此您也必須提供目標(biāo)值。

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

2 個輸入和 1 個神經(jīng)元創(chuàng)建網(wǎng)絡(luò) -

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

現(xiàn)在,訓(xùn)練網(wǎng)絡(luò)。 在這里使用 Delta 規(guī)則進(jìn)行訓(xùn)練。

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()

可以看到下圖顯示了使用錯誤度量標(biāo)準(zhǔn)的訓(xùn)練進(jìn)度 -

img

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號