Hinge loss issue
Closed this issue · 1 comments
Hinge loss does not seem to work unless y_cal is re-indexed from zero.
alphas_cal = hinge(model.predict_proba(X_cal), model.classes_, y_cal)
KeyError: 0
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
in <cell line: 1>()
----> 1 alphas_cal = hinge(model.predict_proba(X_cal), model.classes_, y_cal)
/usr/local/lib/python3.10/dist-packages/crepes/extras.py in hinge(X_prob, classes, y)
69 if y is not None:
70 class_indexes = np.array(
---> 71 [np.argwhere(classes == y[i])[0][0] for i in range(len(y))])
72 result = 1-X_prob[np.arange(len(y)),class_indexes]
73 else:
/usr/local/lib/python3.10/dist-packages/crepes/extras.py in (.0)
69 if y is not None:
70 class_indexes = np.array(
---> 71 [np.argwhere(classes == y[i])[0][0] for i in range(len(y))])
72 result = 1-X_prob[np.arange(len(y)),class_indexes]
73 else:
/usr/local/lib/python3.10/dist-packages/pandas/core/series.py in getitem(self, key)
1005
1006 elif key_is_scalar:
-> 1007 return self._get_value(key)
1008
1009 if is_hashable(key):
/usr/local/lib/python3.10/dist-packages/pandas/core/series.py in _get_value(self, label, takeable)
1114
1115 # Similar to Index.get_value, but we do not fall back to positional
-> 1116 loc = self.index.get_loc(label)
1117
1118 if is_integer(loc):
/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py in get_loc(self, key)
3653 return self._engine.get_loc(casted_key)
3654 except KeyError as err:
-> 3655 raise KeyError(key) from err
3656 except TypeError:
3657 # If we have a listlike key, _check_indexing_error will raise
KeyError: 0
Thanks for pointing this out; it seems to be due that the label vector is a pandas.series and not a NumPy array, which causes a problem with (integer) indexing. This has been fixed in the just released v. 0.7.0.
Best regards,
Henrik