欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python編程實(shí)現(xiàn)的簡(jiǎn)單神經(jīng)網(wǎng)絡(luò)算法示例

 更新時(shí)間:2018年01月26日 11:04:31   作者:Nani_xiao  
這篇文章主要介紹了Python編程實(shí)現(xiàn)的簡(jiǎn)單神經(jīng)網(wǎng)絡(luò)算法,結(jié)合實(shí)例形式分析了神經(jīng)網(wǎng)絡(luò)算法的原理及Python相關(guān)算法實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Python編程實(shí)現(xiàn)的簡(jiǎn)單神經(jīng)網(wǎng)絡(luò)算法。分享給大家供大家參考,具體如下:

python實(shí)現(xiàn)二層神經(jīng)網(wǎng)絡(luò)

包括輸入層和輸出層

# -*- coding:utf-8 -*-
#! python2
import numpy as np
#sigmoid function
def nonlin(x, deriv = False):
 if(deriv == True):
  return x*(1-x)
 return 1/(1+np.exp(-x))
#input dataset
x = np.array([[0,0,1],
    [0,1,1],
    [1,0,1],
    [1,1,1]])
#output dataset
y = np.array([[0,0,1,1]]).T
np.random.seed(1)
#init weight value
syn0 = 2*np.random.random((3,1))-1
print "腳本之家測(cè)試結(jié)果:"
for iter in xrange(100000):
 l0 = x       #the first layer,and the input layer
 l1 = nonlin(np.dot(l0,syn0)) #the second layer,and the output layer
 l1_error = y-l1
 l1_delta = l1_error*nonlin(l1,True)
 syn0 += np.dot(l0.T, l1_delta)
print "outout after Training:"
print l1

這里,

l0:輸入層
l1:輸出層
syn0:初始權(quán)值
l1_error:誤差
l1_delta:誤差校正系數(shù)
func nonlin:sigmoid函數(shù)

這里迭代次數(shù)為100時(shí),預(yù)測(cè)結(jié)果為

迭代次數(shù)為1000時(shí),預(yù)測(cè)結(jié)果為:

迭代次數(shù)為10000,預(yù)測(cè)結(jié)果為:

迭代次數(shù)為100000,預(yù)測(cè)結(jié)果為:

可見迭代次數(shù)越多,預(yù)測(cè)結(jié)果越接近理想值,當(dāng)時(shí)耗時(shí)也越長(zhǎng)。

python實(shí)現(xiàn)三層神經(jīng)網(wǎng)絡(luò)

包括輸入層、隱含層和輸出層

# -*- coding:utf-8 -*-
#! python2
import numpy as np
def nonlin(x, deriv = False):
 if(deriv == True):
  return x*(1-x)
 else:
  return 1/(1+np.exp(-x))
#input dataset
X = np.array([[0,0,1],
    [0,1,1],
    [1,0,1],
    [1,1,1]])
#output dataset
y = np.array([[0,1,1,0]]).T
syn0 = 2*np.random.random((3,4)) - 1 #the first-hidden layer weight value
syn1 = 2*np.random.random((4,1)) - 1 #the hidden-output layer weight value
print "腳本之家測(cè)試結(jié)果:"
for j in range(60000):
 l0 = X      #the first layer,and the input layer
 l1 = nonlin(np.dot(l0,syn0)) #the second layer,and the hidden layer
 l2 = nonlin(np.dot(l1,syn1)) #the third layer,and the output layer
 l2_error = y-l2  #the hidden-output layer error
 if(j%10000) == 0:
  print "Error:"+str(np.mean(l2_error))
 l2_delta = l2_error*nonlin(l2,deriv = True)
 l1_error = l2_delta.dot(syn1.T)  #the first-hidden layer error
 l1_delta = l1_error*nonlin(l1,deriv = True)
 syn1 += l1.T.dot(l2_delta)
 syn0 += l0.T.dot(l1_delta)
print "outout after Training:"
print l2

運(yùn)行結(jié)果:

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python編碼操作技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • 幾種實(shí)用的pythonic語法實(shí)例代碼

    幾種實(shí)用的pythonic語法實(shí)例代碼

    在我理解,Pythonic 就是很 Python 的 Python 代碼。下面這篇文章主要給大家分享介紹了幾種實(shí)用的pythonic語法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-02-02
  • Python深度學(xué)習(xí)pytorch卷積神經(jīng)網(wǎng)絡(luò)LeNet

    Python深度學(xué)習(xí)pytorch卷積神經(jīng)網(wǎng)絡(luò)LeNet

    這篇文章主要為大家講解了Python深度學(xué)習(xí)中的pytorch卷積神經(jīng)網(wǎng)絡(luò)LeNet的示例解析,有需要的朋友可以借鑒參考下希望能夠有所幫助
    2021-10-10
  • python高級(jí)語法之閉包和裝飾器詳解

    python高級(jí)語法之閉包和裝飾器詳解

    這篇文章主要介紹了python高級(jí)語法之閉包和裝飾器詳解,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有很好地幫助,需要的朋友可以參考下
    2021-05-05
  • python使用梯度下降和牛頓法尋找Rosenbrock函數(shù)最小值實(shí)例

    python使用梯度下降和牛頓法尋找Rosenbrock函數(shù)最小值實(shí)例

    這篇文章主要介紹了python使用梯度下降和牛頓法尋找Rosenbrock函數(shù)最小值實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • 通過Folium在地圖上展示數(shù)據(jù)Python地理可視化的入門示例詳解

    通過Folium在地圖上展示數(shù)據(jù)Python地理可視化的入門示例詳解

    這篇文章主要介紹了通過Folium在地圖上展示數(shù)據(jù)Python地理可視化的入門,在本文中,我們介紹了如何使用Python中的Folium庫進(jìn)行地理可視化,通過Folium,我們可以輕松地創(chuàng)建交互式地圖,并在地圖上展示數(shù)據(jù)、繪制形狀、添加圖例和文本標(biāo)簽等,需要的朋友可以參考下
    2024-05-05
  • 詳解python opencv圖像混合算術(shù)運(yùn)算

    詳解python opencv圖像混合算術(shù)運(yùn)算

    這篇文章主要介紹了python opencv圖像混合算術(shù)運(yùn)算的相關(guān)知識(shí),本文通過實(shí)例圖文相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2021-09-09
  • Python import自己的模塊報(bào)錯(cuò)問題及解決

    Python import自己的模塊報(bào)錯(cuò)問題及解決

    這篇文章主要介紹了Python import自己的模塊報(bào)錯(cuò)問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • 教你怎么用python爬取愛奇藝熱門電影

    教你怎么用python爬取愛奇藝熱門電影

    突然心血來潮想看看電影,特地整理了這篇文章,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python爬蟲的小伙伴們有很好的幫助,需要的朋友可以參考下
    2021-05-05
  • 淺析Python打包時(shí)包含靜態(tài)文件處理方法

    淺析Python打包時(shí)包含靜態(tài)文件處理方法

    這篇文章主要介紹了Python打包時(shí)包含靜態(tài)文件處理方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-01-01
  • Django 實(shí)現(xiàn)jwt認(rèn)證的示例

    Django 實(shí)現(xiàn)jwt認(rèn)證的示例

    這篇文章主要介紹了Django 實(shí)現(xiàn)jwt 認(rèn)證的示例,幫助大家更好的理解和學(xué)習(xí)使用django,感興趣的朋友可以了解下
    2021-04-04

最新評(píng)論