brunch

You can make anything
by writing

C.S.Lewis

by 라인하트 Oct 26. 2020

앤드류 응의 머신러닝(8-7):신경망의 멀티클래스 분류

   온라인 강의 플랫폼 코세라의 창립자인 앤드류 응 (Andrew Ng) 교수는 인공지능 업계의 거장입니다. 그가 스탠퍼드 대학에서 머신 러닝 입문자에게 한 강의를 그대로 코세라 온라인 강의 (Coursera.org)에서 무료로 배울 수 있습니다. 이 강의는 머신러닝 입문자들의 필수코스입니다. 인공지능과 머신러닝을 혼자 공부하면서 자연스럽게 만나게 되는 강의입니다. 


Neural Networks : Representation

신경망 : 표현


Application (응용)


Multiclass Classification (멀티 클래스 분류)    


   In this video, I want to tell you about how to use neural networks to do multiclass classification where we may have more than one category that we're trying to distinguish amongst. In the last part of the last video, where we had the handwritten digit recognition problem, that was actually a multiclass classification problem because there were ten possible categories for recognizing the digits from 0 through 9 and so, if you want us to fill you in on the details of how to do that.


   이번 강의는 다수의 카테고리로 분류하는 멀티클래스 분류 신경망을 설명합니다. 지난 강의에서 손글씨 숫자를 인식하는 신경망 사례를 설명했습니다. 신경망의 손글씨 멀티클래스 분류는 인공 신경망이 0에서 9까지 숫자를 인식하기 위해 10개의 클래스로 숫자를 분류하는 문제입니다. 


      


   The way we do multiclass classification in a neural network is essentially an extension of the one versus all method. So, let's say that we have a computer vision example, where instead of just trying to recognize cars as in the original example that I started off with, but let's say that we're trying to recognize, you know, four categories of objects and given an image we want to decide if it is a pedestrian, a car, a motorcycle or a truck. 


   신경망도 멀티클래스 문제를 one-verus-all 기법을 확장해서 사용합니다. 여기 컴퓨터 비전 예제가 있습니다. 전에는 신경망이 이미지를 차인지 아닌지를 분류하였지만, 지금은 보행자, 자동차, 오토바이, 트럭으로 네 가지 카테고리로 분류합니다. 



   If that's the case, what we would do is we would build a neural network with four output units so that our neural network now outputs a vector of four numbers. So, the output now is actually needing to be a vector of four numbers and what we're going to try to do is get the first output unit to classify: is the image a pedestrian, yes or no. The second unit to classify: is the image a car, yes or no. This unit to classify: is the image a motorcycle, yes or no, and this would classify: is the image a truck, yes or no. And thus, when the image is of a pedestrian, we would ideally want the network to output 1, 0, 0, 0, when it is a car we want it to output 0, 1, 0, 0, when this is a motorcycle, we get it to or rather, we want it to output 0, 0, 1, 0 and so on. So this is just like the "one versus all" method that we talked about when we were describing logistic regression, and here we have essentially four logistic regression classifiers, each of which is trying to recognize one of the four classes that we want to distinguish amongst.  


   출력층을 4개의 유닛으로 구현하면 신경망은 4 개의 숫자로 된 벡터를 출력합니다. 


   첫 번째 출력 유닛은 보행자 여부를 구분하고, 가설 hθ(x) = [1; 0; 0; 0]이다.

   두 번째 출력 유닛은 자동차 여부를 구분하고, 가설 hθ(x) = [0; 1; 0; 0]이다.

   세 번째 출력 유닛은 오토바이 여부를 구분하고, 가설 hθ(x) = [0; 0; 1; 0]이다.

   네 번째 출력 유닛은 트럭 여부를 구분하고, 가설  hθ(x) = [0; 0; 0; 1]이다.


   이것은 로지스틱 회귀의 멀티클래스 분류에서 사용한 one-versus-all과 같습니다. 4 개의 로지스틱 회귀 분류기가 있고 각각은 4 개의 분류 중에 하나씩을 나타냅니다.

   

   


   So, rearranging the slide of it, here's our neural network with four output units and those are what we want h of x to be when we have the different images, and the way we're going to represent the training set in these settings is as follows. So, when we have a training set with different images of pedestrians, cars, motorcycles and trucks, what we're going to do in this example is that whereas previously we had written out the labels as y being an integer from 1, 2, 3 or 4. Instead of representing y this way, we're going to instead represent y as follows: namely Yi will be either 1, 0, 0, 0 or 0, 1, 0, 0 or 0, 0, 1, 0 or 0, 0, 0, 1 depending on what the corresponding image Xi is. And so one training example will be one pair Xi colon Yi where Xi is an image with, you know one of the four objects and Yi will be one of these vectors.


   And hopefully, we can find a way to get our Neural Networks to output some value. So, the h of x is approximately y and both h of x and Yi, both of these are going to be in our example, four dimensional vectors when we have four classes. So, that's how you get neural network to do multiclass classification. This wraps up our discussion on how to represent Neural Networks that is on our hypotheses representation.


  여기 4 개의 출력 유닛을 갖는 신경망이 있습니다. 

   각 유닛은 다른 이미지가 주어졌을 때 hθ(x)의 값이 무엇인지를 나타냅니다. 학습 데이터 셋은  4 X 1 벡터로 보행자, 자동차, 오토바이, 트럭이미지를 나타냅니다. 로지스틱 회귀의 멀티클래스 분류에서 y의 값을 1, 2, 3, 4로 표현했습니다. 반면에 신경망의 멀티클래스 분류는 y의 값을 4 X 1 벡터로 표현합니다. 하나의 학습 예제를 (x^(i), y^(i))로 표현할 때 y^(i)는 4 X 1 벡터 중 하나입니다.   


   신경망은 학습 데이터 셋이 (x^(i), y^(i))일 때 가설 hθ(x)가 4 가지 카테고리로 분류할 떄 4차원 벡터입니다. 이것이 인공신경망이 멀티클래스를 분류하는 방법입니다. 이것으로 신경망을 표현하는 방법입니다. 



   In the next set of videos, let's start to talk about how take a training set and how to automatically learn the parameters of the neural network.


   다음 강의부터  학습 데이터 셋을 가져오는 방법과 신경망의 파라미터를 자동으로 학습하는 방법을 설명합니다.  



