brunch

You can make anything
by writing

C.S.Lewis

by 라인하트 Nov 21. 2020

앤드류 응의 머신러닝(12-6):SVM 활용하기

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


Support Vector Machines  

서포트 벡터 머신  


SVMs in Practice


Using An SVM (SVM 활용하기)           


   So far we've been talking about SVMs in a fairly abstract level. In this video I'd like to talk about what you actually need to do in order to run or to use an SVM. 


   지금까지 우리는 상당히 추상적인 SVM에 대해 이야기했습니다. 이번 강의에서는 SVM을 사용하기 위해 실제로 해야 할 작업들에 대해 이야기할 것입니다. 



   The support vector machine algorithm poses a particular optimization problem. But as I briefly mentioned in an earlier video, I really do not recommend writing your own software to solve for the parameter's theta yourself. So just as today, very few of us, or maybe almost essentially none of us would think of writing code ourselves to invert a matrix or take a square root of a number, and so on. We just, you know, call some library function to do that. In the same way, the software for solving the SVM optimization problem is very complex, and there have been researchers that have been doing essentially numerical optimization research for many years. So you come up with good software libraries and good software packages to do this. And then strongly recommend just using one of the highly optimized software libraries rather than trying to implement something yourself. And there are lots of good software libraries out there. The two that I happen to use the most often are the linear SVM but there are really lots of good software libraries for doing this that you know, you can link to many of the major programming languages that you may be using to code up learning algorithm.


   서포트 벡터 머신 알고리즘은 특정 최적화 문제에서 작동합니다. 지난 강의에서 간략히 설명했듯이 파라미터 θ를 최소화하기 위해 직접 코드를 작성하거나 구현할 필요가 없습니다. 오늘날 아무도 역행렬이나 제곱근을 계산하기 위한 코드를 작성하지 않습니다. 사람들은 역행렬과 제곱근을 계산하기 위해 라이브러리 함수를 호출합니다. 마찬가지로 많은 연구자들이 매우 복잡한 SVM 최적화 문제를 해결하기 위해 수년 동안 연구하였습니다. 오늘날 좋고 최적화된 소프트웨어 라이브러리와 패키지가 많이 있기 때문에 직접 구현할 필요가 없습니다. SVM을 이용한 학습 알고리즘을 구현할 때 자주 사용하는 소프트웨어는 liblinear와 libsvm입니다. 



   Even though you shouldn't be writing your own SVM optimization software, there are a few things you need to do, though. First is to come up with with some choice of the parameter's C. We talked a little bit of the bias/variance properties of this in the earlier video. Second, you also need to choose the kernel or the similarity function that you want to use. So one choice might be if we decide not to use any kernel. And the idea of no kernel is also called a linear kernel. So if someone says, I use an SVM with a linear kernel, what that means is you know, they use an SVM without using without using a kernel and it was a version of the SVM that just uses theta transpose X, right, that predicts 1 theta 0 plus theta 1 X1 plus so on plus theta N, X N is greater than equals 0.


   SVM 최적화 소프트웨어를 구현할 필요가 없더라도 제대로 구동시키기 위해 몇 가지를 결정해야 합니다. 첫 번째는 파라미터 C를 선택하는 것입니다. 지난 강의에서 편향과 분산에 대해 설명했습니다. 두 번째는 사용할 커널 또는 유사도 함수를 선택하는 것입니다. 커널을 없다는 것은 선형 커널을 사용하는 것입니다. 따라서, 누군가가 선형 커널과 SVM을 사용한다면, 커널을 사용하지 않고 SVM을 사용한다는 것입니다.  예를 들면, 다음은 SVM 버전의 가설입니다. 

   This term linear kernel, you can think of this as you know this is the version of the SVM that just gives you a standard linear classifier. So that would be one reasonable choice for some problems, and you know, there would be many software libraries, like linear, was one example, out of many, one example of a software library that can train an SVM without using a kernel, also called a linear kernel. So, why would you want to do this? If you have a large number of features, if N is large, and M the number of training examples is small, then you know you have a huge number of features that if X, this is an X is an Rn, Rn +1. So if you have a huge number of features already, with a small training set, you know, maybe you want to just fit a linear decision boundary and not try to fit a very complicated nonlinear function, because might not have enough data. And you might risk overfitting, if you're trying to fit a very complicated function in a very high dimensional feature space, but if your training set sample is small. So this would be one reasonable setting where you might decide to just not use a kernel, or equivalents to use what's called a linear kernel. 


   선형 커널은 표준 선형 분류기를 제공하는 SVM 버전입니다. 이것은 커널을 사용하지 않고 SVM이 학습하는 소프트웨어 라이브러리의 예입니다. 왜 선형 커널을 사용할까요? 피처 n의 개수가 매우 많고 학습 예제의 수 m이 작은 경우를 생각해 봅시다. 피처가 매우 많지만 데이터가 충분하지 않기 때문에 단순한 선형 결정 경계가 복잡한 비선형 함수에 비해 효과적입니다. 데이터가 충분하지 않을 때 고차원의 피처 공간에 매우 복잡한 함수를 맞출 때 과적합이 발생하기 때문입니다. 커널을 사용하지 않거나 선형 커널을 사용하는 것은 합리적인 설정입니다. 



   A second choice for the kernel that you might make, is this Gaussian kernel, and this is what we had previously. And if you do this, then the other choice you need to make is to choose this parameter sigma squared when we also talk a little bit about the bias variance tradeoffs of how, if sigma squared is large, then you tend to have a higher bias, lower variance classifier, but if sigma squared is small, then you have a higher variance, lower bias classifier. So when would you choose a Gaussian kernel? Well, if your omission of features X, I mean 

