Skip to content

Commit

Permalink
Allow None value in feature_scaling and convert it to a valid string …
Browse files Browse the repository at this point in the history
…value
  • Loading branch information
Tamar Lavee committed Sep 9, 2024
1 parent 51c540b commit 59d9461
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions skll/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,8 @@ def parse_config_file(
# ensure that feature_scaling is specified only as one of the
# four available choices
feature_scaling = config.get("Input", "feature_scaling")
if feature_scaling not in VALID_FEATURE_SCALING_OPTIONS:
raise ValueError("Invalid value for feature_scaling parameter: " f"{feature_scaling}")
if feature_scaling.lower() not in VALID_FEATURE_SCALING_OPTIONS:
raise ValueError(f"Invalid value for feature_scaling parameter: {feature_scaling}")

suffix = config.get("Input", "suffix")
label_col = config.get("Input", "label_col")
Expand Down
19 changes: 19 additions & 0 deletions tests/configs/test_feature_scaling_none.template.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[General]
experiment_name=test_class_map
task=evaluate

[Input]
feature_hasher = true
hasher_features = 100
featuresets=[["test_class_map"]]
learners=["LogisticRegression"]
suffix=.jsonlines
class_map={'dog': ['beagle', 'dachsund']}
feature_scaling=None

[Tuning]
grid_search=False
objectives=['accuracy']

[Output]
probability=false
25 changes: 25 additions & 0 deletions tests/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,31 @@ def test_config_parsing_set_wandb_values(self):
self.assertEqual(wandb_credentials["wandb_entity"], "wandb_entity")
self.assertEqual(wandb_credentials["wandb_project"], "wandb_project")

def test_config_parsing_feature_scaling_none(self):
"""Test that feature scaling value of None is acceptable and converted to a string"""
values_to_fill_dict = {
"experiment_name": "config_parsing",
"task": "evaluate",
"train_directory": train_dir,
"test_directory": test_dir,
"featuresets": "[['f1', 'f2', 'f3']]",
"fixed_parameters": '[{"estimator_names": ["SVC", "LogisticRegression", "MultinomialNB"]}]',
"learners": "['VotingClassifier']",
"objectives": "['accuracy']",
"logs": output_dir,
"results": output_dir,
}

config_template_path = config_dir / "test_feature_scaling_none.template.cfg"

config_path = fill_in_config_options(
config_template_path, values_to_fill_dict, "default_value_save_votes"
)

configuration = parse_config_file(config_path)
feature_scaling = configuration[20]

self.assertEqual("none", feature_scaling)
def test_config_parsing_set_wandb_missing_value(self):
"""Test that config parsing works as expected for when values are missing `wandb_credentials`."""
values_to_fill_dict = {
Expand Down

0 comments on commit 59d9461

Please sign in to comment.