class_docstr: Test class for custom metric tests.
docstr: Test config with a lower-is-better custom metric.
docstr_tok: ["Test","config","with","a","lower-is-better","custom","metric","."]
code: def test_config_with_inverted_custom_metric(self):
      """Test config with a lower-is-better custom metric."""
      # run the first experiment that uses a lower-is-better custom metric
      # for grid saerch defined as simply 1 minus the macro-averaged F1 score
      train_file = other_dir / "examples_train.jsonlines"
      test_file = other_dir / "examples_test.jsonlines"
      config_path1 = fill_in_config_paths_for_single_file(
          config_dir / "test_custom_metrics_kwargs1.template.cfg",
          train_file,
          test_file,
      )
      run_configuration(config_path1, local=True, quiet=True)
  
      # laod the results
      with open(
          output_dir / "test_custom_metrics_kwargs1_train_examples_"
          "train.jsonlines_LogisticRegression.results.json"
      ) as f:
          result_dict1 = json.load(f)
          grid_score1 = result_dict1["grid_score"]
          grid_results_dict1 = result_dict1["grid_search_cv_results"]
  
      # now run the second experiment that is identical except that
      # that it uses the regular macro-averaged F1 score for grid search
      config_path2 = fill_in_config_paths_for_single_file(
          config_dir / "test_custom_metrics_kwargs2.template.cfg",
          train_file,
          test_file,
      )
      run_configuration(config_path2, local=True, quiet=True)
  
      # laod the results
      with open(
          output_dir / "test_custom_metrics_kwargs2_train_examples_"
          "train.jsonlines_LogisticRegression.results.json"
      ) as f:
          result_dict2 = json.load(f)
          grid_score2 = result_dict2["grid_score"]
          grid_results_dict2 = result_dict2["grid_search_cv_results"]
  
      # for both experiments the ranking of the C hyperparameter should be
      # should be the identical since when we defined one_minus_precision
      # we set the `greater_is_better` keyword argument to `False`
      assert_array_equal(
          grid_results_dict1["rank_test_score"],
          grid_results_dict2["rank_test_score"],
      )
  
      # furthermore, the final grid score and the mean scores for each
      # C hyperparameter value should follow the same 1-X relationship
      # except that our custom metric should be negated due to the
      # keyword argument that we set when we defined it
      self.assertAlmostEqual(
          1 - grid_score2, -1 * grid_score1, places=6
      )
      assert_array_almost_equal(
          1 - np.array(grid_results_dict2["mean_test_score"]),
          -1 * np.array(grid_results_dict1["mean_test_score"]),
          decimal=6,
      )
  
imports: import json
  import sys
  import unittest
  from itertools import chain
  import numpy
  from numpy.testing import assert_array_almost_equal, assert_array_equal, assert_raises_regex
  from sklearn.metrics import fbeta_score
  import skll.metrics
  from skll.data import NDJReader
  from skll.experiments import run_configuration
  from skll.learner import Learner
  from skll.metrics import _CUSTOM_METRICS, register_custom_metric, use_score_func
  from skll.utils.testing import config_dir, fill_in_config_paths_for_single_file, make_classification_data, other_dir, output_dir, unlink
label_desc: Use image node_id 21 for calling the TestCustomMetrics obj's underlying member method code with example usage: obj.test_config_with_inverted_custom_metric() without return types