앤드류 응의 머신러닝 동영상 강의




정리하며 - 멀티클래스 분류 


   지금까지 이진 분류를 하는 인공 신경망을 살펴보았습니다. 여기서는 멀티클래스로 분류하는 인공 신경망의 기법에 대해 설명합니다. 인공 신경망이 0에서 9까지 숫자를 인식하기 위해 10개의 클래스로 숫자를 분류하는 것이 멀티클래스 분류 문제의 사례입니다. 멀티클래스 문제는 one-verus-all 기법을 확장해서 사용합니다


   멀티 클래스 분류 문제를 해결하는 인공 신경망은 두 개 이상의 출력 유닛을 가집니다. 출력의 결과는 벡터로 표시합니다. 예를 들어, 이지를 4가지 종류로 분류하는 컴퓨터 비전은 다음과 같은 결과를 출력합니다. 


   로지스틱 회귀의 멀티클래스 분류에서 y의 값을 1, 2, 3, 4로 표현했지만, 인공 신경망은 벡터로 표현합니다. 따라서, 훈련용 데이터 셋의 예제를 (x^(i), y^(i))로 표현할 때, y^(i)는 실제값으로 관측치이며 벡터로 표현합니다. 



문제풀이


   10개의 클래스를 가진 멀티클래스 분류 분제가 있습니다. 인공 신경망은 3개 층이며 2 번째층인 은닉층은 5개의 유닛으로 이루어져 있습니다. one-vs-all 기법을 사용할 때 세타는 몇 개의 성분으로 이루어져 있을까요?


정답은 3번입니다. a^(2)0를 고려하면 60개입니다.  


매거진의 이전글 앤드류 응의 머신러닝(8-6):신경망의 논리연산 II
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari