4
$\begingroup$

If we have 5 classes and 3 inputs, let's say [C1, C2, C3, C4, C5] and [X1, X2, X3] then,

  • If X1 belongs to the C4 class then the hot encoder for this will be [0, 0, 0, 1, 0].

  • If X1 belongs to the C2 class then the hot encoder for this will be [0, 1, 0, 0, 0].

How can I mathematically represent it?

I've also seen math-oriented people refer to a one-hot vector using an indicator function, but I am unable to understand this:

$$ 1_A(x) := \begin{cases} 1 & \text{if}\ x \in A, \\ 0 & \text{if}\ x \notin A. \end{cases} $$

Can anyone explain this above scenario to me?

$\endgroup$
0

2 Answers 2

4
$\begingroup$

$A$ is a set. If $x$ is an element of $A$, return $1$. Else return $0$. Thus $A$ is the set of cases that you are assigning a $1$ to in your encoding vector. Thus one-hot encoding is a vector form of this indicator function that applies componentwise.

$\endgroup$
1
  • $\begingroup$ I know this, but how can this one will be assigned to the index in set A? just like If C4 is in X1 class then the index of one will be the 4 and rest will be zero, how this is being happening there? $\endgroup$ Commented Mar 14, 2022 at 6:24
0
$\begingroup$

The mathematical representation of one-hot encoding can indeed be done using indicator functions. An indicator function is a mathematical function that takes a value and returns 1 if the value satisfies a certain condition (belongs to a particular set), and 0 if it doesn't satisfy the condition.

C={C1​,C2​,C3​,C4​,C5​}, and you want to encode an input XX as a one-hot vector. You can define indicator functions for each category:

For category CiCi​, the indicator function 1Ci(X)1Ci​​(X) is defined as: {1if X=Ci0otherwise {10​if X=Ci​otherwise​

In this definition, 1Ci(X)1Ci​​(X) is 1 if XX belongs to category CiCi​, and 0 otherwise. Essentially, it's a function that acts as a "switch" to turn on (1) or off (0) for each category based on whether XX belongs to that category.

So, for your examples:

If X1X1​ belongs to the C4C4​ class, the one-hot encoding can be represented as:
1C1(X1)=0, 1C2(X1)=0, 1C3(X1)=0, 1C4(X1)=1, 1C5(X1)=01C1​​(X1​)=0,1C2​​(X1​)=0,1C3​​(X1​)=0,1C4​​(X1​)=1,1C5​​(X1​)=0

If X1X1​ belongs to the C2C2​ class, the one-hot encoding can be represented as:
1C1(X1)=0, 1C2(X1)=1, 1C3(X1)=0, 1C4(X1)=0, 1C5(X1)=01C1​​(X1​)=0,1C2​​(X1​)=1,1C3​​(X1​)=0,1C4​​(X1​)=0,1C5​​(X1​)=0
$\endgroup$
1
  • 1
    $\begingroup$ This answer would be easier to read and understand with math typesetting, and you would be more likely to receive upvotes. More information: math.meta.stackexchange.com/questions/5020/… $\endgroup$
    – Sycorax
    Commented Oct 14, 2023 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.