{"record":{"id":"2abcaa34f0c0b841","repo":"FoundationAgents/MetaGPT","slug":"number-of-classes-num-classes-not-supported","errorCode":null,"errorMessage":"Number of classes {num_classes} not supported","messagePattern":"Number of classes (.+?) not supported","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/ext/sela/data/dataset.py","lineNumber":278,"sourceCode":"            \"metadata\": metadata,\n            \"df_head\": df_head_text,\n        }\n        return dataset_info\n\n    def get_df_head(self, raw_df):\n        return raw_df.head().to_string(index=False)\n\n    def get_metric(self):\n        dataset_info = self.get_dataset_info()\n        num_classes = dataset_info[\"metadata\"][\"NumberOfClasses\"]\n        if num_classes == 2:\n            metric = \"f1 binary\"\n        elif 2 < num_classes <= 200:\n            metric = \"f1 weighted\"\n        elif num_classes > 200 or num_classes == 0:\n            metric = \"rmse\"\n        else:\n            raise ValueError(f\"Number of classes {num_classes} not supported\")\n        return metric\n\n    def create_base_requirement(self):\n        metric = self.get_metric()\n        req = BASE_USER_REQUIREMENT.format(datasetname=self.name, target_col=self.target_col, metric=metric)\n        return req\n\n    def save_dataset(self, target_col):\n        df, test_df = self.get_raw_dataset()\n        if not self.check_dataset_exists() or self.force_update:\n            print(f\"Saving Dataset {self.name} in {self.dataset_dir}\")\n            self.split_and_save(df, target_col, test_df=test_df)\n        else:\n            print(f\"Dataset {self.name} already exists\")\n        if not self.check_datasetinfo_exists() or self.force_update:\n            print(f\"Saving Dataset info for {self.name}\")\n            dataset_info = self.get_dataset_info()\n            self.save_datasetinfo(dataset_info)","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/ext/sela/data/dataset.py#L260-L296","documentation":"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.","triggerScenarios":"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.","commonSituations":"Incorrect target_col configured in datasets.yaml; degenerate dataset; target column that is constant due to an upstream preprocessing bug.","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"],"exampleFix":"df = pd.read_csv(raw_path)\nassert df[target_col].nunique() != 1, \"target column is constant\"","handlingStrategy":"validation","validationCode":"n = df[target_col].nunique()\nassert n != 1, \"constant target column\"","typeGuard":"def is_usable_target(df, target_col) -> bool:\n    return target_col in df.columns and df[target_col].nunique() != 1","tryCatchPattern":null,"preventionTips":["Verify target_col has >= 2 distinct values before dataset setup","Double-check target_col spelling in datasets.yaml"],"tags":["sela","dataset","metric","validation"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}