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

使用Keras畫神經(jīng)網(wǎng)絡(luò)準(zhǔn)確性圖教程

 更新時(shí)間:2020年06月15日 15:08:39   作者:ZJE_ANDY  
這篇文章主要介紹了使用Keras畫神經(jīng)網(wǎng)絡(luò)準(zhǔn)確性圖教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

1.在搭建網(wǎng)絡(luò)開始時(shí),會(huì)調(diào)用到 keras.models的Sequential()方法,返回一個(gè)model參數(shù)表示模型

2.model參數(shù)里面有個(gè)fit()方法,用于把訓(xùn)練集傳進(jìn)網(wǎng)絡(luò)。fit()返回一個(gè)參數(shù),該參數(shù)包含訓(xùn)練集和驗(yàn)證集的準(zhǔn)確性acc和錯(cuò)誤值loss,用這些數(shù)據(jù)畫成圖表即可。

如:

history=model.fit(x_train, y_train, batch_size=32, epochs=5, validation_split=0.25) #獲取數(shù)據(jù)
 
#########畫圖
acc = history.history['acc']  #獲取訓(xùn)練集準(zhǔn)確性數(shù)據(jù)
val_acc = history.history['val_acc'] #獲取驗(yàn)證集準(zhǔn)確性數(shù)據(jù)
loss = history.history['loss']   #獲取訓(xùn)練集錯(cuò)誤值數(shù)據(jù)
val_loss = history.history['val_loss'] #獲取驗(yàn)證集錯(cuò)誤值數(shù)據(jù)
epochs = range(1,len(acc)+1)
plt.plot(epochs,acc,'bo',label='Trainning acc')  #以epochs為橫坐標(biāo),以訓(xùn)練集準(zhǔn)確性為縱坐標(biāo)
plt.plot(epochs,val_acc,'b',label='Vaildation acc') #以epochs為橫坐標(biāo),以驗(yàn)證集準(zhǔn)確性為縱坐標(biāo)
plt.legend() #繪制圖例,即標(biāo)明圖中的線段代表何種含義
 
plt.figure() #創(chuàng)建一個(gè)新的圖表
plt.plot(epochs,loss,'bo',label='Trainning loss')
plt.plot(epochs,val_loss,'b',label='Vaildation loss')
plt.legend() ##繪制圖例,即標(biāo)明圖中的線段代表何種含義
 
plt.show() #顯示所有圖表

得到效果:

完整代碼:

import keras
from keras.datasets import mnist
from keras.layers import Conv2D, MaxPool2D, Dense, Flatten,Dropout
from keras.models import Sequential
import matplotlib.pyplot as plt
 
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape(-1, 28, 28, 1)
x_test = x_test.reshape(-1, 28, 28, 1)
x_train = x_train / 255.
x_test = x_test / 255.
 
y_train = keras.utils.to_categorical(y_train)
y_test = keras.utils.to_categorical(y_test)
 
