https://www.coursera.org/learn/neural-networks-deep-learning/lecture/Z8j0R/binary-classification

Hello, and welcome back.
 
In this week we're going to go over the basics of neural network programming.
 
It turns out that when you implement a neural network there
 
are some techniques that are going to be really important.
 
For example, if you have a training set of m training examples,
 
you might be used to processing the training set by having a four loop
 
step through your m training examples.
 
But it turns out that when you're implementing a neural network,
 
you usually want to process your entire training set
 
without using an explicit four loop to loop over your entire training set.
 
So, you'll see how to do that in this week's materials.
 
Another idea, when you organize the computation of, in your network,
 
usually you have what's called a forward pause or forward propagation step,
 
followed by a backward pause or what's called a backward propagation step.
 
And so in this week's materials, you also get an introduction about why
 
the computations, in learning an neural network can be organized in this for
 
propagation and a separate backward propagation.
 
For this week's materials I want to convey these ideas using
 
logistic regression in order to make the ideas easier to understand.
 
But even if you've seen logistic regression before, I think that there'll
 
be some new and interesting ideas for you to pick up in this week's materials.
 
So with that, let's get started.
 
Logistic regression is an algorithm for binary classification.
 
So let's start by setting up the problem.
 
Here's an example of a binary classification problem.
 
You might have an input of an image, like that, and
 
want to output a label to recognize this image as either being a cat,
 
in which case you output 1, or not-cat in which case you output 0,
 
and we're going to use y to denote the output label.
 
Let's look at how an image is represented in a computer.
 
To store an image your computer stores three separate matrices
 
corresponding to the red, green, and blue color channels of this image.
 
So if your input image is 64 pixels by 64 pixels,
 
then you would have 3 64 by 64 matrices
 
corresponding to the red, green and blue pixel intensity values for your images.
 
Although to make this little slide I drew these as much smaller matrices, so
 
these are actually 5 by 4 matrices rather than 64 by 64.
 
So to turn these pixel intensity values- Into a feature vector, what we're
 
going to do is unroll all of these pixel values into an input feature vector x.
 
So to unroll all these pixel intensity values into Feature vector, what we're
 
going to do is define a feature vector x corresponding to this image as follows.
 
We're just going to take all the pixel values 255, 231, and so on.
 
255, 231, and so on until we've listed all the red pixels.
 
And then eventually 255 134 255, 134 and so
 
on until we get a long feature vector listing out all the red,
 
green and blue pixel intensity values of this image.
 
If this image is a 64 by 64 image, the total dimension
 
of this vector x will be 64 by 64 by 3 because that's
 
the total numbers we have in all of these matrixes.
 
Which in this case, turns out to be 12,288,
 
that's what you get if you multiply all those numbers.
 
And so we're going to use nx=12288
 
to represent the dimension of the input features x.
 
And sometimes for brevity, I will also just use lowercase n
 
to represent the dimension of this input feature vector.
 
So in binary classification, our goal is to learn a classifier that can input
 
an image represented by this feature vector x.
 
And predict whether the corresponding label y is 1 or 0,
 
that is, whether this is a cat image or a non-cat image.
 
Let's now lay out some of the notation that we'll
 
use throughout the rest of this course.
 
A single training example is represented by a pair,
 
(x,y) where x is an x-dimensional feature
 
vector and y, the label, is either 0 or 1.
 
Your training sets will comprise lower-case m training examples.
 
And so your training sets will be written (x1, y1) which is the input and
 
output for your first training example (x(2), y(2)) for
 
the second training example up to <xm, ym) which is your last training example.
 
And then that altogether is your entire training set.
 
So I'm going to use lowercase m to denote the number of training samples.
 
And sometimes to emphasize that this is the number of train examples,
 
I might write this as M = M train.
 
And when we talk about a test set,
 
we might sometimes use m subscript test to denote the number of test examples.
 
So that's the number of test examples.
 
Finally, to output all of the training examples into a more compact notation,
 
we're going to define a matrix, capital X.
 
