diff --git a/lightwood/analysis/nc/util.py b/lightwood/analysis/nc/util.py index cac3da651..21bdff41f 100644 --- a/lightwood/analysis/nc/util.py +++ b/lightwood/analysis/nc/util.py @@ -156,13 +156,15 @@ def get_numeric_conf_range( def get_categorical_conf(raw_confs: np.ndarray): """ - Gets ICP confidence estimation for categorical targets from raw p-values per class. + ICP confidence estimation for categorical targets from raw p-values: + 1.0 minus 2nd highest p-value yields confidence for predicted label. :param all_confs: p-value for each class per data point - :return: confidence for each data instance + :return: confidence for each data point """ - # one minus 2nd best p-value yields confidence for predicted label - second_best = np.sort(raw_confs, axis=1)[:, -2] - confs = np.clip(np.subtract(1, second_best), 0.0001, 0.9999) + if len(raw_confs.shape) == 1: + raw_confs = np.expand_dims(raw_confs, axis=0) + second_p = np.sort(raw_confs, axis=1)[:, -2] + confs = np.clip(np.subtract(1, second_p), 0.0001, 0.9999) return confs diff --git a/tests/integration/basic/test_categorical.py b/tests/integration/basic/test_categorical.py index c7aab8047..199bf01fb 100644 --- a/tests/integration/basic/test_categorical.py +++ b/tests/integration/basic/test_categorical.py @@ -54,6 +54,9 @@ def test_1_categorical(self): predictions = predictor.predict(df[:10], args={'all_mixers': True}) assert '__mdb_mixer_Neural' in predictions.columns + # predict single sample + predictor.predict(df.iloc[[0]]) + def test_2_binary_no_analysis(self): df = pd.read_csv('tests/data/ionosphere.csv')[:100] mask = np.random.rand(len(df)) < 0.8