Skip to content

Commit

Permalink
fixes for repeated validation (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
pplonski committed Dec 8, 2020
1 parent 115e773 commit d316477
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion supervised/utils/learning_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ def plot_iterations(
else:
plt.xlabel("#Iteration")
plt.ylabel(metric_name)
plt.legend(loc="best")

# limit number of learners in the legend
# too many will raise warnings
if len(learner_names) <= 15:
plt.legend(loc="best")

plt.tight_layout(pad=2.0)
plot_path = os.path.join(model_path, LearningCurves.output_file_name)
plt.savefig(plot_path)
Expand Down
2 changes: 1 addition & 1 deletion supervised/validation/validator_kfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, params):
self.shuffle = self.params.get("shuffle", True)
self.stratify = self.params.get("stratify", False)
self.random_seed = self.params.get("random_seed", 1906)
self.repeats = self.params.get("repeat", 1)
self.repeats = self.params.get("repeats", 1)

if not self.shuffle and self.repeats > 1:
warnings.warn("Disable repeats in validation because shuffle is disabled")
Expand Down
2 changes: 1 addition & 1 deletion supervised/validation/validator_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, params):
self.shuffle = self.params.get("shuffle", True)
self.stratify = self.params.get("stratify", False)
self.random_seed = self.params.get("random_seed", 1234)
self.repeats = self.params.get("repeat", 1)
self.repeats = self.params.get("repeats", 1)

if not self.shuffle and self.repeats > 1:
warnings.warn("Disable repeats in validation because shuffle is disabled")
Expand Down
6 changes: 3 additions & 3 deletions tests/tests_validation/test_validator_kfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_repeats(self):
"shuffle": True,
"stratify": False,
"k_folds": 2,
"repeat": 10,
"repeats": 10,
"results_path": self._results_path,
"X_path": X_path,
"y_path": y_path,
Expand All @@ -163,7 +163,7 @@ def test_repeats(self):
vl = KFoldValidator(params)

self.assertEqual(params["k_folds"], vl.get_n_splits())
self.assertEqual(params["repeat"], vl.get_repeats())
self.assertEqual(params["repeats"], vl.get_repeats())

for repeat in range(vl.get_repeats()):
for k_fold in range(vl.get_n_splits()):
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_disable_repeats_when_disabled_shuffle(self):
"shuffle": False,
"stratify": False,
"k_folds": 2,
"repeat": 10,
"repeats": 10,
"results_path": self._results_path,
"X_path": X_path,
"y_path": y_path,
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_validation/test_validator_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_repeats(self):
"results_path": self._results_path,
"X_path": X_path,
"y_path": y_path,
"repeat": 3
"repeats": 3
}
vl = SplitValidator(params)

Expand Down Expand Up @@ -209,7 +209,7 @@ def test_disable_repeats_when_disabled_shuffle(self):
"results_path": self._results_path,
"X_path": X_path,
"y_path": y_path,
"repeat": 3
"repeats": 3
}
vl = SplitValidator(params)

Expand Down

0 comments on commit d316477

Please sign in to comment.