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

how to add weight for r2_score? #564

Open
RainFung opened this issue Nov 25, 2024 · 1 comment
Open

how to add weight for r2_score? #564

RainFung opened this issue Nov 25, 2024 · 1 comment
Assignees
Labels
help wanted Extra attention is needed

Comments

@RainFung
Copy link

from sklearn.metrics import r2_score  
class R2Score(Metric):  
    def __init__(self):  
        self._name = "r2"  
        self._maximize = True  

    def __call__(self, y_true, y_pred):  
        return r2_score(y_true, y_pred)

how can i add weight for r2_score

@RainFung RainFung added the enhancement New feature or request label Nov 25, 2024
@Optimox
Copy link
Collaborator

Optimox commented Nov 26, 2024

Hello, if the weights you want to apply are based on the labels you could simply do something like that:

from sklearn.metrics import r2_score  
class R2Score(Metric):  
    def __init__(self):  
        self._name = "r2"  
        self._maximize = True  

    def __call__(self, y_true, y_pred):  
        weights_example=y_true**2
        return r2_score(y_true, y_pred, sample_weight=weights_example)

if the weights are just external weights then you won't be able to easily access them inside tabnet .fit unfortunately. You can still monitor a proxy r2_score without weights during training and compute your out of fold weighted r2_score at the end of each fold.

@Optimox Optimox added help wanted Extra attention is needed and removed enhancement New feature or request labels Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants