1. 程式人生 > >Neural Networks and Deep Learning_week3練習

Neural Networks and Deep Learning_week3練習

學習心得: 1、每週的視訊課程看一到兩遍 2、做筆記

3、做每週的作業練習,這個裡面的含金量非常高。掌握後一定要自己敲一遍,這樣以後用起來才能得心應手。

有需要全套作業練習notebook及全套資料的可以留言或者加我微信yuhaidong112

# Package imports
import numpy as np
import matplotlib.pyplot as plt
from testCases import *
import sklearn
import sklearn.datasets
import sklearn.linear_model
from planar_utils import
plot_decision_boundary, sigmoid, load_planar_dataset, load_extra_datasets %matplotlib inline np.random.seed(1) # set a seed so that the results are consistent
X, Y = load_planar_dataset()
#資料集型別,形狀,例項
print (type(X),X.shape,X[:,0])
print (type(Y),Y.shape,Y[:,:3])
# Visualize the data:
# plt.scatter(X[0, :], X[1, :], c=Y, s=40, cmap=plt.cm.Spectral);  #原來的會報錯維度不匹配
plt.scatter(X[0, :], X[1, :],c=np.squeeze(Y[0,:]),s=40, cmap=plt.cm.Spectral); #根據下面圖形,可以看出資料都在(-4,4)之間,可以考慮不進行資料處理 plt.figure() plt.scatter(X[0, :200], X[1, :200],c='red',s=40, cmap=plt.cm.Spectral); plt.figure() plt.scatter(X[0, 200:400], X[1, 200:400],c='blue',s=40, cmap=plt.cm.Spectral); ''' why the data looks like a "flower" '''

正向傳播:

(1)z[1]=W[1]X+b[1]z^{[1]} = W^{[1]}X + b^{[1]}\tag{1} (2)a[1]=g[1](z[1])a^{[1]} = g^{[1]}(z^{[1]})\tag{2} (3)z[2]=W[2]a[1]+b[2]z^{[2]} = W^{[2]}a^{[1]} + b^{[2]}\tag{3} (4)a[2]=σ(z[2])a^{[2]} = \sigma (z^{[2]})\tag{4} (5)J=1mi=1m(y(i)log(a[2](i))+(1y(i))log(1a[2](i))) J =-\frac{1}{m} \sum_{i=1}^m (y^{(i)} \log(a^{[2](i)}) + (1-y^{(i)} ) \log(1-a^{[2](i)}))\tag{5}

反向傳播:

(1)da[2]=Ja[2]=1mi=1m[ya[2]+1y1a[2]]da^{[2]} = \frac{\partial J}{\partial a^{[2]}} = \frac{1}{m} \sum_{i=1}^m[-\frac {y}{a^{[2]}} + \frac {1-y}{1-a^{[2]}}]\tag{1} (2)dz[2]=Ja[2]×a[2]z[2]=1mi=1m[a[2]y]\mathrm{d}z^{[2]} = \frac {\partial{J}}{\partial{a^{[2]}}} \times \frac {\partial{a^{[2]}}}{\partial{z^{[2]}}} = \frac{1}{m} \sum_{i=1}^m[a^{[2]}-y]\tag{2} (3)dw[2]=dz[2]×z[2]w[2]=dz[2]×a[1]T\mathrm{d}w^{[2]} = \mathrm{d}z^{[2]} \times \frac {\partial{z^{[2]}}}{\partial{w^{[2]}}} = \mathrm{d}z^{[2]} \times a^{[1]T}\tag{3} (4)db[2]=dz[2]×z[2]b[2]=dz[2]\mathrm{d}b^{[2]} = \mathrm{d}z^{[2]} \times \frac {\partial{z^{[2]}}}{\partial{b^{[2]}}} = \mathrm{d}z^{[2]}\tag{4} (5)da[1]=dz[2]×z[2]a[1]=w[2]Tdz[2]\mathrm{d}a^{[1]} = \mathrm{d}z^{[2]} \times \frac {\partial{z^{[2]}}}{\partial{a^{[1]}}} = w^{[2]T} \cdot \mathrm{d}z^{[2]} \tag{5} (6)dz[1]=da[1]×g[1](z[1])=w[2]Tdz[2]g[1](z[1])\mathrm{d}z^{[1]} = \mathrm{d}a^{[1]} \times g^{[1]}\prime(z^{[1]}) = w^{[2]T} \cdot \mathrm{d}z^{[2]} \cdot g^{[1]}\prime(z^{[1]}) \tag{6} (7)dw[1]=dz[1]XT\mathrm{d}w^{[1]} = \mathrm{d}z^{[1]} \cdot X^{T}\tag{7} (8)db[1]=dz[1]\mathrm{d}b^{[1]} = \mathrm{d}z^{[1]}\tag{8}

#初始化正向傳播過程中的4個引數
def initialize_pars(num_in,num_h,num_out):
    np.random.seed(2)
    
    w1 = np.random.randn(num_h,num_in)*0.01
    #乘0.01是為了不讓下降速度太慢
    b1 = np.zeros((num_h,1))
    w2 = np.random.randn(num_out,num_h)
    b2 = np.zeros((num_out,1))
    
    assert(w1.shape == (num_h,num_in))
    assert(b1.shape == (num_h,1))
    assert(w2.shape == (num_out,num_h))
    assert(b2.shape == (num_out,1))
    
    pars = {'w1':w1,
            'b1':b1,
            'w2':w2,
            'b2':b2
    }
    return pars
    
