Repository: cleanlab/cleanlab

Issue:
update datalab.get_issues("class_imbalance") to include the label of each example
This dataframe here should indicate the class label of each example

![Screen Shot 2023-12-15 at 7 54 12 PM](https://github.com/cleanlab/cleanlab/assets/1390638/23051dd3-83d6-48f0-bcfd-c9da9ad6dd25)

Also `datalab.report()` should be updated so that:

![Screen Shot 2023-12-15 at 7 55 10 PM](https://github.com/cleanlab/cleanlab/assets/1390638/8e4fc46e-e56b-4e98-a4c5-fbc52dfe5581)

Contains an extra line:

> About this issue:
>        Examples belonging to the most under-represented class in the dataset (class: <name_of_class>)


Discussion:

Resolving patch:
diff --git a/cleanlab/datalab/internal/data_issues.py b/cleanlab/datalab/internal/data_issues.py
--- a/cleanlab/datalab/internal/data_issues.py
+++ b/cleanlab/datalab/internal/data_issues.py
@@ -110,7 +110,7 @@ def get_info(
     ) -> Dict[str, Any]:
         info_extracted = _InfoStrategy._get_info_helper(info=info, issue_name=issue_name)
         info = info_extracted if info_extracted is not None else info
-        if issue_name == "label":
+        if issue_name in ["label", "class_imbalance"]:
             if data.labels.is_available is False:
                 raise ValueError(
                     "The labels are not available. "
@@ -236,9 +236,7 @@ def get_issues(self, issue_name: Optional[str] = None) -> pd.DataFrame:
             specific_issues = specific_issues.assign(**column_dict)
 
         if issue_name == "class_imbalance":
-            specific_issues = specific_issues.assign(
-                class_imbalance_class_name=info["Rarest Class"]
-            )
+            specific_issues = specific_issues.assign(given_label=info["given_label"])
         return specific_issues
 
     def get_issue_summary(self, issue_name: Optional[str] = None) -> pd.DataFrame:
diff --git a/cleanlab/datalab/internal/issue_manager/imbalance.py b/cleanlab/datalab/internal/issue_manager/imbalance.py
--- a/cleanlab/datalab/internal/issue_manager/imbalance.py
+++ b/cleanlab/datalab/internal/issue_manager/imbalance.py
@@ -75,9 +75,13 @@ def find_issues(
             },
         )
         self.summary = self.make_summary(score=class_probs[rarest_class_idx])
-        self.info = self.collect_info(class_name=rarest_class_name)
+        self.info = self.collect_info(class_name=rarest_class_name, labels=labels)
 
-    def collect_info(self, class_name: str) -> dict:
-        params_dict = {"threshold": self.threshold, "Rarest Class": class_name}
+    def collect_info(self, class_name: str, labels: np.ndarray) -> dict:
+        params_dict = {
+            "threshold": self.threshold,
+            "Rarest Class": class_name,
+            "given_label": labels,
+        }
         info_dict = {**params_dict}
         return info_dict


Test patch:
diff --git a/tests/datalab/test_datalab.py b/tests/datalab/test_datalab.py
--- a/tests/datalab/test_datalab.py
+++ b/tests/datalab/test_datalab.py
@@ -177,7 +177,7 @@ def test_get_issues(self, lab, monkeypatch):
                     "distance_to_nearest_neighbor": mock_distance_to_nearest_neighbor,
                 },
                 "class_imbalance": {
-                    "Rarest Class": "class_0",
+                    "given_label": lab.labels,
                 },
             }
         )
@@ -217,7 +217,7 @@ def test_get_issues(self, lab, monkeypatch):
                     key: mock_issues[key]
                     for key in ["is_class_imbalance_issue", "class_imbalance_score"]
                 },
-                "class_imbalance_class_name": ["class_0"] * 5,
+                "given_label": [4, 4, 5, 3, 5],
             },
         )
         pd.testing.assert_frame_equal(