Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosAnonymous Official: I'm begging you to understand this..(20.09.2026 um 21:30 Uhr)
Sichere ProgrammierungHow to Monitor Cron Jobs with a Simple HTTP Health Check(20.09.2026 um 23:14 Uhr)
Sichere ProgrammierungWhy my builds don't run on my laptop(20.09.2026 um 23:15 Uhr)
Sichere ProgrammierungDesigning offline-first when there's no server(20.09.2026 um 23:16 Uhr)
Sichere ProgrammierungSearching for Better Game Recommendations with Jev(20.09.2026 um 23:19 Uhr)
Linux Tipps & HardeningUbuntu 26.10 stops low memory from killing your desktop session(20.09.2026 um 19:55 Uhr)
YouTube Security VideosAnonymous Official: I'm begging you to understand this..(20.09.2026 um 21:30 Uhr)
Sichere ProgrammierungHow to Monitor Cron Jobs with a Simple HTTP Health Check(20.09.2026 um 23:14 Uhr)
Sichere ProgrammierungWhy my builds don't run on my laptop(20.09.2026 um 23:15 Uhr)
Sichere ProgrammierungDesigning offline-first when there's no server(20.09.2026 um 23:16 Uhr)
Sichere ProgrammierungSearching for Better Game Recommendations with Jev(20.09.2026 um 23:19 Uhr)
Linux Tipps & HardeningUbuntu 26.10 stops low memory from killing your desktop session(20.09.2026 um 19:55 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

One Hot Encoding

Reagiere als Erste:r — dein Feedback zählt!

ChatGPT describes the one-hot encoding as following:

One-Hot Encoding is a categorical feature transformation technique used to convert non-numerical labels (like “red”, “blue”, “green”) into numerical binary vectors, so machine-learning models can understand them.

One Hot Encoding

Now the thing with this approach is that what if we have 200s of categorical values, you are not going to create individual 200 columns for each categorical values.

import pandas as pd
import numpy as np

data = pd.read_csv('test.csv', usecols=['X1', 'X2', 'X3', 'X4', 'X5','X6'])
data.head()

This is what this dataset consists

test datasets

Now we don't know what those categories emphasize, and we also don't know how much of those individual unique categorical value exists so let's try to figure out.

for col in data.columns:
   print(col, ": ", len(data[col].unique()), ' labels)

unique categorical values

So we got the count of how much of unique categorical values exists.

Now let's say we convert all those unique categorical values into individual columns then

pd.get_dummies(data, drop_first=True).shape

That would yield (4209, 121) which means would have 121 columns which increases the dimension and that's not what we want.

So let's find top 10 most frequent categories specifically for X2 columns

data.X2.value_counts().sort_values(ascending=False).head(10)

Top 10 most frequent categories

Let's store those each individual top categorical values into index.

top_10 = [x for x in data.X2.value_counts().sort_values(ascending=False).head(10).index]

That would yield
['as', 'ae', 'ai', 'm', 'ak', 'r', 'n', 's', 'f', 'e']

Now let's have binary value that justify existence of categorical values

for label in top_10:
  data[label] = np.where(data['X2']==label, 1, 0)

data[['X2']+top_10].head(20)

Top 20 labels

Let's finalize that into function

def one_hot_top(df, variable, top_x_labels):
  for label in top_x_labels:
    df[variable+'_'+label] = np.where(data[variable]==label, 1, 0)

data = pd.read_csv('test.csv', usecols=['X1', 'X2', 'X3', 'X4', 'X5','X6'])

one_hot_top(data, 'X2', top_10)
data.head()

I have shared my learning here, open for feedback.

Thanks :)

Socials:

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten One Hot Encoding

Thematisch verwandte Begriffe: Encoding · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-93956 | A flaw has been found in olivier-ls PHP-FTS up to 1.1.2. Affected by thi…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick