simplify.education

Data representation / feature encoding · BEGINNER LESSON

One-hot encoding

One-hot encoding is a way to represent a category or symbol as a binary vector, with one position set to 1 and the others set to 0. It keeps categories separate without implying that one category is larger or smaller than another.

What it is and what is measured

One-hot encoding turns a discrete item into a set of binary indicators, also called 0/1 features. In medical machine learning, each category of a variable becomes its own binary feature. In DNA sequence representation, each nucleotide can be written as a 4-dimensional binary vector, such as A = [1,0,0,0]. The thing being measured is category identity or symbol identity, not size, order, or amount. This is useful when the original labels are not numerical measurements. [0,1]

[1] Enhancing Model Generalizability in Medical Artificial ... - PMC [2] EDEN: multiscale expected density of nucleotide encoding for ... - PMC

How it works

The mechanism is simple: list all possible categories, then make one binary column for each category. For a given item, put 1 in the column that matches the category and 0 in all other columns. This preserves the nonordinal nature of the original variable, meaning it does not pretend that one label comes before or after another. In sequence data, the same idea keeps exact nucleotide positions while encoding each base separately. [0,1]

[1] Enhancing Model Generalizability in Medical Artificial ... - PMC [2] EDEN: multiscale expected density of nucleotide encoding for ... - PMC

Why it is used

One-hot encoding can help models use categorical information without inventing a fake ranking between categories. In one medical study, it was reported to perform well with certain imbalance-handling methods, and it expanded the number of variables from 83 to 113. In DNA work, it is described as a simple standard representation that preserves exact locations. These are task-specific findings, not universal guarantees. [0,1]

[1] Enhancing Model Generalizability in Medical Artificial ... - PMC [2] EDEN: multiscale expected density of nucleotide encoding for ... - PMC

Limitations

A major limitation is dimensionality growth: when a variable has many unique categories, one-hot encoding can greatly increase the number of features. For very long DNA sequences, the binary vectors can also be memory-intensive because they are sparse, meaning many entries are 0. Another limitation is that, by itself, one-hot encoding gives exact position or category identity but does not automatically add broader context such as neighborhood patterns. [0,1]

[1] Enhancing Model Generalizability in Medical Artificial ... - PMC [2] EDEN: multiscale expected density of nucleotide encoding for ... - PMC

Limits of the evidence

The sources support one-hot encoding as a representation method and show examples in medical classification and DNA sequence encoding. They do not show that one-hot encoding is always best; performance depends on the dataset, model, and task. Reported results are specific to the studied problems. [0,1]

[1] Enhancing Model Generalizability in Medical Artificial ... - PMC [2] EDEN: multiscale expected density of nucleotide encoding for ... - PMC

SEE THE IDEA

How one-hot encoding represents a category

Each step converts identity into a binary pattern without creating an artificial order.

One-hot encoding maps one category to one active position in a binary vector; the rest stay 0.

TRY IT YOURSELF

Test your understanding

Choose an answer, then check the explanation.

0 of 3 questions answered
01 Which vector is a valid one-hot encoding for a four-category system if the third category is present?
02 A dataset has a variable with 60 different labels. What is the main practical drawback of one-hot encoding this variable?
03 A DNA model uses A = [1,0,0,0], C = [0,1,0,0], G = [0,0,1,0], and T = [0,0,0,1]. If a sequence position contains G, what is the encoded vector?

PUT IT TOGETHER

Match each concept to its meaning

Drag a label onto its description, or select a label and then select a description. This also works with a keyboard.

Sources and further reading

This general lesson was generated from public source material. It explains a concept; it does not interpret a private paper or provide medical advice.

  1. Enhancing Model Generalizability in Medical Artificial ... - PMC
  2. EDEN: multiscale expected density of nucleotide encoding for ... - PMC
  3. pmc.ncbi.nlm.nih.gov › articles › PMC13478580A smaller and more efficient one-hot encoding for QUBO - PMC
Apply this to a paper →