def default_metrics(self): return [ metrics.Accuracy(), metrics.CrossEntropy(), metrics.MacroPrecision(), metrics.MacroRecall(), metrics.MacroF1(), metrics.MicroPrecision(), metrics.MicroRecall(), metrics.MicroF1() ]
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 ], [True, True, False, True, True]), (metrics.MacroF1(), functools.partial( sk_metrics.f1_score, average='macro'), [0, 1, 2, 2, 2], [0, 0, 2, 2, 1]), (metrics.MicroF1(), functools.partial( sk_metrics.f1_score, average='micro'), [0, 1, 2, 2, 2], [0, 0, 2, 2, 1]), (metrics.LogLoss(), sk_metrics.log_loss, [True, False, False, True ], [0.9, 0.1, 0.2, 0.65]), (metrics.CrossEntropy(), functools.partial(sk_metrics.log_loss, labels=[0, 1, 2]), [0, 1, 2, 2], [[0.29450637, 0.34216758, 0.36332605], [0.21290077, 0.32728332, 0.45981591], [0.42860913, 0.33380113, 0.23758974], [0.44941979, 0.32962558, 0.22095463]])]) def test_metric(metric, sk_metric, y_true, y_pred): for i, (yt, yp) in enumerate(zip(y_true, y_pred)): if isinstance(yp, list):
(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), ] @pytest.mark.parametrize('metric, sk_metric', TEST_CASES) @pytest.mark.filterwarnings('ignore::RuntimeWarning') @pytest.mark.filterwarnings( 'ignore::sklearn.metrics.classification.UndefinedMetricWarning') def test_metric(metric, sk_metric):
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) print(metric.update(yt, xt))
(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), ] @pytest.mark.parametrize('metric, sk_metric', TEST_CASES) @pytest.mark.filterwarnings('ignore::RuntimeWarning') @pytest.mark.filterwarnings('ignore::sklearn.metrics.classification.UndefinedMetricWarning') def test_metric(metric, sk_metric): # Check str works str(metric)
partial(sk_metrics.precision_score, average='weighted')), (metrics.Recall(), sk_metrics.recall_score), (metrics.MacroRecall(), partial(sk_metrics.recall_score, average='macro')), (metrics.MicroRecall(), partial(sk_metrics.recall_score, average='micro')), (metrics.WeightedRecall(), partial(sk_metrics.recall_score, average='weighted')), (metrics.FBeta(beta=.5), partial(sk_metrics.fbeta_score, beta=.5)), (metrics.MacroFBeta(beta=.5), partial(sk_metrics.fbeta_score, beta=.5, average='macro')), (metrics.MicroFBeta(beta=.5), partial(sk_metrics.fbeta_score, beta=.5, average='micro')), (metrics.WeightedFBeta(beta=.5), partial(sk_metrics.fbeta_score, beta=.5, average='weighted')), (metrics.F1(), sk_metrics.f1_score), (metrics.MacroF1(), partial(sk_metrics.f1_score, average='macro')), (metrics.MicroF1(), partial(sk_metrics.f1_score, average='micro')), (metrics.WeightedF1(), 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), ] @pytest.mark.parametrize('metric, sk_metric', [ pytest.param(metric, sk_metric, id=f'{metric.__class__.__name__}') for metric, sk_metric in TEST_CASES ]) @pytest.mark.filterwarnings('ignore::RuntimeWarning') @pytest.mark.filterwarnings( 'ignore::sklearn.metrics.classification.UndefinedMetricWarning') def test_metric(metric, sk_metric):