class_docstr: Test class for custom metric tests.
docstr: Test API with a lower-is-better custom metric.
docstr_tok: ["Test","API","with","a","lower-is-better","custom","metric","."]
code: def test_api_with_inverted_custom_metric(self):
      """Test API with a lower-is-better custom metric."""
      # register a lower-is-better custom metrics from our file
      # which is simply 1 minus the precision score
      custom_metrics_file1 = other_dir / "custom_metrics.py"
      register_custom_metric(
          custom_metrics_file1, "one_minus_precision"
      )
  
      # create some classification data
      train_fs, _ = make_classification_data(
          num_examples=1000, num_features=10, num_labels=2
      )
  
      # set up a learner to tune using the lower-is-better custom metric
      learner1 = Learner("LogisticRegression")
      (grid_score1, grid_results_dict1) = learner1.train(
          train_fs,
          grid_objective="one_minus_precision",
          grid_search_folds=3,
      )
  
      # now setup another learner that uses the complementary version
      # of our custom metric (regular precision) for grid search
      learner2 = Learner("LogisticRegression")
      (grid_score2, grid_results_dict2) = learner2.train(
          train_fs, grid_objective="precision", grid_search_folds=3
      )
  
      # for both learners 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 - grid_results_dict2["mean_test_score"],
          -1 * 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 20 for calling the TestCustomMetrics obj's underlying member method code with example usage: obj.test_api_with_inverted_custom_metric() without return types