model = Sequential()
model.add(Conv2D(20,(5,5),strides=(1,1),input_shape=(28,28,1),padding='valid',activation='relu',kernel_initializer='uniform'))
model.add(MaxPool2D(pool_size=(2,2),strides=(2,2)))
model.add(Conv2D(64,(5,5),strides=(1,1),padding='valid',activation='relu',kernel_initializer='uniform'))
model.add(MaxPool2D(pool_size=(2,2),strides=(2,2)))
model.add(Flatten())
model.add(Dense(500,activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(10,activation='softmax'))
model.compile('sgd', loss='categorical_crossentropy', metrics=['accuracy']) #隨機(jī)梯度下降
 
history=model.fit(x_train, y_train, batch_size=32, epochs=5, validation_split=0.25) #獲取數(shù)據(jù)
 
#########畫圖
acc = history.history['acc']  #獲取訓(xùn)練集準(zhǔn)確性數(shù)據(jù)
val_acc = history.history['val_acc'] #獲取驗(yàn)證集準(zhǔn)確性數(shù)據(jù)
loss = history.history['loss']   #獲取訓(xùn)練集錯(cuò)誤值數(shù)據(jù)
val_loss = history.history['val_loss'] #獲取驗(yàn)證集錯(cuò)誤值數(shù)據(jù)
epochs = range(1,len(acc)+1)
plt.plot(epochs,acc,'bo',label='Trainning acc')  #以epochs為橫坐標(biāo),以訓(xùn)練集準(zhǔn)確性為縱坐標(biāo)
plt.plot(epochs,val_acc,'b',label='Vaildation acc') #以epochs為橫坐標(biāo),以驗(yàn)證集準(zhǔn)確性為縱坐標(biāo)
plt.legend() #繪制圖例,即標(biāo)明圖中的線段代表何種含義
 
plt.figure() #創(chuàng)建一個(gè)新的圖表
plt.plot(epochs,loss,'bo',label='Trainning loss')
plt.plot(epochs,val_loss,'b',label='Vaildation loss')
plt.legend() ##繪制圖例,即標(biāo)明圖中的線段代表何種含義

以上這篇使用Keras畫神經(jīng)網(wǎng)絡(luò)準(zhǔn)確性圖教程就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python使用flask框架操作sqlite3的兩種方式

    Python使用flask框架操作sqlite3的兩種方式

    這篇文章主要介紹了Python使用flask框架操作sqlite3的兩種方式,結(jié)合實(shí)例形式分析了Python基于flask框架操作sqlite3數(shù)據(jù)庫的兩種常用操作技巧,需要的朋友可以參考下
    2018-01-01
  • 在Django的模型中執(zhí)行原始SQL查詢的方法

    在Django的模型中執(zhí)行原始SQL查詢的方法

    這篇文章主要介紹了在Django的模型中執(zhí)行原始SQL查詢的方法,Django是最具人氣的Python web開發(fā)框架,需要的朋友可以參考下
    2015-07-07
  • 利用Python實(shí)現(xiàn)給圖像添加標(biāo)簽

    利用Python實(shí)現(xiàn)給圖像添加標(biāo)簽

    這篇文章主要為大家詳細(xì)介紹了如何利用Python實(shí)現(xiàn)給指定的圖片添加標(biāo)簽,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,需要的可以參考一下
    2023-07-07
  • Python中使用dwebsocket實(shí)現(xiàn)后端數(shù)據(jù)實(shí)時(shí)刷新

    Python中使用dwebsocket實(shí)現(xiàn)后端數(shù)據(jù)實(shí)時(shí)刷新

    dwebsocket是Python中一款用于實(shí)現(xiàn)WebSocket協(xié)議的庫,可用于后端數(shù)據(jù)實(shí)時(shí)刷新。在Django中結(jié)合使用dwebsocket和Channels,可以實(shí)現(xiàn)前后端的實(shí)時(shí)通信,支持雙向數(shù)據(jù)傳輸和消息推送,適用于實(shí)時(shí)聊天、數(shù)據(jù)監(jiān)控、在線游戲等場(chǎng)景
    2023-04-04
  • Python爬蟲 批量爬取下載抖音視頻代碼實(shí)例

    Python爬蟲 批量爬取下載抖音視頻代碼實(shí)例

    這篇文章主要介紹了Python爬蟲 批量爬取下載抖音視頻代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08
  • 利用Pytorch實(shí)現(xiàn)ResNet網(wǎng)絡(luò)構(gòu)建及模型訓(xùn)練

    利用Pytorch實(shí)現(xiàn)ResNet網(wǎng)絡(luò)構(gòu)建及模型訓(xùn)練

    這篇文章主要為大家介紹了利用Pytorch實(shí)現(xiàn)ResNet網(wǎng)絡(luò)構(gòu)建及模型訓(xùn)練詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • django 模版關(guān)閉轉(zhuǎn)義方式

    django 模版關(guān)閉轉(zhuǎn)義方式

    這篇文章主要介紹了django 模版關(guān)閉轉(zhuǎn)義方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05
  • Python關(guān)于抽獎(jiǎng)系統(tǒng)的思考與設(shè)計(jì)思路

    Python關(guān)于抽獎(jiǎng)系統(tǒng)的思考與設(shè)計(jì)思路

    這篇文章主要介紹了Python關(guān)于抽獎(jiǎng)系統(tǒng)的思考與設(shè)計(jì)思路,本文通過一些簡(jiǎn)單的例子來說一說抽獎(jiǎng)系統(tǒng)背后的邏輯,看看究竟是你運(yùn)氣不好還是系統(tǒng)邏輯在作怪,需要的朋友可以參考下
    2023-03-03
  • 關(guān)于Python形參打包與解包小技巧分享

    關(guān)于Python形參打包與解包小技巧分享

    今天小編就為大家分享一篇關(guān)于Python形參打包與解包小技巧分享,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • Python的Lambda函數(shù)用法詳解

    Python的Lambda函數(shù)用法詳解

    在Python中有兩種函數(shù),一種是def定義的函數(shù),另一種是lambda函數(shù),也就是大家常說的匿名函數(shù)。這篇文章主要介紹了Python的Lambda函數(shù)用法,需要的朋友可以參考下
    2019-09-09

最新評(píng)論