brunch

You can make anything
by writing

C.S.Lewis

by 라인하트 Nov 25. 2020

앤드류 응의 머신러닝(14-1): 차원 축소 데이터 압

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


Dimensionality Reduction 

(차원 축소)


Motivation (동기 부여)


Motivation I: Data Compression (동기부여: 데이터 압축)   


   In this video, I'd like to start talking about a second type of unsupervised learning problem called dimensionality reduction. There are a couple of different reasons why one might want to do dimensionality reduction. One is data compression, and as we'll see later, a few videos later, data compression not only allows us to compress the data and have it therefore use up less computer memory or disk space, but it will also allow us to speed up our learning algorithms. But first, let's start by talking about what is dimensionality reduction.


   이번 강의에서, 비지도 학습 알고리즘의 두 번째 유형인 차원 축소(dimensionality reduction)를 설명합니다. 차원 축소를 활용하는 첫 번째 유형은 데이터 압축입니다. 데이터 압축은 컴퓨터 메모리나 하드디스크 사용량을 줄이고 학습 알고리즘의 속도를 높입니다. 차원 축소가 무엇인지부터 설명합니다. 



    As a motivating example, let's say that we've collected a data set with many, many, many features, and I've plotted just two of them here. And let's say that unknown to us two of the features were actually the length of something in centimeters, and a different feature, x2, is the length of the same thing in inches. So, this gives us a highly redundant representation and maybe instead of having two separate features x1 then x2, both of which basically measure the length, maybe what we want to do is reduce the data to one-dimensional and just have one number measuring this length. 

   In case this example seems a bit contrived, this centimeter and inches example is actually not that unrealistic, and not that different from things that I see happening in industry.  If you have hundreds or thousands of features, it is often this easy to lose track of exactly what features you have. And sometimes may have a few different engineering teams, maybe one engineering team gives you two hundred features, a second engineering team gives you another three hundred features, and a third engineering team gives you five hundred features so you have a thousand features all together, and it actually becomes hard to keep track of you know, exactly which features you got from which team, and it's actually not that want to have highly redundant features like these. And so if the length in centimeters were rounded off to the nearest centimeter and lengthened inches was rounded off to the nearest inch. Then, that's why these examples don't lie perfectly on a straight line, because of, you know, round-off error to the nearest centimeter or the nearest inch. And if we can reduce the data to one dimension instead of two dimensions, that reduces the redundancy. 


   여기 흥미로운 예제가 있습니다. 많은 피처를 가진 데이터 셋에서 두 개의 피처를 기준으로 도식화하였습니다. 피처 x1은 cm 단위이고  피처 x2는 inch 단위입니다. 이 두 피처는 물체의 길이에 대한 값이지만 단위만 다릅니다. 두 피처 x1과 x2를 유지하는 것보다 하나의 피처만을 유지하여 1차원으로 줄이는 것이 효율적입니다. 

   이런 사례는 인위적으로 만든 것처럼 보이겠지만, 실제로 자주 발생합니다. 데이터 셋이 수백 또는 수천의 피처가 있을 때 어떤 피처가 있는지 정확히 추적하는 것은 쉽지 않습니다. 때때로 하나의 데이트 셋을 여러 엔지니어링 팀이 피처 별로 따로 관리하기도 합니다. 예를 들면, 첫 번째 엔지니어링 팀이 200개의 피처를 관리하고, 두 번째 엔지니어링 팀이 300개의 피처를 관리하고 세 번째 엔지니어링 팀이 500개의 피처를 관리합니다. 모두 합치면 1,000개의 피처를 가진 데이터 셋입니다. 실제로 어떤 팀이 어떤 피처를 관리하는지 정확히 파악하는 것은 어렵습니다. 중복되는 피처를 아무도 원하지 않지만 종종 발생합니다

   cm 단위와 inch 단위를 각각 반올림합니다. 반올림 오차는 데이터들이 직선에 완벽하게 일치하지 않게 합니다. 데이터를 2차원에서 1차원으로 줄인다면 중복을 회피할 수 있습니다.



   For a different example, again maybe when there seems fairly less contrives. For many years I've been working with autonomous helicopter pilots.Or I've been working with pilots that fly helicopters. And so. If you were to measure--if you were to, you know, do a survey or do a test of these different pilots--you might have one feature, x1, which is maybe the skill of these helicopter pilots, and maybe "x2" could be the pilot enjoyment. That is, you know, how much they enjoy flying, and maybe these two features will be highly correlated. And what you really care about might be this sort of this sort of, this direction, a different feature that really measures pilot aptitude. And I'm making up the name aptitude of course, but again, if you highly correlated features, maybe you really want to reduce the dimension. So, let me say a little bit more about what it really means to reduce the dimension of the data from 2 dimensions down from 2D to 1 dimensional or to 1D. 


   또 다른 사례가 있습니다. 저는 수년 동안 자율 비행 헬리콥터 조종사와 가끔 헬리콥터 조종사와도 일했습니다. 만일 조종사에 대해 측정이나 조사를 한다면, 헬리콥터 조종사의 조종 기술(pilot skill)에 대한 피처 x1, 조종사의 비행 즐거움(pilot enjoyment)에 대한 피처  x2가 있을 것입니다. 조종사의 비행 즐거움은 조종사들이 얼마나 비행을 즐기는 지를 나타내고 조종 기술은 숙련도를 나타냅니다. 두 피처는 높은 상관관계가 있습니다. 그리고 정말로 측정하고 싶은 것은 일종의 조종사의 적성(aptitude)입니다. 즉, 상관관계가 높은 두 개의 피처를 하나의 피처로 줄일 수 있습니다. 데이터의 차원을 2차원에서 1차원으로 줄이는 것의 의미는 나중에 설명할 것입니다. 

 


   Let me color in these examples by using different colors. And in this case by reducing the dimension what I mean is that I would like to find maybe this line, this, you know, direction on which most of the data seems to lie and project all the data onto that line which is true, and by doing so, what I can do is just measure the position of each of the examples on that line. And what I can do is come up with a new feature, z1, and to specify the position on the line I need only one number, so it says z1 is a new feature that specifies the location of each of those points on this green line. And what this means, is that where as previously if i had an example x1, maybe this was my first example, x1. So in order to represent x1 originally x1. I needed a two dimensional number, or a two dimensional feature vector. Instead now I can represent z1. I could use just z1 to represent my first example, and that's going to be a real number. And similarly x2 you know, if x2 is my second example there, then previously, whereas this required two numbers to represent if I instead compute the projection of that black cross onto the line. And now I only need one real number which is z2 to represent the location of this point z2 on the line. And so on through my M examples. So, just to summarize, if we allow ourselves to approximate the original data set by projecting all of my original examples onto this green line over here, then I need only one number, I need only real number to specify the position of a point on the line, and so what I can do is therefore use just one number to represent the location of each of my training examples after they've been projected onto that green line.


   다른 색을 사용하여 학습 예제를 지정합니다. 2차원 데이터를 1차원으로 줄여서 데이터가 놓여 있는 방향을 찾습니다. 모든 데이터를 하나의 직선 위에 투영하고, 직선에 있는 각 예제의 위치를 측정하는 새로운 피처 z를 생성합니다. 피처 z는 녹색 선 위의 예제를 지정하는 하나의 숫자만 필요합니다. 2차원 그래프에 첫 번째 예제 x^(1)이 있습니다. x^(1)을 표현하기 위해 2차원 숫자 또는 2차원 피처 벡터가 필요합니다. 이제는 z^(1)으로 표현할 수 있고, z^(1)는 실수 한 개입니다. 마찬가지로 두 번째 예제 x^(2)는 2차원 그래프에서 검은색 십자가로 두 개의 숫자가 필요합니다. 이제는 z^(2)로 표현할 수 있고  실수 하나만 필요합니다. m 번째 예제 x^(m)도 마찬가지로 z^(m)으로 표현할 수 있습니다. 정리하면, 2차원 그래프의 녹색선 위의 모든 원래 예제를 근사화할 수 있다면, 하나의 숫자만 필요합니다.  선 위의 점의 위치는 단 하나의 실수만 필요합니다. 녹색 선 위에 투영된 학습 예제의 위치를 나타내는 하나의 숫자만 사용합니다. 

       

   So this is an approximation to the original training self because I have projected all of my training examples onto a line. But now, I need to keep around only one number for each of my examples. And so this halves the memory requirement, or a space requirement, or what have you, for how to store my data. And perhaps more interestingly, more importantly, what we'll see later, in the later video as well is that this will allow us to make our learning algorithms run more quickly as well.    And that is actually, perhaps, even the more interesting application of this data compression rather than reducing the memory or disk space requirement for storing the data. 


   그래서, 모든 학습 예제를 한 줄에 투영했기 때문에 원 학습 예제에 대한 근사치입니다. 두 개의 피처를 하나의 피처로 줄이면서 하나의 숫자만 필요합니다. 데이터를 저장하기 위한 메모리와 하드 디스크 공간을 절반으로 줄입니다. 더 중요한 것은 학습 알고리즘을 더 빨리 실행할 수 있습니다. 



   On the previous slide we showed an example of reducing data from 2D to 1D. On this slide, I'm going to show another example of reducing data from three dimensional 3D to two dimensional 2D. By the way, in the more typical example of dimensionality reduction we might have a thousand dimensional data or 1000D data that we might want to reduce to let's say a hundred dimensional or 100D, but because of the limitations of what I can plot on the slide. I'm going to use examples of 3D to 2D, or 2D to 1D. So, let's have a data set like that shown here. And so, I would have a set of examples x(i) which are points in r3. So, I have three dimension examples. I know it might be a little bit hard to see this on the slide, but I'll show a 3D point cloud in a little bit.


   여러분들은 2D에서 1D로 줄이는 이유와 방법을 이해했습니다. 차원 축소에 관한 일반적인 사례는 1,000차원 데이터를 100차원 데이터로 줄이는 것입니다. 하지만, 표현의 한계와 이해를 돕기 위해 3D에서 2D로 줄이는 사례를 설명합니다. 그림과 같은 데이터 셋이 있습니다. R^(3)의 점 x^(i) 예제 셋입니다.  3차원 데이터 셋 예제입니다. 슬라이드에서 이 부분을 보기가 조금 어려울 수 있지만 조금 있다가 3D 포인트 클라우드를 보여 드리겠습니다



   And it might be hard to see here, but all of this data maybe lies roughly on the plane, like so. And so what we can do with dimensionality reduction, is take all of this data and project the data down onto a two dimensional plane. So, here what I've done is, I've taken all the data and I've projected all of the data, so that it all lies on the plane. Now, finally, in order to specify the location of a point within a plane, we need two numbers, right? We need to, maybe, specify the location of a point along this axis, and then also specify it's location along that axis. So, we need two numbers, maybe called z1 and z2 to specify the location of a point within a plane. 


   보기 어려울 수 있지만 여기 있는 데이터는 대충 평면 위에 놓을 수 있습니다. 모든 데이터를 차원 축소를 통해 2차원 평면 위에 투영합니다.  모든 데이터 평면에 투영할 수 있도록 조정했습니다. 이 축을 따라 점의 위치를 지정하고 그 축을 따라 위치를 지정합니다. 따라서, 평면 내 점의 위치를 지정하려면 z1과 z2라고 하는 두 개의 숫자가 필요합니다.




   And so, what that means, is that we can now represent each example, each training example, using two numbers that I've drawn here, z1, and z2. So, our data can be represented using vector z which are in r2. And these subscript, z subscript 1, z subscript 2, what I just mean by that is that my vectors here, z, you know, are two dimensional vectors, z1, z2. And so if I have some particular examples, z(i), or that's the two dimensional vector, z(i) 1, z(i) 2. And on the previous slide when I was reducing data to one dimensional data then I had only z1, right? And that is what a z1 subscript 1 on the previous slide was, but here I have two dimensional data, so I have z1 and z2 as the two components of the data.


   즉, z1과 z2를 사용하여 학습 예제를 표현할 수 있습니다. 모든 데이터를 R^(2) 벡터 z를 사용하여 표현하 수 있습니다. 벡터 z = [z1 ; z2]이고 벡터 z^(i) = [z^(i)1; z^(i)2] 입니다. 이전 슬라이드에서 2차원 데이터를 1차원 데이터로 축소할 때 z1만 사용했습니다. 여기는 2차원 데이터이므로 두 개의 구성 요소인 z1과 z2가 있습니다. 



   Now, let me just make sure that these figures make sense. So let me just reshow these exact three figures again but with 3D plots. So the process we went through was that shown in the lab is the optimal data set, in the middle the data set projects on the 2D, and on the right the 2D data sets with z1 and z2 as the axis. 


   이제 3개의 그림이 의미가 있는 지를 확인합시다. 정확히 3 개의 그림을 3D로 다시 보여드리겠습니다. 왼쪽은 실험실에서 보여준 최적의 데이터 셋, 중간은 2D로 차원 축소한 데이터 셋, 오른쪽은 z1과 z2 축으로 하는 2D 데이터 셋입니다. 



   Let's look at them a little bit further. Here's my original data set, shown on the left, and so I had started off with a 3D point cloud like so, where the axis are labeled x1, x2, x3, and so there's a 3D point but most of the data, maybe roughly lies on some, you know, not too far from some 2D plain.