Rn, and if N is small, and, ideally, you know, if n is large, right, so that's if, you know, we have say, a two-dimensional training set, like the example I drew earlier. So n is equal to 2, but we have a pretty large training set. So, you know, I've drawn in a fairly large number of training examples, then maybe you want to use a kernel to fit a more complex nonlinear decision boundary, and the Gaussian kernel would be a fine way to do this. I'll say more towards the end of the video, a little bit more about when you might choose a linear kernel, a Gaussian kernel and so on.


   두 번째 고려 사항은 가우시안 터널입니다. σ^2이 크면 더 높은 편향이 있고, 편향과 분산의 트레이드오프를 이야기할 때 파라미터 σ^2를 선택합니다. 더 낮은 분산 분류기이지만 σ^2이 작으면 분산이 더 높고 더 낮은 편향 분류기입니다. 그러면 언제 가우시안 커널을 선택할까요? 피처 x는 R^(n) 차원이고, n은 작고 m이 크면 간단하게 그린 2차원 학습 셋입니다. 즉, n= 2이고, 학습셋은 꽤 큽니다.  여기 상당히 많은 수의 학습 예제를 그렸습니다. 그러면 더 복잡한 비선형 결정 경계에 맞추기 위해 커널을 사용합니다. 가우스 커널은 이것을 수행하기 좋은 방법입니다. 강의 마지막 부분에서 선형 커널과 가우시안 커널 등을 선택할 수 있는 시기에 대해 조금 더 설명할 것입니다. 



   But if concretely, if you decide to use a Gaussian kernel, then here's what you need to do. Depending on what support vector machine software package you use, it may ask you to implement a kernel function, or to implement the similarity function. So if you're using an octave or MATLAB implementation of an SVM, it may ask you to provide a function to compute a particular feature of the kernel. So this is really computing f subscript i for one particular value of i, where f here is just a single real number, so maybe I should move this better written f(i), but what you need to do is to write a kernel function that takes this input, you know, a training example or a test example whatever it takes in some vector X and takes as input one of the landmarks and but only I've come down X1 and X2 here, because the landmarks are really training examples as well. But what you need to do is write software that takes this input, you know, X1, X2 and computes this sort of similarity function between them and return a real number. And so what some support vector machine packages do is expect you to provide this kernel function that take this input you know, X1, X2 and returns a real number.


   그러나 구체적으로 가우시안 커널을 사용하기 위해 필요한 작업은 다음과 같습니다. 서포트 벡터 머신 소프트웨어 패키지에 따라 커널 함수 구현 또는 유사도 함수 구현을 요청할 수 있습니다. 따라서 옥타브 또는 매트랩에서 SVM을 구현할 때 커널의 특정 기능을 계산하는 함수를 호출할 수 있습니다. 실제로 아래 첨자 i 사용하는 fi를 계산합니다. f는 실수일 뿐입니다. fi로 바꿔야 하지만 커널을 먼저 작성합니다. f = kernel(x1, x2)에서 입력은 학습 예제 또는 테스트 예제입니다. 어떤 벡터 x를 받으면 x2는 랜드마크 중 하나를 입력합니다. 랜드마크는 실제로 학습 예제이기 때문에 여기서는 x1과 x2를 표시합니다. 다음 작업은 x1과 x2 입력을 받아 x1과 x2 사이의 유사도 함수를 계산하고 실수를 반환하는 소프트웨어를 구축하는 것입니다. 그래서 일부 서포트 벡터 머신 패키지는 이 커널 함수를 제공합니다. 즉, x1과 x2 입력을 받아 실수를 반환합니다.  

    

   And then it will take it from there and it will automatically generate all the features, and so automatically take X and map it to f1, f2, down to f(m) using this function that you write, and generate all the features and train the support vector machine from there. But sometimes you do need to provide this function yourself. Other if you are using the Gaussian kernel, some SVM implementations will also include the Gaussian kernel and a few other kernels as well, since the Gaussian kernel is probably the most common kernel. Gaussian and linear kernels are really the two most popular kernels by far. 

   그리고 모든 Feature를 자동으로 생성할 것입니다. 자동으로 x를 가져와서 f1, f2,..., fm까지 매핑합니다. 그리고 모든 Feature를 생성하고 서포트 벡터 머신을 학습시킵니다. 때때로 직접 학습합니다. 일부 SVM을 구현할 때 가우시안 커널과 몇 가지 다른 커널을 사용하지만, 가우시안 커널이 가장 일반적입니다. 가우스 및 선형 커널은 실제로 가장 인기 있는 커널입니다. 



   Just one implementational note. If you have features of very different scales, it is important to perform feature scaling before using the Gaussian kernel. And here's why. If you imagine the computing the norm between X and l, right, so this term here, and the numerator term over there. What this is doing, the norm between X and l, that's really saying, you know, let's compute the vector V, which is equal to X minus l. And then let's compute the norm does vector V, which is the difference between X. So the norm of V is really equal to V1 squared plus V2 squared plus dot dot dot, plus Vn squared. Because here X is in Rn, or Rn plus 1, but I'm going to ignore, you know, X0. So, let's pretend X is an Rn, square on the left side is what makes this correct. So this is equal to that, right? And so written differently, this is going to be X1 minus l1 squared, plus x2 minus l2 squared, plus dot dot dot plus Xn minus ln squared. 


   구현 참고 사항입니다. 다른 스케일의 피처가 있을 경우 가우시안 커널을 사용하기 전에 피처 스케일링을 수행합니다.  그 이유는 여기에 있습니다. 우선  ||x - ㅣ||^2 계산한다고 가정합니다. 


         ||x - ㅣ||^2  = ||v||^2  (v = x - l 일 때)

                          = v1^2 + v2^2 +... + vn^2 

                          = (x1- l1)^2 + (x2 - l2)^2 +... + (xn - ln)^2


   따라서, x는 R^(n) 또는 R^(n+1) 차원 벡터입니다. 여기서 x0는 무시합니다. x가 R^(n) 차원이라고 가정합니다. 



   And now if your features take on very different ranges of value. So take a housing prediction, for example, if your data is some data about houses. And if X is in the range of thousands of square feet, for the first feature, X1. But if your second feature, X2 is the number of bedrooms. So if this is in the range of one to five bedrooms, then X1 minus l1 is going to be huge. This could be like a thousand squared, whereas X2 minus l2 is going to be much smaller and if that's the case, then in this term, those distances will be almost essentially dominated by the sizes of the houses and the number of bathrooms would be largely ignored. As so as, to avoid this in order to make a machine work well, do perform future scaling. And that will sure that the SVM gives, you know, comparable amount of attention to all of your different features, and not just to in this example to size of houses were big movement here the features.


   이제 Feature가 매우 다른 범위의 값을 가지는 경우를 생각해 봅니다. 예를 들어, 학습 예제가 주택에 대한 데이터인 경우 주택 가격을 예측합니다. Feature x1은 1,000 feet^2입니다. Feature x2는 침실의 수로 1-5의 범위에 있습니다. x1 - l1의 값은 엄청 큰 값인 반면에 x2 - l2의 값은 매우 작은 값일 것입니다. 따라서, (x1 - l1) 항의 거리는 본질적으로 집의 크기에 의해 좌우되고 침실의 수는 무시될 것입니다. SVM이 제대로 동작하려면 피처 스케일을 해야 합니다. 다른 모든 Feature들이 비슷한 범위의 값을 가져야 합니다. 이 예에서 집의 크기는 너무 큰 값입니다. 



   When you try a support vector machines chances are by far the two most common kernels you use will be the linear kernel, meaning no kernel, or the Gaussian kernel that we talked about. And just one note of warning which is that not all similarity functions you might come up with are valid kernels. And the Gaussian kernel and the linear kernel and other kernels that you sometimes others will use, all of them need to satisfy a technical condition. It's called Mercer's Theorem and the reason you need to this is because support vector machine algorithms or implementations of the SVM have lots of clever numerical optimization tricks. 

