class_docstr: Test class for cross-validation tests.
class_docstr_tok: ["Test","class","for","cross-validation","tests","."]
docstr: Test that 10-fold cross_validate experiments work and fold ids get saved.
docstr_tok: ["Test","that","10-fold","cross_validate","experiments","work","and","fold","ids","get","saved","."]
code: def test_cross_validate_task(self):
      """Test that 10-fold cross_validate experiments work and fold ids get saved."""
      # Run experiment
      suffix = ".jsonlines"
      train_path = train_dir / f"f0{suffix}"
  
      template_path = config_dir / "test_save_cv_folds.template.cfg"
      config_path = fill_in_config_paths_for_single_file(
          template_path, train_path, None
      )
      run_configuration(config_path, quiet=True, local=True)
  
      # Check final average results
      with open(
          output_dir
          / "test_save_cv_folds_train_f0.jsonlines_LogisticRegression.results.json"
      ) as f:
          result_dict = json.load(f)[10]
  
      assert_almost_equal(result_dict["accuracy"], 0.517)
  
      # Check that the fold ids were saved correctly
      # First compute the expected fold IDs
      examples = load_featureset(train_path, "", suffix, quiet=True)
      expected_skll_ids = compute_expected_folds_for_cv_testing(
          examples, num_folds=10
      )
      # read in the computed fold IDs
      skll_fold_ids = {}
      with open(
          output_dir / "test_save_cv_folds_skll_fold_ids.csv"
      ) as f:
          reader = csv.DictReader(f)
          for row in reader:
              skll_fold_ids[row["id"]] = row["cv_test_fold"]
  
      # convert the dictionary to strings (sorted by key) for quick comparison
      skll_fold_ids_str = "".join(
          f"{key}{val}" for key, val in sorted(skll_fold_ids.items())
      )
      expected_skll_ids_str = "".join(
          f"{key}{val}"
          for key, val in sorted(expected_skll_ids.items())
      )
  
      self.assertEqual(skll_fold_ids_str, expected_skll_ids_str)
  
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 11 for calling the TestCrossValidation obj's underlying member method code with example usage: obj.test_cross_validate_task() without return types