좀 더 살펴보겠습니다. 여기 왼쪽에 표시된 원래 데이터 셋이 있습니다. 3D 포인트 클라우드를 시작합니다. x1, x2, x3 레이블이 지정되어 있고, 3D 포인트가 있지만 대부분의 데이터는 대략적으로 2D 평면에서 멀지 않습니다. 


   


   So, what we can do is take this data and here's my middle figure. I'm going to project it onto 2D. So, I've projected this data so that all of it now lies on this 2D surface. As you can see all the data lies on a plane, 'cause we've projected everything onto a plane, 


   여기 중간 그림이 있습니다. 2D로 투사합니다. 에이터를 투영하여 모든 것이 2D 표면에 놓이도록 했습니다. 보시다시피 모든 데이터는 평면에 있습니다. 왜냐하면 모든 데이터를 평면에 투영했기 때문입니다. 



   And so what this means is that now I need only two numbers, z1 and z2, to represent the location of point on the plane.


   이것이 의미하는 것은 점의 위치를 나타내기 위해 z1과 z2 두 개의 숫자만  필요하다는 것입니다. 

      

   And so that's the process that we can go through to reduce our data from three dimensional to two dimensional. So that's dimensionality reduction and how we can use it to compress our data. And as we'll see later this will allow us to make some of our learning algorithms run much faster as well, but we'll get to that only in a later video.


   이것이 바로 데이터를 3차원에서 2차원으로 축소하는 과정입니다. 이것이 차원 축소이며 데이터를 압축하는 방법입니다. 차원 축소는 학습 알고리즘을 훨씬 더 빨리 실행할 수 있게 합니다. 나중에 자세히 다룰 것입니다.  



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



정리하며

 

   여기서 공부하는 비지도 학습 알고리즘은 차원 축소입니다. 차원 축소를 사용하는 가장 큰 이유는 데이터 압축 기능입니다. 상관관계가 높은 피처를 합치거나 줄일 수 있습니다. 예를 들어, 2차원 데이터를 1차원으로 줄일 수 있다면 데이터를 저장하기 위한 메모리와 하드 디스크 공간을 절반으로 줄이고, 학습 알고리즘을 더 빨리 실행할 수 있습니다.


   상관관계가 높은 피처의 예는 몇 가지가 있습니다. 예를 들어, 길이는 cm와 inch로 각각 피처로 표현하기도 하고, 조종사의 조종 스킬과 비행 즐거움으로 나눈 피처를 조종사의 적성으로 합칠 수 있습니다. 



문제 풀이


   차원 축소를 적용합니다. 다음 중 제대로 된 것은?


정답은 3번입니다. 


매거진의 이전글 앤드류 응의 머신러닝(13-5): K-평균 클러스터 수
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari