Skip to content

Commit

Permalink
fix: add test for single-sample categorical prediction and fix bug in…
Browse files Browse the repository at this point in the history
… get_categorical_conf()
  • Loading branch information
paxcema committed Dec 27, 2021
1 parent 137f746 commit ffa88a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lightwood/analysis/nc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 3 additions & 0 deletions tests/integration/basic/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffa88a5

Please sign in to comment.