In order to solve for the parameter's theta efficiently and in the original design envisaged, those are decision made to restrict our attention only to kernels that satisfy this technical condition called Mercer's Theorem. And what that does is, that makes sure that all of these SVM packages, all of these SVM software packages can use the large class of optimizations and get the parameter theta very quickly. So, what most people end up doing is using either the linear or Gaussian kernel, but there are a few other kernels that also satisfy Mercer's theorem and that you may run across other people using, although I personally end up using other kernels you know, very, very rarely, if at all.


   서포트 벡터 머신을 사용할 때 활용하는 두 가지 커널은 커널 없음 을 의미하는 선형 커널과 가우스 커널입니다. "모든 유사도 함수가 유효한 커널은 아닙니다."라는 경고가 있습니다. 가우시안 커널, 선형 커널, 기타 다른 커널은 모두 기술적인 조건을 충족해야 합니다. 이것은 머서(Mercer)의 정리라고 합니다. 서포트 벡터 머신 알고리즘과 서포트 벡터 머신 구현에 많은 수학적 최적화 수법이 있기 때문입니다. 파라미터  θ를 효율적으로 해결하기 위해 머서의 정리라고 불리는 기술적 조건을 충족하는 커널에만 집중합니다. 모든 SVM 패키지가 대규모 최적화 클래스를 사용하고 파라미터 θ를 매우 빠르게 계산하는 것입니다. 그래서, 많은 사람들이 선형 또는 가우스 커널을 사용하지만 머서의 정리를 만족시키는 다른 커널이 있고 다른 커널을 사용할 수 있습니다. 아주 드물게 개인적으로 알고 있는 다른 커널을 사용하기도 합니다. 



   Just to mention some of the other kernels that you may run across. One is the polynomial kernel. And for that the similarity between X and l is defined as, there are a lot of options, you can take X transpose l squared. So, here's one measure of how similar X and l are. If X and l are very close with each other, then the inner product will tend to be large. And so, you know, this is a slightly unusual kernel. That is not used that often, but you may run across some people using it. This is one version of a polynomial kernel. 


   다른 커널들 중에 몇 가지를 설명합니다. 하나는 다항식 커널입니다. 벡터 x와 l 사이의 유사도는 다음과 같이 정의합니다. 

  

         k(x, l) = (X^Tl)^2 


   즉, x와 l이 얼마나 유사한 지를 측정합니다. x와 l이 매우 가까우면 내적이 커지는 경향이 있습니다. 이것은 약간 특이한 커널입니다. 이것은 자주 사용하지 않지만 가끔 사용합니다. 이것은 다항식 커널의 한 버전입니다. 



   Another is X transpose l cubed. These are all examples of the polynomial kernel. X transpose l plus 1 cubed. X transpose l plus maybe a number different then one 5 and, you know, to the power of 4 and so the polynomial kernel actually has two parameters. One is, what number do you add over here? It could be 0. This is really plus 0 over there, as well as what's the degree of the polynomial over there. So the degree power and these numbers. And the more general form of the polynomial kernel is X transpose l, plus some constant and then to some degree in the X1 and so both of these are parameters for the polynomial kernel. So the polynomial kernel almost always or usually performs worse. And the Gaussian kernel does not use that much, but this is just something that you may run across.


