def validate_score_metric_for_number_of_classes(self, metric): """ Check that a user's choice of scoring metric makes sense with the number of prediction classes Args: metric (str): a string of the scoring metric """ # TODO test this for errors and multiclass # TODO make this more robust for other scoring metrics classes = hcai_helpers.count_unique_elements_in_column(self.dataframe, self.predicted_column) if classes is 2: # return True for testing return True elif classes > 2 and metric in ['pr_auc', 'roc_auc']: raise (HealthcareAIError('AUC (aka roc_auc) cannot be used for more than two classes. Please choose another' ' metric such as \'accuracy\''))
def test_class_counter_on_many(self): df = hcai_datasets.load_diabetes() result = count_unique_elements_in_column(df, 'PatientEncounterID') self.assertEqual(result, 1000)
def test_class_counter_on_binary(self): df = hcai_datasets.load_diabetes() df.dropna(axis=0, how='any', inplace=True) result = count_unique_elements_in_column(df, 'ThirtyDayReadmitFLG') self.assertEqual(result, 2)