Search code examples
pythonpython-3.xfunctionscikit-learnkeyword-argument

Redefine a function from an existing by specifying one keyword argument


I want to create a dictionary with string keys and some existing functions as corresponding values.

For example:

import numpy as np
my_useful_funtions_dicts = {'sum': np.sum, 'dot': np.dot}

This works great. But I wanted to use a function from scikit learn and specifying a keyword argument. For example using sklearn.metrics.roc_auc_score(*args, average='weighted')

I would like to run smtg like this :

from sklearn import metrics
my_dict = {'weighted_roc_auc': metrics.roc_auc_score(*args, average='weighted')}

Solution

  • my_dict = {'weighted_auc_roc_score': lambda true, pred: metrics.roc_auc_score(true, pred, average="weighted")}