From d29f88f55d05388cb151ae0081e111a3ff5b5377 Mon Sep 17 00:00:00 2001 From: Ysobel Date: Fri, 31 Jul 2026 10:21:14 +1000 Subject: [PATCH] Allow non integer categories --- ecosci/data/preprocessing.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ecosci/data/preprocessing.py b/ecosci/data/preprocessing.py index 350cfea..2f81599 100755 --- a/ecosci/data/preprocessing.py +++ b/ecosci/data/preprocessing.py @@ -111,15 +111,13 @@ def encode_labels(y, labels: List[str], problem_type: str = "classification"): """ from sklearn.preprocessing import LabelEncoder import numpy as np - import pandas as pd - from pandas.api.types import is_numeric_dtype - + label_encoders = {} label_classes_dict = {} if len(labels) == 1: # Single output: maintain backward compatibility - if problem_type == "classification" and not is_numeric_dtype(y): + if problem_type == "classification": label_encoder = LabelEncoder() y_encoded = label_encoder.fit_transform(y) label_encoders[labels[0]] = label_encoder @@ -131,7 +129,7 @@ def encode_labels(y, labels: List[str], problem_type: str = "classification"): # Multi-output: encode each column separately y_encoded = [] for col in labels: - if problem_type == "classification" and not is_numeric_dtype(y[col]): + if problem_type == "classification": label_encoder = LabelEncoder() y_col_encoded = label_encoder.fit_transform(y[col]) label_encoders[col] = label_encoder