일대다는 이진 분류를 사용하는 방법을 제공합니다.
'예' 또는 '아니요' 예측 결과를 제공합니다.
가능한 해가 N개인 분류 문제에서는 일대다(one-vs.-all)
한 개의 이진 분류기로 구성되며
가능한 각 결과에 대한 분류기입니다. 학습 중에는 모델이 실행됩니다.
이진 분류기의 시퀀스를 통해 각각을 학습시켜 별개의
분류 질문입니다.
예를 들어, 과일 한 조각의 사진을 4,
인식기가 서로 다른 학습자가 될 수 있으며, 각 인식기는 서로 다른 예/아니요에 답변합니다.
질문:
사과 이미지인가요?
주황색 이미지인가요?
바나나 이미지인가요?
포도 이미지인가요?
다음 이미지는 이것이 실제로 어떻게 작동하는지 보여줍니다.
그림 7. 4가지 다른 이미지에 입력되는 배 이미지
바이너리 분류 기준입니다. 첫 번째, 두 번째, 네 번째 모델(
이미지가 각각 사과, 오렌지, 포도인지 여부)
네거티브 클래스를 예측합니다. 세 번째 모델 (실제 상황에서는
양성 클래스를 예측합니다.를 통해 개인정보처리방침을 정의할 수 있습니다.
를 통해 개인정보처리방침을 정의할 수 있습니다.
이 접근 방식은 총 클래스 수가
작지만 클래스 수가 증가함에 따라
증가하기 시작했습니다.
훨씬 더 효율적인 일대다 모델을 만들 수 있습니다
각 출력 노드가 서로 다른
클래스에 대해 자세히 알아보세요. 다음 이미지는 이 접근 방식을 보여줍니다.
그림 8. 동일한 일대다 분류 작업은
신경망 모델입니다. 시그모이드 활성화 함수가 출력에 적용됨
각 출력값은 입력 문장이
image는 지정된 과일입니다. 이 모델은 100개 문자 중 84%가
이미지가 배일 확률은 7% 이고
포도.
1 대 1 (소프트맥스)
그림 8의 출력 레이어에서 확률 값이
합계가 1.0 (또는 100%)이 되지 않습니다. 실제로 합하면 1.43입니다. 일대다(one-vs.-all)
각 이진 결과 세트의 확률은
서로 독립적으로 작동합니다. 다시 말해서
(사과) '사과 아님' 대비 다른 광고 항목의 게재 가능성을 고려하지 않고
과일 옵션: '오렌지', '배', '포도'
각 과일의 확률을 예측하려면
어떻게 해야 할까요? 이 경우 '사과'를 예측하지 않고 '아님'과
'사과'라는 단어를 '주황색' 대비 '배' 비교 '포도'로 바꾸세요.
이러한 유형의 다중 클래스 분류를 일대일 분류라고 합니다.
동일한 유형의 신경망을 사용하여 일대일 분류를 구현할 수 있습니다.
일대다 분류에 사용되는 네트워크 아키텍처로, 한 가지 주요 변경사항이 있습니다.
출력 레이어에 다른 변환을 적용해야 합니다.
일대다 모델의 경우, 각 출력값에 시그모이드 활성화 함수를 적용했습니다.
그 결과 각 노드에 대해 0과 1 사이의 출력값이
이러한 값이 정확히 1이 된다는 것을 보장하지는 않았습니다.
일대일의 경우, 소프트맥스라는 함수를 대신 적용할 수 있습니다.
다중 클래스 문제에서 각 클래스에 소수 확률을 할당합니다.
모든 확률의 합이 1.0이 됩니다. 이러한 추가 제약 조건
학습이 수렴되지 않는 경우보다 더 빠르게 수렴하는 데 도움이 됩니다.
다음 이미지는 일대다 다중 클래스 분류를 재구현합니다.
작업을 일대일 작업으로 간주합니다. 소프트맥스를 실행하기 위해 숨겨진
출력 레이어 (소프트맥스 레이어라고 함) 바로 앞에 오는 레이어는
출력 레이어와 동일한 수의 노드를 사용합니다.
<ph type="x-smartling-placeholder"></ph>
<ph type="x-smartling-placeholder"></ph>
그림 9. 다음을 사용한 일대일 분류의 신경망 구현
살펴보겠습니다 각 출력 값은
입력 이미지가 다른 세 과일이 아닌 지정된 과일임
(모든 확률의 합은 1.0입니다.) 이 모델은 2019년의 90%가
확률을 나타냅니다.
소프트맥스 옵션
다음과 같은 소프트맥스의 변형을 생각해 보세요.
전체 소프트맥스는 앞서 설명한 소프트맥스입니다. 즉,
소프트맥스는 가능한 모든 클래스의 확률을 계산합니다.
후보 샘플링은 소프트맥스에서 특정 예측이 아닌
양성 라벨에 대해 학습했지만
제외 라벨입니다. 예를 들어 사용자가
입력 이미지가 비글이든 블러드하운드이든 상관없이
개가 아닌 모든 예에 대한 확률을 제공합니다.
전체 소프트맥스는 클래스 수가 적을 때 상당히 저렴함
클래스 수가 증가하면 엄청난 비용이 듭니다.
후보 샘플링은 데이터가 큰 문제에서 효율성을
클래스 수
단일 라벨 및 여러 라벨 비교
소프트맥스는 각 예가 정확히 하나의 클래스에 속해 있다고 가정합니다.
그러나 동시에 여러 클래스의 멤버가 될 수 있는 예도 있습니다.
이러한 예의 경우 다음과 같습니다.
소프트맥스를 사용할 수 없습니다.
여러 로지스틱 회귀를 사용해야 합니다.
예를 들어, 위의 그림 9에서 일대일 모델은 각 입력의 입력 값이
이미지는 사과, 오렌지, 배 또는
있습니다. 그러나 입력 이미지에 여러 유형의 과일(
한 그릇에 사과와 오렌지가 담겨 있습니다.
회귀를 사용할 수도 있습니다
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-08-16(UTC)"],[[["\u003cp\u003eThis document explores multi-class classification models, which predict from multiple possibilities instead of just two, like binary classification models.\u003c/p\u003e\n"],["\u003cp\u003eMulti-class classification can be achieved through two main approaches: one-vs.-all and one-vs.-one (softmax).\u003c/p\u003e\n"],["\u003cp\u003eOne-vs.-all uses multiple binary classifiers, one for each possible outcome, to determine the probability of each class independently.\u003c/p\u003e\n"],["\u003cp\u003eOne-vs.-one (softmax) predicts probabilities of each class relative to all other classes, ensuring all probabilities sum to 1 using the softmax function.\u003c/p\u003e\n"],["\u003cp\u003eSoftmax is efficient for fewer classes but can become computationally expensive with many classes; candidate sampling offers an alternative for increased efficiency.\u003c/p\u003e\n"]]],[],null,["# Neural networks: Multi-class classification\n\nEarlier, you encountered\n[**binary classification**](/machine-learning/glossary#binary-classification)\nmodels that could pick between one of *two* possible choices, such as whether:\n\n- A given email is spam or not spam.\n- A given tumor is malignant or benign.\n\nIn this section, we'll investigate\n[**multi-class classification**](/machine-learning/glossary#multi-class)\nmodels, which can pick from *multiple* possibilities. For example:\n\n- Is this dog a beagle, a basset hound, or a bloodhound?\n- Is this flower a Siberian Iris, Dutch Iris, Blue Flag Iris, or Dwarf Bearded Iris?\n- Is that plane a Boeing 747, Airbus 320, Boeing 777, or Embraer 190?\n- Is this an image of an apple, bear, candy, dog, or egg?\n\nSome real-world multi-class problems entail choosing from *millions*\nof separate classes. For example, consider a multi-class classification\nmodel that can identify the image of just about anything.\n\nThis section details the two main variants of multi-class classification:\n\n- [**one-vs.-all**](/machine-learning/glossary#one-vs.-all)\n- **one-vs.-one** , which is usually known as [**softmax**](/machine-learning/glossary#softmax)\n\nOne versus all\n--------------\n\n*One-vs.-all* provides a way to use binary classification\nfor a series of yes or no predictions across multiple possible labels.\n\nGiven a classification problem with N possible solutions, a one-vs.-all\nsolution consists of N separate binary classifiers---one binary\nclassifier for each possible outcome. During training, the model runs\nthrough a sequence of binary classifiers, training each to answer a separate\nclassification question.\n\nFor example, given a picture of a piece of fruit, four\ndifferent recognizers might be trained, each answering a different yes/no\nquestion:\n\n1. Is this image an apple?\n2. Is this image an orange?\n3. Is this image a banana?\n4. Is this image a grape?\n\nThe following image illustrates how this works in practice.\n**Figure 7. An image of a pear being passed as input to four different\nbinary classifiers. The first, second, and fourth models (predicting\nwhether or not the image is an apple, orange, or grape, respectively)\npredict the negative class. The third model (predicting whether or not\nthe image is a pear) predicts the positive class.** For more on how binary classifiers make predictions (setting a classification threshold to convert numerical model output into a positive or negative label), see the [Classification](/machine-learning/crash-course/classification) module.\n\nThis approach is fairly reasonable when the total number of classes\nis small, but becomes increasingly inefficient as the number of classes\nrises.\n\nWe can create a significantly more efficient one-vs.-all model\nwith a deep neural network in which each output node represents a different\nclass. The following image illustrates this approach.\n**Figure 8. The same one-vs.-all classification tasks accomplished using a\nneural net model. A sigmoid activation function is applied to the output\nlayer, and each output value represents the probability that the input\nimage is a specified fruit. This model predicts that there is a 84%\nchance that the image is a pear, and a 7% chance that the image is a\ngrape.**\n\nOne versus one (softmax)\n------------------------\n\nYou may have noticed that the probability values in the output layer of Figure 8\ndon't sum to 1.0 (or 100%). (In fact, they sum to 1.43.) In a one-vs.-all\napproach, the probability of each binary set of outcomes is determined\nindependently of all the other sets. That is, we're determining the probability\nof \"apple\" versus \"not apple\" without considering the likelihood of our other\nfruit options: \"orange\", \"pear\", or \"grape.\"\n\nBut what if we want to predict the probabilities of each fruit\nrelative to each other? In this case, instead of predicting \"apple\" versus \"not\napple\", we want to predict \"apple\" versus \"orange\" versus \"pear\" versus \"grape\".\nThis type of multi-class classification is called *one-vs.-one classification*.\n\nWe can implement a one-vs.-one classification using the same type of neural\nnetwork architecture used for one-vs.-all classification, with one key change.\nWe need to apply a different transform to the output layer.\n\nFor one-vs.-all, we applied the sigmoid activation function to each output\nnode independently, which resulted in an output value between 0 and 1 for each\nnode, but did not guarantee that these values summed to exactly 1.\n\nFor one-vs.-one, we can instead apply a function called *softmax*, which\nassigns decimal probabilities to each class in a multi-class problem such that\nall probabilities add up to 1.0. This additional constraint\nhelps training converge more quickly than it otherwise would.\n\n#### Click the plus icon to see the softmax equation.\n\nThe softmax equation is as follows: \n$$p(y = j\\|\\\\textbf{x}) = \\\\frac{e\\^{(\\\\textbf{w}_j\\^{T}\\\\textbf{x} + b_j)}}{\\\\sum_{k\\\\in K} {e\\^{(\\\\textbf{w}_k\\^{T}\\\\textbf{x} + b_k)}} }$$\n\nNote that this formula basically extends the formula for logistic\nregression into multiple classes.\n\nThe following image re-implements our one-vs.-all multi-class classification\ntask as a one-vs.-one task. Note that in order to perform softmax, the hidden\nlayer directly preceding the output layer (called the softmax layer) must have\nthe same number of nodes as the output layer.\n**Figure 9. Neural net implementation of one-vs.-one classification, using\na softmax layer. Each output value represents the probability that the\ninput image is the specified fruit and not any of the other three fruits\n(all probabilities sum to 1.0). This model predicts that there is a 63%\nchance that the image is a pear.**\n\n### Softmax options\n\nConsider the following variants of softmax:\n\n- **Full softmax** is the softmax we've been discussing; that is,\n softmax calculates a probability for every possible class.\n\n- **Candidate sampling** means that softmax calculates a probability\n for all the positive labels but only for a random sample of\n negative labels. For example, if we are interested in determining\n whether an input image is a beagle or a bloodhound, we don't have to\n provide probabilities for every non-doggy example.\n\nFull softmax is fairly cheap when the number of classes is small\nbut becomes prohibitively expensive when the number of classes climbs.\nCandidate sampling can improve efficiency in problems having a large\nnumber of classes.\n\n### One label versus many labels\n\nSoftmax assumes that each example is a member of exactly one class.\nSome examples, however, can simultaneously be a member of multiple classes.\nFor such examples:\n\n- You may not use softmax.\n- You must rely on multiple logistic regressions.\n\nFor example, the one-vs.-one model in Figure 9 above assumes that each input\nimage will depict exactly one type of fruit: an apple, an orange, a pear, or\na grape. However, if an input image might contain multiple types of fruit---a\nbowl of both apples and oranges---you'll have to use multiple logistic\nregressions instead.\n| **Key terms:**\n|\n| - [Binary classification](/machine-learning/glossary#binary-classification)\n| - [Multi class classification](/machine-learning/glossary#multi-class-classification)\n| - [One-vs.-all classification](/machine-learning/glossary#one-vs.-all)\n- [softmax (one-vs.-one classification)](/machine-learning/glossary#softmax) \n[Help Center](https://support.google.com/machinelearningeducation)"]]