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

FIX: errors in Ensemble while using custom_metric(use df.values to change dataframe to numpy array) #647

Closed
wants to merge 1 commit into from

Conversation

Ldoun
Copy link

@Ldoun Ldoun commented Aug 25, 2023

def custom_metric(y_true, y_predicted, sample_weight=None):
    v = 2 * abs(y_predicted - y_true) / ((abs(y_predicted) + abs(y_true)) + 1e-9)
    output = np.mean(v) * 100
    return output

automl = AutoML(mode=args.mode, algorithms=alg, eval_metric=custom_metric)

During Our project, we computed models using custom_eval_metric and met errors in Ensemble and Stacking Ensemble.
The problem was that in the ensemble step, the custom metric had an input type of DataFrame, not a numpy array.
So my pull request fixed this issue by just giving numpy array as input in the Ensemble step.

To other users who want to use this feature can code your function like the below

def custom_metric(y_true, y_predicted, sample_weight=None):
    if isinstance(y_true, pd.DataFrame):
        y_true = y_true.values
        y_predicted = y_predicted.values
        
    v = 2 * abs(y_predicted - y_true) / ((abs(y_predicted) + abs(y_true)) + 1e-9)
    output = np.mean(v) * 100
    return output

@Ldoun Ldoun changed the title fix: use df.values to change dataframe to numpy array FIX: errors in Ensemble while using custom_metric(use df.values to change dataframe to numpy array) Aug 25, 2023
@hoon-bari
Copy link

👍🏻

@pplonski
Copy link
Contributor

Not sure if this is needed. As you wrote, you can handle it by providing check in custom_metric() function.

@pplonski pplonski closed this Aug 28, 2023
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.

None yet

3 participants