# Test initialize_pars function
pars_test = initialize_pars(2,4,1)
# print (pars_test['w1'])

            
           

相關推薦

Neural Networks and Deep Learning_week3練習

學習心得: 1、每週的視訊課程看一到兩遍 2、做筆記 3、做每週的作業練習,這個裡面的含金量非常高。掌握後一定要自己敲一遍,這樣以後用起來才能得心應手。 有需要全套作業練習notebook及全套資料的可以留言或者加我微信yuhaidong112 # Pack

Neural Networks and Deep Learning學習筆記ch1 - 神經網絡

1.4 true ole 輸出 使用 .org ptr easy isp 近期開始看一些深度學習的資料。想學習一下深度學習的基礎知識。找到了一個比較好的tutorial,Neural Networks and Deep Learning,認真看完了之後覺

課程一(Neural Networks and Deep Learning)總結:Logistic Regression

pdf idt note hub blog bsp http learn gre -------------------------------------------------------------------------

第四節,Neural Networks and Deep Learning 一書小節(上)

rain 集合 最大值 劃分 import {0} mar result bsp 最近花了半個多月把Mchiael Nielsen所寫的Neural Networks and Deep Learning這本書看了一遍,受益匪淺。 該書英文原版地址地址:http://neur

【DeepLearning學習筆記】Coursera課程《Neural Networks and Deep Learning》——Week1 Introduction to deep learning課堂筆記

決定 如同 樣本 理解 你是 水平 包含 rod spa Coursera課程《Neural Networks and Deep Learning》 deeplearning.ai Week1 Introduction to deep learning What is a

【DeepLearning學習筆記】Coursera課程《Neural Networks and Deep Learning》——Week2 Neural Networks Basics課堂筆記

樣本數目 and 編程 多次 之間 優化 我們 round 符號 Coursera課程《Neural Networks and Deep Learning》 deeplearning.ai Week2 Neural Networks Basics 2.1 Logistic

課程一(Neural Networks and Deep Learning),第一週(Introduction to Deep Learning)—— 0、學習目標

1. Understand the major trends driving the rise of deep learning. 2. Be able to explain how deep learning is applied to supervised learning. 3. Unde

課程一(Neural Networks and Deep Learning),第二週(Basics of Neural Network programming)—— 1、10個測驗題(Neural N

              --------------------------------------------------中文翻譯-------

Neural Networks and Deep Learning

too near poi sel ace data- big Dimension important Neural Networks and Deep Learning This is the first course of the deep learning specia

課程一(Neural Networks and Deep Learning),第一週(Introduction to Deep Learning)—— 2、10個測驗題

1、What does the analogy “AI is the new electricity” refer to?  (B) A. Through the “smart grid”, AI is delivering a new wave of electricity.

sp1.1-1.2 Neural Networks and Deep Learning

    Relu這影象也叫線性流動函式 不再用sigmoid函式當啟用函式     相當於max(0,x)函式 比較0和當前值哪個大   可以把隱藏層看作 前面整合

sp1.3-1.4 Neural Networks and Deep Learning

交叉熵定義了兩個概率分佈之間的距離,因為是概率分佈 所以又引入softmax變為概率的形式 相加還是1 3 shallow neural network   神經網路輸入層不算     上

Neural networks and deep learning 概覽

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

如何免費學習coursera上吳恩達的Neural Networks and Deep Learning課程

首先,在註冊時不要選擇免費試用,而是要選擇旁聽。 進入旁聽之後,中間的部分課程是無法做的,這時候,需要用anaconda的jupyter notebook功能來進行作業。具體方法如下: 安裝後開啟進入到一個資料夾目錄,找到這個目錄在你的資料夾的具體位置。並將作業檔案複

Neural Networks and Deep Learning_week2_神經網路基礎

前段時間在網易雲課堂零散學習了吳恩達老師的機器學習和深度學習課程,能聽懂課程,但是不能使用裡面的技能,學習效率不高。從2018/9開始系統性學習深度學習課程,今特把做的筆記思維導圖傳上部落格,與學習者多多交流。不足之處,不喜勿噴。 目前的學習心得: 1、每週的

Neural Networks and Deep Learning 整理

   之前看了一些吳恩達的視訊和大話機器學習的一部分東西。選擇記錄的這本書頁數比較少,但是可以作為一個不錯的總結記錄。   權重,w1, w2, . . .,表⽰相應輸⼊對於輸出重要性的實數。神經元的輸出,0 或者 1,則由分配權重後的總和 ∑j wjxj ⼩於

Neural Networks and Deep Learning 整理(三)

公式太麻煩,沒寫公式。 交叉熵函式作為代價函式         用求導推理說明了這樣比二次代價函式(方差的形式)要更好一些,即導數和(y-a)成正比。         一開始期望值和輸出的差別越大,下降的速度

Neural Networks and Deep Learning 整理(二)

反向傳播(backpropagation)         權重矩陣         偏置向量         帶權輸入z      

A Beginner's Guide to Neural Networks and Deep Learning

Neural networks are a set of algorithms, modeled loosely after the human brain, that are designed to recognize patterns. They interpret sensory data throug

Neural Networks and Deep Learning 筆記

目錄 1 Introduction to Deep Learning 1.1 結構化資料/非結構化資料 1.2 為什麼深度學習會興起 2 Neural Networks Basics 2.1 二分類問題 2.2 邏輯迴歸 2.3 損失函式