Skip to content
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

training: fixed EarlyStopping._calc_new_threshold to account for negative scores #1065

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MaxBalmus
Copy link

This fix is meant to account for training models with potentially negative scores as we see in the case of cost functions based on the log likelihood. The current fix ensures that abs_threshold_change is always positive, guaranteeing the intended monotonicity of the threshold.

@BenjaminBossan
Copy link
Collaborator

Thanks for creating this PR. Just to ensure that I got things right: Let's assume we have a negative score, say, -10, and a threshold of 0.1. Then, with the current code, we would have:

abs_threshold_change = self.threshold * score = -1

Then, for lower_is_better = True, we would have new_threshold = score - abs_threshold_change = score - -1 = score + 1. However, we want score - 1 (vice versa forlower_is_better = False) . Is my understanding correct?

Ideally, we could have a unit test for this. I would need to be a bit tricky. Maybe we can create a custom scoring function that just returns from a list of predefined negative scores, and set the monitor value to that scoring function. WDYT?

@MaxBalmus
Copy link
Author

Yes, you described the issue exactly as I see it.

Regarding the test: I am not as familiar with code, but I think I follow what you mean and I think it should work.

@BenjaminBossan
Copy link
Collaborator

BenjaminBossan commented Sep 6, 2024

Yes, you described the issue exactly as I see it.

Great, thanks for confirming.

Regarding the test: I am not as familiar with code, but I think I follow what you mean and I think it should work.

Would you be interested in giving it a try? The tests reside here:

class TestEarlyStopping:

If not, it's fine too, just let me know.

@MaxBalmus
Copy link
Author

Sure, I will give it a go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants