FoundationAgents/MetaGPT · error · ValueError
Number of classes {num_classes} not supported
Error message
Number of classes {num_classes} not supported What it means
Raised by ExpDataset.get_metric when the number of unique values in the target column (NumberOfClasses) does not map to a supported metric: 2 -> 'f1 binary', 2<n<=200 -> 'f1 weighted', >200 or 0 -> 'rmse'. The only remaining case, num_classes == 1, raises — a single-class target is neither a classification nor a regression target.
Source
Thrown at metagpt/ext/sela/data/dataset.py:278
"metadata": metadata,
"df_head": df_head_text,
}
return dataset_info
def get_df_head(self, raw_df):
return raw_df.head().to_string(index=False)
def get_metric(self):
dataset_info = self.get_dataset_info()
num_classes = dataset_info["metadata"]["NumberOfClasses"]
if num_classes == 2:
metric = "f1 binary"
elif 2 < num_classes <= 200:
metric = "f1 weighted"
elif num_classes > 200 or num_classes == 0:
metric = "rmse"
else:
raise ValueError(f"Number of classes {num_classes} not supported")
return metric
def create_base_requirement(self):
metric = self.get_metric()
req = BASE_USER_REQUIREMENT.format(datasetname=self.name, target_col=self.target_col, metric=metric)
return req
def save_dataset(self, target_col):
df, test_df = self.get_raw_dataset()
if not self.check_dataset_exists() or self.force_update:
print(f"Saving Dataset {self.name} in {self.dataset_dir}")
self.split_and_save(df, target_col, test_df=test_df)
else:
print(f"Dataset {self.name} already exists")
if not self.check_datasetinfo_exists() or self.force_update:
print(f"Saving Dataset info for {self.name}")
dataset_info = self.get_dataset_info()
self.save_datasetinfo(dataset_info)View on GitHub (pinned to 11cdf466d0)
Solutions
- Check nunique() of the configured target column in raw/train.csv and correct target_col if it is wrong
- If the dataset truly has one class, it is unusable for this pipeline — pick another target or dataset
- For regression targets with few distinct values, consider that <=200 unique values will be treated as classification
Example fix
df = pd.read_csv(raw_path) assert df[target_col].nunique() != 1, "target column is constant"
Defensive patterns
Strategy: validation
Validate before calling
n = df[target_col].nunique() assert n != 1, "constant target column"
Type guard
def is_usable_target(df, target_col) -> bool:
return target_col in df.columns and df[target_col].nunique() != 1 Prevention
- Verify target_col has >= 2 distinct values before dataset setup
- Double-check target_col spelling in datasets.yaml
When it happens
Trigger: The target column of raw/train.csv has exactly one unique value, e.g. a constant label, wrong column selected as target_col, or an id/constant column mistaken for the target.
Common situations: Incorrect target_col configured in datasets.yaml; degenerate dataset; target column that is constant due to an upstream preprocessing bug.
Related errors
- Dataset {dataset_name} not found in config file. Available d
- Dataset {task_name} not found in config file. Available data
- Target column not provided
- Unsupported dataset: {dataset}
- Raw dataset `train.csv` not found in {raw_dir}
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/2abcaa34f0c0b841.
Report an issue: GitHub.