class_docstr: Test class for cross-validation tests.
class_docstr_tok: ["Test","class","for","cross-validation","tests","."]
docstr: Check cross-validation results with specified folds, feature hashing, and RBFSampler.
docstr_tok: ["Check","cross-validation","results","with","specified","folds",",","feature","hashing",",","and","RBFSampler","."]
code: def test_specified_cv_folds(self):
      """Check cross-validation results with specified folds, feature hashing, and RBFSampler."""
      # This runs four tests.
  
      # The first does not use feature hashing with 9 features (3 numeric, 6
      # binary) has pre-specified folds and has less than 60% accuracy for each
      # of the 3 folds.
  
      # The second uses feature hashing with 4 features, uses 10 folds (not pre-
      # specified) and has more than 70% accuracy accuracy for each of the 10
      # folds.
  
      # The third is the same as the first but uses an RBFSampler.
  
      # The fourth is the same as the second but uses an RBFSampler.
  
      for (
          test_value,
          assert_func,
          expected_folds,
          use_hashing,
          use_sampler,
      ) in [
          (0.58, self.assertLess, 3, False, False),
          (0.1, self.assertGreater, 10, True, False),
          (0.57, self.assertLess, 3, False, True),
          (0.69, self.assertGreater, 10, True, True),
      ]:
          sampler = "RBFSampler" if use_sampler else None
          learner = Learner("LogisticRegression", sampler=sampler)
          cv_fs, custom_cv_folds = self.make_cv_folds_data(
              use_feature_hashing=use_hashing
          )
          folds = custom_cv_folds if not use_hashing else 10
          (grid_scores, _, _, _, _) = learner.cross_validate(
              cv_fs,
              cv_folds=folds,
              grid_search=True,
              grid_objective="f1_score_micro",
              save_cv_folds=False,
          )
          fold_test_scores = [t[-2] for t in grid_scores]
  
          overall_score = np.mean(fold_test_scores)
  
          assert_func(overall_score, test_value)
  
          self.assertEqual(len(fold_test_scores), expected_folds)
          for fold_score in fold_test_scores:
              assert_func(fold_score, test_value)
  
imports: import csv
  import itertools
  import json
  import re
  import unittest
  import numpy
  from numpy.testing import assert_almost_equal
  from sklearn.datasets import make_classification
  from sklearn.feature_extraction import FeatureHasher
  from skll.config import load_cv_folds
  from skll.data import FeatureSet
  from skll.experiments import load_featureset, run_configuration
  from skll.learner import Learner
  from skll.utils.testing import compute_expected_folds_for_cv_testing, config_dir, create_jsonlines_feature_files, fill_in_config_paths_for_single_file, other_dir, output_dir, remove_jsonlines_feature_files, train_dir, unlink
label_desc: Use image node_id 4 for calling the TestCrossValidation obj's underlying member method code with example usage: obj.test_specified_cv_folds() without return types