다른 다항식 커널도 있습니다. 


        (X^Tl)^3, (X^Tl + 1)^3, (X^Tl + 5)^4


   다항식에는 실제로 두 개의 매개 변수가 있습니다. 하나는 X^Tl에 어떤 상수를 더하는 것입니다. 따라서, 


        (X^Tl)^2 = (X^Tl + 0)^3 


  또 다른 하나는 다항식의 차수입니다. 여기에 있는 제곱, 세제곱, 네제곱입니다. 다항식 커널의 더 일반적인 형태는 


       (X^Tl + 상수)^차수


   따라서, 이 두 가지가 다항식 커널의 파라미터입니다. 다항식 커널은 거의 항상 성능이 저하됩니다. 가우스 커널은 그 다지 많이 사용하지 않습니다. 실제로 경험할 수 있습니다. 


   Usually it is used only for data where X and l are all strictly non negative, and so that ensures that these inner products are never negative. And this captures the intuition that X and l are very similar to each other, then maybe the inter product between them will be large. They have some other properties as well but people tend not to use it much. 


   일반적으로 x와 l이 모두 음수가 아닌 데이터에만 사용되므로 내적은 절대로 음수가 되지 않습니다. 이것은 x와 l이 매우 유사하다는 것을 포착할 수 있습니다. 아마도 x와 l의 곱은 매우 클 것입니다. 그것들은 다른 속성도 있지만 그것을 많이 사용하지 않는 경향이 있습니다. 



   And then, depending on what you're doing, there are other, sort of more esoteric kernels as well, that you may come across. You know, there's a string kernel, this is sometimes used if your input data is text strings or other types of strings. There are things like the chi-square kernel, the histogram intersection kernel, and so on. There are sort of more esoteric kernels that you can use to measure similarity between different objects. So for example, if you're trying to do some sort of text classification problem, where the input x is a string then maybe we want to find the similarity between two strings using the string kernel, but I personally you know end up very rarely, if at all, using these more esoteric kernels. I think I might have use the chi-square kernel, may be once in my life and the histogram kernel, may be once or twice in my life. I've actually never used the string kernel myself. But in case you've run across this in other applications. You know, if you do a quick web search we do a quick Google search or quick Bing search you should have found definitions that these are the kernels as well. 


   그리고, 경우에 따라 더 난해하고 복잡한 커널도 만날 수 있습니다. 문자열 커널은 입력 데이터가 텍스트 문자열이거나 다른 유형의 문자열일 때 사용합니다. 카이-스퀘어 커널, 히스토그램 교차 커널 등도 있습니다. 다른 객체 사이의 유사성을 측정하는 좀 난해한 커널입니다. 예를 들어, 입력 x가 문자열인 일종의 텍스트 분류 문제를 수행할 때 문자열 커널을 사용하여 두 문자열 사이의 유사성을 찾을 수 있습니다. 또는 더 난해한 카이- 스퀘어 커널을 평생 한 번 사용했을 수도 있고, 히스토그램 커널을 사용할 수도 있습니다. 필자는 직접 문자열 커널을 사용하지 않았습니다. 그러나 경우에 따라 다른 응용 프로그램에서 이 커널을 실행했을 것입니다. 빠르게 웹 검색을 할 때 구글 검색 또는 빙 검색을 사용할 것입니다. 이것들도 커널입니다. 



   So just two last details I want to talk about in this video. One in multiclass classification. So, you have four classes or more generally 3 classes output some appropriate decision boundary between your multiple classes. Most SVM, many SVM packages already have built-in multiclass classification functionality. So if your using a pattern like that, you just use the both that functionality and that should work fine. Otherwise, one way to do this is to use the one versus all method that we talked about when we are developing logistic regression. So what you do is you trade kSVM's if you have k classes, one to distinguish each of the classes from the rest. 


   이번 강의 마지막에서 이야기하고 싶은 두 가지가 있습니다. 하나는 멀티클래스 분류입니다. 여기 멀티 클래스 사이에서 적절한 결정 경계를 그리는 4 개의 클래스 또는 3 개의 클래스가 있습니다. 대부분의 SVM은 이미 내장된 멀티클래스 분류 기능이 있습니다. 이와 같은 패턴을 사용할 때 해당 기능을 사용하면 제대로 작동합니다. 그렇지 않을 경우 멀티클래스를 분류할 수 있는 한 가지 방법은 로지스틱 회귀를 개발할 때 언급한 대로 일대 다 방법을 사용하는 것입니다. 즉, k개의 클래스가 있다면 k 개의 SVM을 학습합니다. 하나의 클래스는 나머지 클래스와 구별합니다. 이것이 파라미터 벡터 k입니다. 


   And this would give you k parameter vectors, so this will give you theta 1, which is trying to distinguish class y equals one from all of the other classes, then you get the second parameter, vector theta 2, which is what you get when you, you know, have y equals 2 as the positive class and all the others as negative class and so on up to a parameter vector theta k, which is the parameter vector for distinguishing the final class key from anything else, and then lastly, this is exactly the same as the one versus all method we have for logistic regression. Where we you just predict the class i with the largest theta transpose X. So let's multiclass classification designate. For the more common cases that there is a good chance that whatever software package you use, you know, there will be a reasonable chance that are already have built in multiclass classification functionality, and so you don't need to worry about this result. 


   k 개의 파라미터 벡터를 제공합니다.   첫 번째 파라미터 벡터 θ^(1)은 다른 모든 클래스와 구별되는 값인 y = 1입니다. 두 번째 파라미터 벡터 θ^(2)는 다른 모든 클래스와 구별되는 값인 y = 2입니다. y는 양의 클래스이고 나머지는 모두 음의 클래스입니다. 마지막으로 θ^(k)는 다른 모든 클래스와 구별되는 값인 y = k입니다. 로지스틱 회귀에서 사용한 모든 것이 도일합니다. 가장 큰 (θ^(i))^Tx를 사용하여 클래스 i를 예측합니다. 어떤 소프트웨어 패키지를 사용하던지 멀티클래스 분류 기능이 내장되어 있습니다. 이 기능을 사용하면 결과를 쉽게 도출할 수 있으므로 걱정할 필요는 없습니다. 



   Finally, we developed support vector machines starting off with logistic regression and then modifying the cost function a little bit. The last thing we want to do in this video is, just say a little bit about. when you will use one of these two algorithms, so let's say n is the number of features and m is the number of training examples.So, when should we use one algorithm versus the other? Well, if n is larger relative to your training set size, so for example, if you take a business with a number of features this is much larger than m and this might be, for example, if you have a text classification problem, where you know, the dimension of the feature vector is I don't know, maybe, 10 thousand. And if your training set size is maybe 10 you know, maybe, up to 1000. So, imagine a spam classification problem, where email spam, where you have 10,000 features corresponding to 10,000 words but you have, you know, maybe 10 training examples or maybe up to 1,000 examples. So if n is large relative to m, then what I would usually do is use logistic regression or use it as the m without a kernel or use it with a linear kernel. Because, if you have so many features with smaller training sets, you know, a linear function will probably do fine, and you don't have really enough data to fit a very complicated nonlinear function. 


   지금까지 로지스틱 회귀로 시작하여 비용 함수를 약간 수정한 서포트 벡터 머신을 개발했습니다. 마지막으로 n은 피처의 수이고 m은 학습 예제의 수 일 때 어떤 알고리즘을 사용해야 할까요? 만약 피처의 수 n이 학습 예제의 수 m 보다 클 때를 가정합니다. 예를 들어, 학습 예제의 수보다 피처의 수가 훨씬 큰 상황입니다. n = 10,000이고 m = 10 or 1000입니다. 텍스트 분류 문제나 스팸 분류 문제를 생각하면 수월합니다. 이메일 스팸은 10,000개의 단어에 해당하는 10,000개의 피처가 있지만 학습 예제는 10개뿐이거나 1,000개뿐입니다. n이 m에 비해 크면 일반적으로 로지스틱 회귀를 사용하거나 커널 없이 서포트 벡터 머신을 사용합니다. 학습 세트가 적고 피처가 많으면 선형 함수가 잘 동작합니다. 왜냐하면 복잡한 비선형 함수에 적합할 만큼 데이터가 충분하지 않기 때문입니다. 


   Now if is n is small and m is intermediate what I mean by this is n is maybe anywhere from 1 - 1000, 1 would be very small. But maybe up to 1000 features and if the number of training examples is maybe anywhere from 10, you know, 10 to maybe up to 10,000 examples. Maybe up to 50,000 examples. If m is pretty big like maybe 10,000 but not a million. Right? So if m is an intermediate size then often an SVM with a linear kernel will work well. We talked about this early as well, with the one concrete example, this would be if you have a two dimensional training set. So, if n is equal to 2 where you have, you know, drawing in a pretty large number of training examples. So Gaussian kernel will do a pretty good job separating positive and negative classes. 


   이제 n 이 작고 m이 중간일 때를 가정합니다. n은 1-1000 사이의 어느 곳이든 1은 매우 작을 것입니다. 최대 1000 개의 피처와 학습 에제의 수가 10개에서 최대 10,000개까지 가능합니다. 아마도 최대 50,000 개의 예제도 가능합니다. m은 10,000이지만 백만 개의 단위는 아닙니다. 따라서, m이 중간 크기이면 선형 커널이 있는 SVM이 잘 작동하는 경구가 많습니다. 우리는 이것을 이미 다루었습니다. 2차원 훈련 셋이 있는 경우입니다 다. n =2이고 꽤 많은 수의 학습 예제가 있는 오른쪽 그림입니다.  따라서, 가우시안 커널은 양의 클래스와 음의 클래스를 분리하는 데 효과적입니다.  


   One third setting that's of interest is if n is small but m is large. So if n is you know, again. maybe 1 to 1000, could be larger. But if m was, maybe 50,000 and greater to millions. So, 50,000, a 100,000, million, trillion. You have very very large training set sizes, right. So if this. is the case, then a SVM of the Gaussian Kernel will be somewhat slow to run. 


   세 번째는 n이 작고 m이 큰 경우입니다. n은 1에서 1,000 사이의 값이고, m은 50,000에서 수백만 개 이상일 수 있습니다. 50,000, 100,000, 백만, 조 등의 크기일 수 있습니다. 매우 큰 학습 셋입니다. 따라서, 가우시안 커널의 SVM은 다소 느리게 계산을 수행합니다.

   


   Today's SVM packages, if you're using a Gaussian Kernel, tend to struggle a bit. If you have, you know, maybe 50 thousands okay, but if you have a million training examples, maybe or even a 100,000 with a massive value of m. Today's SVM packages are very good, but they can still struggle a little bit when you have a massive, massive trainings that size when using a Gaussian Kernel. So in that case, what I would usually do is try to just manually create have more features and then use logistic regression or an SVM without the Kernel. And in case you look at this slide and you see logistic regression or SVM without a kernel. In both of these places, I kind of paired them together. There's a reason for that, is that logistic regression and SVM without the kernel, those are really pretty similar algorithms and, you know, either logistic regression or SVM without a kernel will usually do pretty similar things and give pretty similar performance, but depending on your implementational details, one may be more efficient than the other. 


   오늘날의 SVM 패키지는 가우시안 커널을 사용할 때 약간의 어려움을 겪는 경향이 있습니다. 아마도 5만 개 정도의 학습 셋은 괜찮습니다. 하지만 백만 개의 학습 셋은 다를 수 있습니다. 오늘날의 SVM은 매우 뛰어나지만 가우시안 커널은 그 정도의 방대한 학습 셋을 처리할 때 어려움을 겪을 수 있습니다. 따라서, 수동으로 더 많은 피처를 생성한 다음 로지스틱 회귀 또는 커널이 없는 SVM을 사용합니다. 이렇게 짝을 지운 이유는 로지스틱 회귀와 커널이 없는 SVM은 매우 유사한 알고리즘이고 비슷한 성능을 제공하지만 구현 방법에 따라 둘 중 하나가 더 효율적일 수 있기 때문입니다.  


   But, where one of these algorithms applies, logistic regression where SVM without a kernel, the other one is to likely to work pretty well as well. But along with the power of the SVM is when you use different kernels to learn complex nonlinear functions. And this regime, you know, when you have maybe up to 10,000 examples, maybe up to 50,000. And your number of features, this is reasonably large.  That's a very common regime and maybe that's a regime where a support vector machine with a kernel kernel will shine. You can do things that are much harder to do that will need logistic regression. 


   그러나, 커널이 없는 SVM,  로지스틱 회귀 또는 기타 알고리즘 중 하나를 적용할 때 잘 작동할 가능성이 높습니다. 또한 SVM의 성능과 함께 복잡한 비선형 함수를 학습하기 위해 다른 커널을 사용할 때도 있습니다. 그리고 학습 예제가 최대 10,000개에서 50,000개까지 가능합니다. 피처가 1에서 1,000개 라면 충분히 큽니다. 이 상황에서 가장 일반적인 값은 가우시안 커널을 가진 서포트 벡터 머신입니다. 학습 예제가 그 보다 훨씬 더 많다면 로지스틱 회귀가 필요할 것입니다.  


  And finally, where do neural networks fit in? Well for all of these problems, for all of these different regimes, a well designed neural network is likely to work well as well.

