-
Notifications
You must be signed in to change notification settings - Fork 127
MTN: improve risk control tests #761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
42b6a73
47199e5
dbc0692
1f6807b
64585e9
4524c69
8e35373
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,13 +19,6 @@ | |||||
|
||||||
random_state = 42 | ||||||
|
||||||
X, y = make_multilabel_classification( | ||||||
n_samples=1000, | ||||||
n_classes=5, | ||||||
random_state=random_state, | ||||||
allow_unlabeled=False | ||||||
) | ||||||
|
||||||
|
||||||
def fpr_func(y_true: NDArray, y_pred: NDArray) -> float: | ||||||
"""Computes false positive rate.""" | ||||||
|
@@ -34,6 +27,11 @@ def fpr_func(y_true: NDArray, y_pred: NDArray) -> float: | |||||
return fp / (tn + fp) | ||||||
|
||||||
|
||||||
dummy_param = np.array([0.5]) | ||||||
dummy_target = 0.9 | ||||||
dummy_X_test = [[0]] | ||||||
|
||||||
|
||||||
def dummy_predict(X): | ||||||
return np.random.rand(1, 2) | ||||||
|
||||||
|
@@ -43,7 +41,7 @@ def bcc_dummy(): | |||||
return BinaryClassificationController( | ||||||
predict_function=dummy_predict, | ||||||
risk=precision, | ||||||
target_level=0.9, | ||||||
target_level=dummy_target, | ||||||
) | ||||||
|
||||||
# The following test is voluntarily agnostic | ||||||
|
@@ -107,7 +105,7 @@ def test_auto( | |||||
controller = BinaryClassificationController( | ||||||
predict_function=dummy_predict, | ||||||
risk=risk_instance, | ||||||
target_level=0.8, | ||||||
target_level=dummy_target, | ||||||
best_predict_param_choice="auto" | ||||||
) | ||||||
|
||||||
|
@@ -121,7 +119,7 @@ def test_custom(self): | |||||
controller = BinaryClassificationController( | ||||||
predict_function=dummy_predict, | ||||||
risk=precision, | ||||||
target_level=0.8, | ||||||
target_level=dummy_target, | ||||||
best_predict_param_choice=custom_risk | ||||||
) | ||||||
|
||||||
|
@@ -136,7 +134,7 @@ def test_auto_unknown_risk(self): | |||||
BinaryClassificationController( | ||||||
predict_function=dummy_predict, | ||||||
risk=unknown_risk, | ||||||
target_level=0.8, | ||||||
target_level=dummy_target, | ||||||
best_predict_param_choice="auto" | ||||||
) | ||||||
|
||||||
|
@@ -199,15 +197,14 @@ def test_only_one_param(self, best_predict_param_choice): | |||||
controller = BinaryClassificationController( | ||||||
predict_function=dummy_predict, | ||||||
risk=precision, | ||||||
target_level=0.9, | ||||||
target_level=dummy_target, | ||||||
best_predict_param_choice=best_predict_param_choice | ||||||
) | ||||||
|
||||||
dummy_param = 0.5 | ||||||
y_calibrate = np.array([1, 0]) | ||||||
|
||||||
dummy_predictions = np.array([[True, False]]) | ||||||
valid_params_index = [0] | ||||||
controller.valid_predict_params = np.array([dummy_param]) | ||||||
controller.valid_predict_params = dummy_param | ||||||
|
||||||
|
||||||
controller._set_best_predict_param( | ||||||
y_calibrate_=y_calibrate, | ||||||
|
@@ -222,13 +219,10 @@ def test_only_one_param(self, best_predict_param_choice): | |||||
[[precision, 0.5], [recall, 0.7]] | ||||||
) | ||||||
def test_correct_param_out_of_two(self, best_predict_param_choice, expected): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding this test, maybe we can stick to numerical values everywhere (for param and target)? (the dummy_param and dummy_param_2 were misnamed). My point: here we actually care about the param value. In other words, if we change the dummy param/target values, the test may break. |
||||||
dummy_param = 0.5 | ||||||
dummy_param_2 = 0.7 | ||||||
|
||||||
controller = BinaryClassificationController( | ||||||
predict_function=dummy_predict, | ||||||
risk=precision, | ||||||
target_level=0.9, | ||||||
target_level=dummy_target, | ||||||
best_predict_param_choice=best_predict_param_choice | ||||||
) | ||||||
|
||||||
|
@@ -242,8 +236,7 @@ def test_correct_param_out_of_two(self, best_predict_param_choice, expected): | |||||
valid_params_index = [0, 1] | ||||||
|
||||||
controller.valid_predict_params = np.array( | ||||||
[dummy_param, dummy_param_2] | ||||||
) | ||||||
[dummy_param, dummy_param + 0.2]) | ||||||
|
[dummy_param, dummy_param + 0.2]) | |
[dummy_param[0], dummy_param[0] + 0.2]) |
Copilot uses AI. Check for mistakes.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as in line 218. The assignment should be np.array([dummy_param])
to maintain consistency with the expected array type, or dummy_param
should be defined as a scalar if that's the intended usage pattern.
Copilot uses AI. Check for mistakes.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure about using dummy_param
here, as it is not obvious that it is a singleton (and that's the point of the test). Maybe we can create a single_param
constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be renamed
dummy_X
for a more generic use?