scikit-learn
scikit-learn.org › stable › modules › generated › sklearn.preprocessing.LabelEncoder.html
LabelEncoder — scikit-learn 1.9.1 documentation
Encode categorical features as a one-hot numeric array. Examples · LabelEncoder can be used to normalize labels. >>> from sklearn.preprocessing import LabelEncoder >>> le = LabelEncoder() >>> le.fit([1, 2, 2, 6]) LabelEncoder() >>> le.classes_ array([1, 2, 6]) >>> le.transform([1, 1, 2, 6]) array([0, 0, 1, 2]...) >>> le.inverse_transform([0, 0, 1, 2]) array([1, 1, 2, 6]) It can also be used to transform non-numerical labels (as long as they are hashable and comparable) to numerical labels.
09:03
One Hot Encoder with Python Machine Learning (Scikit-Learn) - YouTube
08:28
Label Encoding in Python | Machine Learning | Label Encoder Sklearn ...
06:19
Ordinal Encoder with Python Machine Learning (Scikit-Learn) - YouTube
One Hot Encoder with Python Machine Learning (Scikit-Learn)
10:45
Data Preprocessing 06: One Hot Encoding python | Scikit Learn | ...
scikit-learn
scikit-learn.org › stable › modules › generated › sklearn.preprocessing.TargetEncoder.html
TargetEncoder — scikit-learn 1.9.1 documentation
The target is first binarized using the “one-vs-all” scheme via LabelBinarizer, then the average target value for each class and each category is used for encoding, resulting in n_features * n_classes encoded output features.
Scikit-learn
contrib.scikit-learn.org › category_encoders
Category Encoders — Category Encoders 2.11.1 documentation
Can explicitly configure which columns in the data are encoded by name or index, or infer non-numeric columns regardless of input type · Can drop any columns with very low variance based on training set optionally · Portability: train a transformer on data, pickle it, reuse it later and get the same thing out. Full compatibility with sklearn pipelines, input an array-like dataset like any other transformer (*)
APXML
apxml.com › courses › getting-started-with-scikit-learn › chapter-4-data-preprocessing-feature-engineering › applying-encoders
Applying Encoders in Scikit-learn
One-Hot Encoding is suitable when the categorical features do not have an inherent order. It transforms each category into a new binary feature (0 or 1). Scikit-learn's OneHotEncoder is the primary tool for this task. Let's examine a simple dataset with a categorical feature: import pandas as pd from sklearn.preprocessing import OneHotEncoder # Sample data data = pd.DataFrame({'color': ['Red', 'Green', 'Blue', 'Green'], 'size': ['M', 'L', 'S', 'M']}) print("Original Data:") print(data) # Select the categorical column(s) to encode categorical_features = ['color'] # Let's encode 'color' first
Medium
medium.com › @prathik.codes › labelencoder-in-scikit-learn-c1b7bccec412
LabelEncoder in scikit-learn. ML Quickies #24 | by Prathik C | Medium
October 9, 2025 - from sklearn.preprocessing import LabelEncoder # Example categorical labels y = ["cat", "dog", "cat", "bird"] # Create and fit the encoder le = LabelEncoder() y_encoded = le.fit_transform(y) print("Encoded labels:", y_encoded) Output: Encoded labels: [1 2 1 0] After fitting, LabelEncoder stores the unique categories it has seen in the .classes_ attribute, sorted alphabetically.
scikit-learn
scikit-learn.org › dev › modules › generated › sklearn.preprocessing.LabelEncoder.html
LabelEncoder — scikit-learn 1.10.dev0 documentation
Encode categorical features as a one-hot numeric array. Examples · LabelEncoder can be used to normalize labels. >>> from sklearn.preprocessing import LabelEncoder >>> le = LabelEncoder() >>> le.fit([1, 2, 2, 6]) LabelEncoder() >>> le.classes_ array([1, 2, 6]) >>> le.transform([1, 1, 2, 6]) array([0, 0, 1, 2]...) >>> le.inverse_transform([0, 0, 1, 2]) array([1, 1, 2, 6]) It can also be used to transform non-numerical labels (as long as they are hashable and comparable) to numerical labels.
Scikit-learn course
inria.github.io › scikit-learn-mooc › python_scripts › 03_categorical_pipeline.html
Encoding of categorical variables — Scikit-learn course
We can encode a single feature (e.g. "education") to illustrate how the encoding works. from sklearn.preprocessing import OneHotEncoder encoder = OneHotEncoder(sparse_output=False).set_output(transform="pandas") education_encoded = encoder.fit_transform(education_column) education_encoded
scikit-learn
scikit-learn.org › 1.1 › modules › generated › sklearn.preprocessing.LabelEncoder.html
sklearn.preprocessing.LabelEncoder — scikit-learn 1.1.3 documentation
Encode target labels with value between 0 and n_classes-1.
scikit-learn
scikit-learn.org › stable › auto_examples › preprocessing › plot_target_encoder.html
Comparing Target Encoder with Other Encoders — scikit-learn 1.9.1 documentation
First, we list out the encoders we will be using to preprocess the categorical features: from sklearn.compose import ColumnTransformer from sklearn.preprocessing import OneHotEncoder, OrdinalEncoder, TargetEncoder categorical_preprocessors = [ ("drop", "drop"), ("ordinal", OrdinalEncoder(handle_unknown="use_encoded_value", unknown_value=-1)), ( "one_hot", OneHotEncoder(handle_unknown="ignore", max_categories=20, sparse_output=False), ), ("target", TargetEncoder(target_type="continuous")), ]
GitHub
github.com › scikit-learn › scikit-learn › blob › cc50648cc › sklearn › preprocessing › _encoders.py
scikit-learn/sklearn/preprocessing/_encoders.py at cc50648cc1b759b53a4edbce0f3bb6c237349448 · scikit-learn/scikit-learn
values per feature and transform the data to a binary one-hot encoding. · >>> from sklearn.preprocessing import OneHotEncoder · · One can discard categories not seen during `fit`: ·
Author: scikit-learn
Scikit-learn
contrib.scikit-learn.org › category_encoders › targetencoder.html
Target Encoder — Category Encoders 2.11.1 documentation
Target encoding for categorical features.