The one disadvantage, or the one reason that might not sometimes use the neural network is that, for some of these problems, the neural network might be slow to train. But if you have a very good SVM implementation package, that could run faster, quite a bit faster than your neural network. And, although we didn't show this earlier, it turns out that the optimization problem that the SVM has is a convex optimization problem and so the good SVM optimization software packages will always find the global minimum or something close to it. 

And so for the SVM you don't need to worry about local optima. In practice local optima aren't a huge problem for neural networks but they all solve, so this is one less thing to worry about if you're using an SVM. And depending on your problem, the neural network may be slower, especially in this sort of regime than the SVM.


   마지막으로 인공 신경망은 어디에 적합합니까? 이런 모든 문제에 대한 잘 설계된 신경망이 잘 동작할 것입니다. 때때로 인공 신경망을 사용하지 않는 한 가지 이유이자 단점은 이런 문제들 중 일부에서 인공 신경망의 학습 속도가 늘릴 수 있다는 것입니다. 그러나 아주 좋은 SVM 패키지가 있다면 신경망보다 훨씬 더 빠르게 실행할 수 있습니다. SVM이 최적화 문제는 볼록 최적화 문제입니다. 그래서 좋은 SVM 최적화 소프트웨어 패키지는 항상 전역 최솟값이나 그에 가까운 것을 찾을 것입니다. 따라서 SVM에서 로컬 최적화에 대해 고민할 필요는 없습니다. 실제로 로컬 최적화는 인공 신경망에서 큰 문제는 아니지만 해결해야 합니다. 인공 신경망은 이런 영역에서 SVM보다 더 느릴 수 있습니다. 


    In case the guidelines they gave here, seem a little bit vague and if you're looking at some problems, you know, the guidelines are a bit vague, I'm still not entirely sure, should I use this algorithm or that algorithm, that's actually okay. When I face a machine learning problem, you know, sometimes its actually just not clear whether that's the best algorithm to use, but as you saw in the earlier videos, really, you know, the algorithm does matter, but what often matters even more is things like, how much data do you have. And how skilled are you, how good are you at doing error analysis and debugging learning algorithms, figuring out how to design new features and figuring out what other features to give you learning algorithms and so on. And often those things will matter more than what you are using logistic regression or an SVM. But having said that, the SVM is still widely perceived as one of the most powerful learning algorithms, and there is this regime of when there's a very effective way to learn complex non linear functions. 


   그들이 여기에 제시한 가이드라인이 약간 모호합니다. 어떤 알고리즘을 사용해야 할지 확실치 않습니다. 머신러닝 문제에 부딪혔을 때 종종 가장 좋은 알고리즘이 무엇인지 확실하지 않은 경우도 있지만, 지난 강의에서 배웠듯이 알고리즘보다 더 중요한 것이 있습니다. 바로 데이터의 양과 여러분이 얼마나 능숙하게 알고리즘을 다루는지, 오류 분석을 수행하고 학습 알고리즘 디버깅에 능숙한 지입니다.  새로운 피처를 설계하는 방법을 파악하고 학습 알고리즘에 제공할 수 있는 다른 피처를 파악합니다. 이런 것들이 로지스틱 회귀 또는 SVM을 사용하는 것보다 더 중요합니다. 그러나 SVM은 여전히 가장 강력한 학습 알고리즘 중 하나입니다. 복잡한 비선형 함수를 학습하는 매우 효과적인 방법입니다. 


   And so I actually, together with logistic regressions, neural networks, SVM's, using those to speed learning algorithms you're I think very well positioned to build state of the art you know, machine learning systems for a wide region for applications and this is another very powerful tool to have in your arsenal. One that is used all over the place in Silicon Valley, or in industry and in the Academia, to build many high performance machine learning system.


   그래서 학습 알고리즘의 속도를 높이기 위해 로지스틱 회귀, 인공 신경망, SVM을 사용합니다. 응용 프로그램을 위한 광범위한 지역에 머신 러닝 시스템과 최첨단 기술을 구축합니다. 이것이 여러분의 무기고에 있는 또 다른 강력한 도구입니다. 많은 고성능 머신러닝 시스템을 구축하기 위해 실리콘 밸리에서, 업계에서, 학계에서 이것들을 사용합니다. 



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



문제 풀이


   몇 가지 커널과 C, σ^2 등의 파라미터를 선택하려고 합니다. 어떻게 선택을 하나요?

정답은 2번입니다. 

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