Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mcgrad/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ def calibration_free_normalized_entropy(
:param max_iter: Maximum number of iterations for the calibration adjustment. Defaults to 10000.
:return: the calibration-free NE.
"""
if len(labels.shape) != 1:
if len(predicted_scores.shape) != 1:
raise ValueError("y_pred must be the predicted probability for class 1 only.")

current_calibration = calibration_ratio(labels, predicted_scores, sample_weight)
Expand Down
20 changes: 20 additions & 0 deletions src/mcgrad/tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,26 @@ def test_calibration_free_normalized_entropy_higher_for_reversed_predictions():
assert result_bad > result_good


def test_calibration_free_normalized_entropy_rejects_2d_predictions():
labels = np.array([0, 1, 0, 1])
predictions_2d = np.array([[0.2, 0.8], [0.7, 0.3], [0.1, 0.9], [0.6, 0.4]])

with pytest.raises(ValueError, match="y_pred must be the predicted probability"):
metrics.calibration_free_normalized_entropy(
labels=labels, predicted_scores=predictions_2d
)


def test_calibration_free_normalized_entropy_accepts_1d_labels():
labels = np.array([0, 1, 0, 1])
predictions = np.array([0.2, 0.8, 0.3, 0.7])

result = metrics.calibration_free_normalized_entropy(
labels=labels, predicted_scores=predictions
)
assert isinstance(result, (float, np.floating))


def test_rank_calibration_error_zero_for_perfect_ranking():
labels = np.array([0.0, 0.2, 0.4, 0.6, 0.8, 1.0])
perfect_predictions = labels * 2.0
Expand Down
Loading