Exemple #1
0
 def default_metrics(self):
     return [
         metrics.Accuracy(),
         metrics.CrossEntropy(),
         metrics.MacroPrecision(),
         metrics.MacroRecall(),
         metrics.MacroF1(),
         metrics.MicroPrecision(),
         metrics.MicroRecall(),
         metrics.MicroF1()
     ]
Exemple #2
0
from sklearn import metrics as sk_metrics


@pytest.mark.parametrize(
    'metric, sk_metric, y_true, y_pred',
    [(metrics.Precision(), sk_metrics.precision_score,
      [True, False, True, True, True], [True, True, False, True, True]),
     (metrics.MacroPrecision(),
      functools.partial(sk_metrics.precision_score,
                        average='macro'), [0, 1, 2, 2, 2], [0, 0, 2, 2, 1]),
     (metrics.MicroPrecision(),
      functools.partial(sk_metrics.precision_score,
                        average='micro'), [0, 1, 2, 2, 2], [0, 0, 2, 2, 1]),
     (metrics.Recall(), sk_metrics.recall_score,
      [True, False, True, True, True], [True, True, False, True, True]),
     (metrics.MacroRecall(),
      functools.partial(sk_metrics.recall_score,
                        average='macro'), [0, 1, 2, 2, 2], [0, 0, 2, 2, 1]),
     (metrics.MicroRecall(),
      functools.partial(sk_metrics.recall_score,
                        average='micro'), [0, 1, 2, 2, 2], [0, 0, 2, 2, 1]),
     (metrics.FBeta(beta=0.5),
      functools.partial(sk_metrics.fbeta_score, beta=0.5),
      [True, False, True, True, True], [True, True, False, True, True]),
     (metrics.MacroFBeta(beta=0.5),
      functools.partial(sk_metrics.fbeta_score, beta=0.5,
                        average='macro'), [0, 1, 0, 2, 2], [0, 0, 1, 1, 2]),
     (metrics.MicroFBeta(beta=0.5),
      functools.partial(sk_metrics.fbeta_score, beta=0.5,
                        average='micro'), [0, 1, 0, 2, 2], [0, 0, 1, 1, 2]),
     (metrics.F1(), sk_metrics.f1_score, [True, False, True, True, True
Exemple #3
0
config = json.loads(input())

target = config['target']
predict = config['predict']
m = config['metric']

if (m == "Accuracy"):
    metric = metrics.Accuracy()
elif (m == "CrossEntropy"):
    metric = metrics.CrossEntropy()
elif (m == "MacroF1"):
    metric = metrics.MacroF1()
elif (m == "MacroPrecision"):
    metric = metrics.MacroPrecision()
elif (m == "MacroRecall"):
    metric = metrics.MacroRecall()
elif (m == "MicroF1"):
    metric = metrics.MicroF1()
elif (m == "MicroPrecision"):
    metric = metrics.MicroPrecision()
elif (m == "MicroRecall"):
    metric = metrics.MicroRecall()

while True:

    #wait request
    data = input()

    Xi = json.loads(data)
    xt = Xi.pop(predict)
    yt = Xi.pop(target)
Exemple #4
0
    if isinstance(metric, base.RegressionMetric):
        yield (
            [random.random() for _ in range(n)],
            [random.random() for _ in range(n)],
            sample_weights
        )


TEST_CASES = [
    (metrics.Accuracy(), sk_metrics.accuracy_score),
    (metrics.Precision(), sk_metrics.precision_score),
    (metrics.MacroPrecision(), functools.partial(sk_metrics.precision_score, average='macro')),
    (metrics.MicroPrecision(), functools.partial(sk_metrics.precision_score, average='micro')),
    (metrics.WeightedPrecision(), functools.partial(sk_metrics.precision_score, average='weighted')),
    (metrics.Recall(), sk_metrics.recall_score),
    (metrics.MacroRecall(), functools.partial(sk_metrics.recall_score, average='macro')),
    (metrics.MicroRecall(), functools.partial(sk_metrics.recall_score, average='micro')),
    (metrics.WeightedRecall(), functools.partial(sk_metrics.recall_score, average='weighted')),
    (metrics.FBeta(beta=.5), functools.partial(sk_metrics.fbeta_score, beta=.5)),
    (metrics.MacroFBeta(beta=.5), functools.partial(sk_metrics.fbeta_score, beta=.5, average='macro')),
    (metrics.MicroFBeta(beta=.5), functools.partial(sk_metrics.fbeta_score, beta=.5, average='micro')),
    (metrics.WeightedFBeta(beta=.5), functools.partial(sk_metrics.fbeta_score, beta=.5, average='weighted')),
    (metrics.F1(), sk_metrics.f1_score),
    (metrics.MacroF1(), functools.partial(sk_metrics.f1_score, average='macro')),
    (metrics.MicroF1(), functools.partial(sk_metrics.f1_score, average='micro')),
    (metrics.WeightedF1(), functools.partial(sk_metrics.f1_score, average='weighted')),
    (metrics.MCC(), sk_metrics.matthews_corrcoef),
    (metrics.MAE(), sk_metrics.mean_absolute_error),
    (metrics.MSE(), sk_metrics.mean_squared_error),
]