As defined by taking you training set inputs x1, x2 and
 
so on and stacking them in columns.
 
So we take X1 and put that as a first column of this matrix,
 
X2, put that as a second column and so on down to Xm,
 
then this is the matrix capital X.
 
So this matrix X will have M columns, where M is the number of train
 
examples and the number of railroads, or the height of this matrix is NX.
 
Notice that in other causes, you might see the matrix capital
 
X defined by stacking up the train examples in rows like so,
 
X1 transpose down to Xm transpose.
 
It turns out that when you're implementing neural networks using
 
this convention I have on the left, will make the implementation much easier.
 
So just to recap, x is a nx by m dimensional matrix, and
 
when you implement this in Python,
 
you see that x.shape, that's the python command for
 
finding the shape of the matrix, that this an nx, m.
 
That just means it is an nx by m dimensional matrix.
 
So that's how you group the training examples, input x into matrix.
 
How about the output labels Y?
 
It turns out that to make your implementation of a neural network easier,
 
it would be convenient to also stack Y In columns.
 
So we're going to define capital Y to be equal to Y 1, Y 2,
 
up to Y m like so.
 
So Y here will be a 1 by m dimensional matrix.
 
And again, to use the notation without the shape of Y will be 1, m.
 
Which just means this is a 1 by m matrix.
 
And as you influence your new network, mtrain discourse, you find that a useful
 
convention would be to take the data associated with different training
 
examples, and by data I mean either x or y, or other quantities you see later.
 
But to take the stuff or
 
the data associated with different training examples and
 
to stack them in different columns, like we've done here for both x and y.
 
So, that's a notation we we'll use e for a regression and for
 
neural networks networks later in this course.
 
If you ever forget what a piece of notation means, like what is M or
 
what is N or
 
what is something else, we've also posted on the course website a notation guide
 
that you can use to quickly look up what any particular piece of notation means.
 
So with that, let's go on to the next video where we'll start to fetch out
 
logistic regression using this notation.
 
 

