Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use signature instead of poping kwargs
  • Loading branch information
Guillaume Lemaitre committed Dec 31, 2016
commit 0d03d87ca11056641a64090f447c94fdaf48b650
33 changes: 18 additions & 15 deletions imblearn/metrics/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import logging
import functools

from inspect import getcallargs

import numpy as np

from sklearn.metrics.classification import (_check_targets, _prf_divide,
Expand All @@ -22,6 +24,12 @@
from sklearn.utils.fixes import bincount
from sklearn.utils.multiclass import unique_labels

try:
from inspect import signature
except ImportError:
from sklearn.externals.funcsigs import signature


LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -603,21 +611,16 @@ def compute_score(*args, **kwargs):
# Square if desired
if squared:
_score = np.power(_score, 2)
# args will contain the y_pred and y_true
# kwargs will contain the other parameters
labels = kwargs.get('labels', None)
pos_label = kwargs.get('pos_label', 1)
average = kwargs.get('average', 'binary')
sample_weight = kwargs.get('sample_weight', None)
# Compute the sensitivity and specificity
dict_sen_spe = {
'labels': labels,
'pos_label': pos_label,
'average': average,
'sample_weight': sample_weight
}
sen, spe, _ = sensitivity_specificity_support(*args,
**dict_sen_spe)
# Create the list of tags
tags_scoring_func = getcallargs(scoring_func, *args, **kwargs)
# Get the signature of the sens/spec function
sens_spec_sig = signature(sensitivity_specificity_support)
# Filter the inputs required by the sens/spec function
tags_sens_spec = sens_spec_sig.bind(**tags_scoring_func)
# Call the sens/spec function
sen, spe, _ = sensitivity_specificity_support(
*tags_sens_spec.args,
**tags_sens_spec.kwargs)
# Compute the dominance
dom = sen - spe
return (1. + alpha * dom) * _score
Expand Down