"""
Appends new scorers in to the SCORERS constant.
"""

from sklearn.metrics import SCORERS
from sklearn.metrics import make_scorer
from imblearn.metrics import geometric_mean_score
from ..metrics.classification import tp_score, tn_score, fp_score, fn_score
from ..metrics.regression import weighted_mean_squared_error

__all__ = [
    'geometric_mean_score', 'tp_score', 'tn_score', 'fp_score', 'fn_score',
    'weighted_mean_squared_error', 'SCORERS'
]

APPENDED_SCORERS = {
    'tp': (tp_score, ),
    'tn': (tn_score, ),
    'fp': (fp_score, False),
    'fn': (fn_score, False),
    'geometric_mean_score': (geometric_mean_score, ),
    'weighted_mean_squared_error': (weighted_mean_squared_error, )
}

APPENDED_SCORERS = {
    name: make_scorer(*sc_func)
    for name, sc_func in APPENDED_SCORERS.items()
}

SCORERS.update(APPENDED_SCORERS)
Beispiel #2
0
_scorers = {
    'f1_score_micro':
    make_scorer(f1_score, average='micro', pos_label=None),
    'f1_score_macro':
    make_scorer(f1_score, average='macro', pos_label=None),
    'f1_score_weighted':
    make_scorer(f1_score, average='weighted', pos_label=None),
    'f1_score_least_frequent':
    make_scorer(f1_score_least_frequent),
    'pearson':
    make_scorer(pearson),
    'spearman':
    make_scorer(spearman),
    'kendall_tau':
    make_scorer(kendall_tau),
    'unweighted_kappa':
    make_scorer(kappa),
    'quadratic_weighted_kappa':
    make_scorer(kappa, weights='quadratic'),
    'linear_weighted_kappa':
    make_scorer(kappa, weights='linear'),
    'qwk_off_by_one':
    make_scorer(kappa, weights='quadratic', allow_off_by_one=True),
    'lwk_off_by_one':
    make_scorer(kappa, weights='linear', allow_off_by_one=True),
    'uwk_off_by_one':
    make_scorer(kappa, allow_off_by_one=True)
}

SCORERS.update(_scorers)
Beispiel #3
0
from .version import __version__, VERSION


__all__ = ['Learner', 'load_examples', 'kappa', 'kendall_tau', 'spearman',
           'pearson', 'f1_score_least_frequent', 'run_configuration',
           'run_ablation', 'write_feature_file', 'convert_examples']

# Add our scorers to the sklearn dictionary here so that they will always be
# available if you import anything from skll
_scorers = {'f1_score_micro': make_scorer(f1_score, average='micro',
                                          pos_label=None),
            'f1_score_macro': make_scorer(f1_score, average='macro',
                                          pos_label=None),
            'f1_score_weighted': make_scorer(f1_score, average='weighted',
                                             pos_label=None),
            'f1_score_least_frequent': make_scorer(f1_score_least_frequent),
            'pearson': make_scorer(pearson),
            'spearman': make_scorer(spearman),
            'kendall_tau': make_scorer(kendall_tau),
            'unweighted_kappa': make_scorer(kappa),
            'quadratic_weighted_kappa': make_scorer(kappa,
                                                    weights='quadratic'),
            'linear_weighted_kappa': make_scorer(kappa, weights='linear'),
            'qwk_off_by_one': make_scorer(kappa, weights='quadratic',
                                          allow_off_by_one=True),
            'lwk_off_by_one': make_scorer(kappa, weights='linear',
                                          allow_off_by_one=True),
            'uwk_off_by_one': make_scorer(kappa, allow_off_by_one=True)}

SCORERS.update(_scorers)
Beispiel #4
0
        'neg_root_mean_squared_error': 'neg_root_mean_squared_error',
        'neg_mean_poisson_deviance': 'neg_mean_poisson_deviance',
        'neg_mean_gamma_deviance': 'neg_mean_gamma_deviance'
    },
}
AVALIABLE['categorical'] = AVALIABLE['binary'].copy()

# Set defaults
AVALIABLE['binary']['default'] = 'roc_auc'
AVALIABLE['regression']['default'] = 'r2'
AVALIABLE['categorical']['default'] = 'roc_auc_ovr'

SCORERS.update({
    'neg_hamming':
    M.make_scorer(score_func=M.hamming_loss,
                  greater_is_better=False,
                  needs_threshold=False),
    'matthews':
    M.make_scorer(score_func=M.matthews_corrcoef, greater_is_better=True)
})


def get_scorer_from_str(scorer_str):

    return SCORERS[scorer_str]


def get_scorers_by_type(problem_type):

    objs = []
    for scorer_str in AVALIABLE[problem_type]:
        conv = AVALIABLE[problem_type][scorer_str]