From 9f8b4b7431e16bd09479518338427bfa4922f3a9 Mon Sep 17 00:00:00 2001 From: Thierry RAMORASOAVINA Date: Fri, 9 Oct 2026 17:32:43 +0200 Subject: [PATCH] Fix a bogus translation of the `use_complement_as_test` parameter that leaded to a systematic model testing --- CHANGELOG.md | 1 + khiops/core/api.py | 2 +- .../ref/Adult._kh | 69 +++++++++++++++++++ tests/test_core.py | 37 ++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tests/resources/scenario_generation/api/train_predictor_no_model_testing/ref/Adult._kh diff --git a/CHANGELOG.md b/CHANGELOG.md index f15c72dc..89cea29b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixed - (`core`) Fix a RuntimeException error when automatically correcting deprecated data paths in task args +- (`core`) Fix a bogus translation of the `use_complement_as_test` parameter that leaded to a systematic model testing. ## 11.0.1.0 - 2026-07-02 diff --git a/khiops/core/api.py b/khiops/core/api.py index 3774c4c0..03dec3a3 100644 --- a/khiops/core/api.py +++ b/khiops/core/api.py @@ -361,7 +361,7 @@ def _preprocess_task_arguments(task_args): if task_args["use_complement_as_test"]: task_args["test_database_mode"] = "Complementary" else: - task_args["test_database_mode"] = "None" + task_args["test_database_mode"] = "none" del task_args["use_complement_as_test"] # Preprocess the database format parameters diff --git a/tests/resources/scenario_generation/api/train_predictor_no_model_testing/ref/Adult._kh b/tests/resources/scenario_generation/api/train_predictor_no_model_testing/ref/Adult._kh new file mode 100644 index 00000000..41116b9e --- /dev/null +++ b/tests/resources/scenario_generation/api/train_predictor_no_model_testing/ref/Adult._kh @@ -0,0 +1,69 @@ +// Scenario for task train_predictor +// Dictionary file and class settings +ClassManagement.OpenFile +ClassFileName Adult/Adult.kdic // +OK + +// Train/test database settings +TrainDatabase.ClassName Adult +TrainDatabase.DatabaseSpec.Data.DatabaseFiles.List.Key +TrainDatabase.DatabaseSpec.Data.DatabaseFiles.DataTableName Adult/Adult.txt // +TrainDatabase.DatabaseSpec.Data.HeaderLineUsed true +TrainDatabase.DatabaseSpec.Data.FieldSeparator +TrainDatabase.DatabaseSpec.Data.DatabaseFormatDetector.DetectFileFormat +TrainDatabase.DatabaseSpec.Sampling.SampleNumberPercentage 70.0 +TrainDatabase.DatabaseSpec.Sampling.SamplingMode Include sample +TrainDatabase.DatabaseSpec.Selection.SelectionAttribute +TrainDatabase.DatabaseSpec.Selection.SelectionValue +TrainDatabase.TestDatabaseSpecificationMode none + +// Target variable +AnalysisSpec.TargetAttributeName class +AnalysisSpec.MainTargetModality + +// Do data preparation only +AnalysisSpec.PredictorsSpec.AdvancedSpec.DataPreparationOnly false + +// Selective Naive Bayes settings +AnalysisSpec.PredictorsSpec.AdvancedSpec.SelectiveNaiveBayesParameters.TrainParameters.MaxEvaluatedAttributeNumber 0 +AnalysisSpec.PredictorsSpec.AdvancedSpec.SelectiveNaiveBayesParameters.SelectionParameters.MaxSelectedAttributeNumber 0 + +// Feature engineering +AnalysisSpec.PredictorsSpec.ConstructionSpec.MaxTextFeatureNumber 10000 +AnalysisSpec.PredictorsSpec.ConstructionSpec.MaxTreeNumber 10 +AnalysisSpec.PredictorsSpec.ConstructionSpec.MaxAttributePairNumber 0 +AnalysisSpec.PredictorsSpec.AdvancedSpec.InspectAttributePairsParameters +AllAttributePairs true +Exit +AnalysisSpec.PredictorsSpec.ConstructionSpec.KeepSelectedAttributesOnly true +AnalysisSpec.PredictorsSpec.ConstructionSpec.MaxConstructedAttributeNumber 1000 +AnalysisSpec.PredictorsSpec.AdvancedSpec.InspectConstructionDomain +Exit + +// Text feature parameters +AnalysisSpec.PredictorsSpec.AdvancedSpec.InspectTextFeaturesParameters +TextFeatures words +Exit + + +// Data preparation (discretization & grouping) settings +AnalysisSpec.PreprocessingSpec.TargetGrouped false +AnalysisSpec.PreprocessingSpec.InspectAdvancedParameters +DiscretizerUnsupervisedMethodName MODL +GrouperUnsupervisedMethodName MODL +Exit + +// Max parts +AnalysisSpec.PreprocessingSpec.MaxPartNumber 0 + +// Output settings +AnalysisResults.ReportFileName train_predictor_file_paths/AnalysisResults.khj // + +// Build model +ComputeStats + +// End of scenario for task train_predictor + +// Exit Khiops +ClassManagement.Quit +OK diff --git a/tests/test_core.py b/tests/test_core.py index facdc667..e82a16e3 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -750,6 +750,43 @@ def test_api_scenario_generation(self): # Restore the default runner kh.set_runner(default_runner) + def test_correct_args_translation(self): + """Tests the translation of specific args is correct + so that Khiops takes them into account + """ + # Set the root directory of this test + test_resources_dir = os.path.join(resources_dir(), "scenario_generation", "api") + + # Use the test runner that only compares the scenarios + default_runner = kh.get_runner() + test_runner = ScenarioWriterRunner(self, test_resources_dir) + kh.set_runner(test_runner) + + test_runner.test_name = "train_predictor_no_model_testing" + test_runner.subtest_name = "Adult" + # Clean the directory for this method's tests + cleanup_dir(test_runner.output_scenario_dir, "*/output/*._kh", verbose=True) + + kh.train_predictor( + dictionary_file_path_or_domain="Adult/Adult.kdic", + dictionary_name="Adult", + data_table_path="Adult/Adult.txt", + target_variable="class", + analysis_report_file_path="train_predictor_file_paths/AnalysisResults.khj", + use_complement_as_test=False, + ) + + # Compare the reference with the output + assert_files_equal( + self, + test_runner.ref_scenario_path, + test_runner.output_scenario_path, + line_comparator=scenario_line_comparator, + ) + + # Restore the default runner + kh.set_runner(default_runner) + def test_data_path_deprecation_in_api_method(self): """Tests if the core.api deprecates legacy data paths""" # Set the root directory of these tests