嗨,歡迎回來. 這個禮拜我們將學習
基本的神經網路程式 實際上當您
建立神經網路時 有一些技巧
將非常重要 例如, 如果您訓練
一組m個訓練例子 您可能習慣處理
這個訓練集使用迴圈 一個接著一個經過您m個訓練例子 但實際上當您
建置一個神經網路 您通常想要處理
您整個訓練集 不需要使用明顯的迴圈來
迴過您整個訓練集 您會看到如何做到的
在本週的課程裡 另一個觀念,當你組織
運算時,在您的網路中 通常您有所謂的正向
路徑或者正向傳播步驟 接著是反向路徑或者
稱為反向傳播步驟 所以在這個星期的課程
您也會學習到為什麼 在運算中, 在神經
網路可以組織成正向 傳播跟
分別的反向傳播 對於本週的課程我想
傳達這些觀念使用 羅吉斯迴歸分析為了讓
這些觀念易懂 但即使您見過羅吉斯
迴歸分析, 我想還是有 一些新的有趣的觀念
讓您在這週的課程學習到 所以,我們開始吧 羅吉斯迴歸分析是一種演算法
使用在二元分類 讓我們開始設定問題 這是一個例子有關於二元
分類問題 您也許有一個輸入的影像
像這樣 想要輸出一個標籤來識別
這個影像是否是一隻貓 是貓您輸出是1,或者
不是貓輸出是0 而您將使用y
來記這個輸出標籤 讓我們看看一個影像如何
在電腦中呈現 儲存一個影像在電腦
您儲存了三個分別的矩陣 相當是紅,綠跟
藍色通道對於這個影像 所以如果您輸入一個影像是
64像素乘64像素 那您會得到三個64乘64矩陣 相當於紅,綠跟藍
像素強度值對於您的影像 雖然這張小投影片我
畫的是小一點的矩陣 其實是5乘4
矩陣而不是64乘64 所以轉換這些像素強度值
成為一個特徵向量, 我們 將展開這些所有的像素
值變成一個輸入特徵向量x 為了展開所有這些強度
值成為特徵向量我們 將定義一個特徵向量x
相當於這個影像像這樣 我們將拿所有
像素值255,231,..等等 255,231..等等
直到我們列出所有紅的像素 然後終究是255,134,.255,
134..等 直到我們得到一個長的特徵
向量列出所有紅 綠跟
藍像素強度值對於這個影像 如果這是一個64乘64影像
總共的維度 對於這個向量x會是64
乘64乘3因為那是 所有的數字我們
在這些矩陣中 在這個例子
實際上是12,288 這是您得到的數字如果您
將所有這些數字相乘 所以我們將使用nx=12288 來表示
輸入特徵x的維度 有時候為了省略
我也會用小寫的 n 來代表
這個輸入特徵向量的維度 在二元分類中, 我們的目標是
學習一個分類子可以用來輸入 一個影像
用這個特徵向量x表示 來預測是否
相對於標籤y是1還是0 也就是, 是否這是一張貓的影像或
不是貓的影像 讓我們佈置一些
我們將用到的符號 一直到本課程結束 一個單一的訓練例子
是用一對來表示 (x,y)而x是nx維度的特徵 向量, y,標籤則不是0就是1 您的訓練集將包含
小寫m個訓練例子 所以您訓練及會是
寫成(x1,y1)也就是輸入及 輸出對於您的一個訓練
例子, (x2, y2)是 第二個訓練例子直到(xm,
ym)就是最後一個例子 而全部這些
就是您整個訓練集 我將使用小寫m
來表示訓練例子的數目 有時候為了強調這是
訓練例子的數目 我會寫成 m = m下標train 而當我們談到測試集時 我也許有時候使用m下標test 來記測試例子的數量 所以那是測試例子的數量 最後, 輸出所有訓練
例子到更緊湊的記號 我們將定義一個矩陣, 大寫的 X 這樣定義著拿您的
訓練輸入x1,x2... 等等將他們放在一欄一欄上 所以我們拿x1
將它放在第一欄的這個矩陣 x2放在第二欄等等
一直到xm 那這就是矩陣大寫的X 這個矩陣X會有m欄
而m是 訓練例子的數目, 而行數
或者說矩陣的高度是nx 請注意在其他課程裡
您也許看過矩陣大寫 X定義為堆疊訓練
例子在行, 像這樣 x1轉置一直到xm轉置 實際上當您
建置神經網路時使用 這種左邊的方式
會讓建置更快 所以總結一下
X是nx乘m維度的矩陣而 當您用Python建置這個 您看到x.shape
那是Python指令來 找出矩陣的形狀
也就是nx, m 那就意味著它是 nx
乘 m 維矩陣 所以這是您如何組織訓練
例子,輸入x變成矩陣 如何處理輸出標籤y呢? 實際上為了讓您
建置神經網路更容易些 將y疊在欄也是比較容易 所以我們將定義大寫
Y為y1, y2... 一直到ym像這樣 所以Y是1乘
m維度矩陣 同樣地, 使用Python記號
用shape of Y 會是1, m 也就是這是一個1乘m矩陣 而當您日後建置神經網路
在這個課程中您會發現這是有用的 慣例就是拿資料
對應到不同的訓練 例子時, 而這裡的資料指的是x或是
y或是其他的量以後會見到 但拿這些東西或者 資料對應到
不同的訓練例子 堆疊到不同的欄位
像我們這樣做x跟y 所以這就是我們即將用在
羅吉斯迴歸分析跟 神經網路
在往後的課程的記號 如果您忘記了
其中一個記號代表的意思, 像是什麼是m 什麼是n或者 什麼是...我們也發佈在
課程網站上的符號指南 您可以使用它快速的查找
任何特定的記號代表的意思 所以有了這個,讓我們繼續到下一段
影片我們開始來進行 羅吉斯迴歸分析使用這些符號

posted on 2018-03-15 15:34  cdekelon  阅读(315)  评论(0)    收藏  举报

导航