-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose cv_folds and stratified #240
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bfe7581
adding option to have non-stratified folds, and specify the number of…
aoifecahill f65e7ee
update documentation for cv_folds, random_folds, and grid_search_folds
aoifecahill c58fa9c
output information about folds/stratification in results file; fix bu…
aoifecahill 6468872
fix version of sklearn in requirements_rtd.txt
aoifecahill bb7e694
update unit test for output
aoifecahill 3f028d3
fixing scikit learn version for travis too
aoifecahill 6529131
some testing
aoifecahill f4bf9d3
adding more tests
aoifecahill 3062046
adding a warning
aoifecahill 73d5ff5
update warning message
aoifecahill 6c55959
catch ValueError explicitly
aoifecahill 186a015
Fix typo in warning.
desilinguist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
configparser | ||
logutils | ||
mock | ||
scikit-learn>=0.14 | ||
scikit-learn==0.15.2 | ||
six | ||
PrettyTable | ||
beautifulsoup4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,11 @@ def _print_fancy_output(learner_result_dicts, output_file=sys.stdout): | |
print('Feature Set: {}'.format(lrd['featureset']), file=output_file) | ||
print('Learner: {}'.format(lrd['learner_name']), file=output_file) | ||
print('Task: {}'.format(lrd['task']), file=output_file) | ||
if lrd['task'] == 'cross_validate': | ||
print('Number of Folds: {}'.format(lrd['cv_folds']), | ||
file=output_file) | ||
print('Stratified Folds: {}'.format(lrd['stratified_folds']), | ||
file=output_file) | ||
print('Feature Scaling: {}'.format(lrd['feature_scaling']), | ||
file=output_file) | ||
print('Grid Search: {}'.format(lrd['grid_search']), file=output_file) | ||
|
@@ -246,6 +251,8 @@ def _setup_config_parser(config_path): | |
'grid_search_jobs': '0', | ||
'grid_search_folds': '3', | ||
'cv_folds_file': '', | ||
'num_cv_folds': '10', | ||
'random_folds': 'False', | ||
'suffix': '', | ||
'label_col': 'y', | ||
'id_col': 'id', | ||
|
@@ -387,13 +394,33 @@ def _parse_config_file(config_path): | |
id_col = config.get("Input", "id_col") | ||
ids_to_floats = config.getboolean("Input", "ids_to_floats") | ||
|
||
# get the cv folds file and make a dictionary from it | ||
# get the cv folds file and make a dictionary from it, if it exists | ||
cv_folds_file = config.get("Input", "cv_folds_file") | ||
num_cv_folds = config.get("Input", "num_cv_folds") | ||
if cv_folds_file: | ||
cv_folds = _load_cv_folds(cv_folds_file, | ||
ids_to_floats=ids_to_floats) | ||
else: | ||
cv_folds = 10 | ||
# set the number of folds for cross-validation | ||
if num_cv_folds: | ||
try: | ||
cv_folds = int(num_cv_folds) | ||
except: | ||
raise ValueError("The value for cv_folds should be an integer. " + | ||
"You specified {}".format(num_cv_folds)) | ||
else: | ||
# default number of cross-validation folds | ||
cv_folds = 10 | ||
|
||
# whether or not to do stratified cross validation | ||
random_folds = config.get("Input", "random_folds") | ||
if random_folds == 'True': | ||
if cv_folds_file: | ||
logger.warning('Random folds will not override'+ | ||
'values in cv_folds_file') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message is not entirely clear. So, basically, random_folds is being ignored here, right? May be something like: |
||
do_stratified_folds = False | ||
else: | ||
do_stratified_folds = True | ||
|
||
train_file = config.get("Input", "train_file") | ||
test_file = config.get("Input", "test_file") | ||
|
@@ -541,7 +568,7 @@ def _parse_config_file(config_path): | |
test_set_name, suffix, featuresets, do_shuffle, model_path, | ||
do_grid_search, grid_objective, probability, results_path, | ||
pos_label_str, feature_scaling, min_feature_count, | ||
grid_search_jobs, grid_search_folds, cv_folds, | ||
grid_search_jobs, grid_search_folds, cv_folds, do_stratified_folds, | ||
fixed_parameter_list, param_grid_list, featureset_names, learners, | ||
prediction_dir, log_path, train_path, test_path, ids_to_floats, | ||
class_map, custom_learner_path) | ||
|
@@ -650,6 +677,7 @@ def _classify_featureset(args): | |
grid_search_jobs = args.pop("grid_search_jobs") | ||
grid_search_folds = args.pop("grid_search_folds") | ||
cv_folds = args.pop("cv_folds") | ||
stratified_folds = args.pop("do_stratified_folds") | ||
label_col = args.pop("label_col") | ||
id_col = args.pop("id_col") | ||
ids_to_floats = args.pop("ids_to_floats") | ||
|
@@ -666,8 +694,8 @@ def _classify_featureset(args): | |
# logging | ||
print("Task:", task, file=log_file) | ||
if task == 'cross_validate': | ||
print(("Cross-validating on {}, feature " + | ||
"set {} ...").format(train_set_name, featureset), | ||
print(("Cross-validating ({} folds) on {}, feature " + | ||
"set {} ...").format(cv_folds, train_set_name, featureset), | ||
file=log_file) | ||
elif task == 'evaluate': | ||
print(("Training on {}, Test on {}, " + | ||
|
@@ -756,6 +784,7 @@ def _classify_featureset(args): | |
'grid_search_folds': grid_search_folds, | ||
'min_feature_count': min_feature_count, | ||
'cv_folds': cv_folds, | ||
'stratified_folds': stratified_folds, | ||
'scikit_learn_version': SCIKIT_VERSION} | ||
|
||
# check if we're doing cross-validation, because we only load/save | ||
|
@@ -764,7 +793,7 @@ def _classify_featureset(args): | |
if task == 'cross_validate': | ||
print('\tcross-validating', file=log_file) | ||
task_results, grid_scores = learner.cross_validate( | ||
train_examples, shuffle=shuffle, | ||
train_examples, shuffle=shuffle, stratified=stratified_folds, | ||
prediction_prefix=prediction_prefix, grid_search=grid_search, | ||
grid_search_folds=grid_search_folds, cv_folds=cv_folds, | ||
grid_objective=grid_objective, param_grid=param_grid, | ||
|
@@ -776,7 +805,6 @@ def _classify_featureset(args): | |
'{} model').format(learner_name), | ||
file=log_file) | ||
|
||
grid_search_folds = 3 | ||
if not isinstance(cv_folds, int): | ||
grid_search_folds = cv_folds | ||
|
||
|
@@ -1062,7 +1090,7 @@ def run_configuration(config_file, local=False, overwrite=True, queue='all.q', | |
hasher_features, id_col, label_col, train_set_name, test_set_name, suffix, | ||
featuresets, do_shuffle, model_path, do_grid_search, grid_objective, | ||
probability, results_path, pos_label_str, feature_scaling, | ||
min_feature_count, grid_search_jobs, grid_search_folds, cv_folds, | ||
min_feature_count, grid_search_jobs, grid_search_folds, cv_folds, do_stratified_folds, | ||
fixed_parameter_list, param_grid_list, featureset_names, learners, | ||
prediction_dir, log_path, train_path, test_path, ids_to_floats, class_map, | ||
custom_learner_path) = _parse_config_file(config_file) | ||
|
@@ -1202,6 +1230,7 @@ def run_configuration(config_file, local=False, overwrite=True, queue='all.q', | |
job_args["grid_search_jobs"] = grid_search_jobs | ||
job_args["grid_search_folds"] = grid_search_folds | ||
job_args["cv_folds"] = cv_folds | ||
job_args["do_stratified_folds"] = do_stratified_folds | ||
job_args["label_col"] = label_col | ||
job_args["id_col"] = id_col | ||
job_args["ids_to_floats"] = ids_to_floats | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to specify a
ValueError
explicitly here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean? There is a ValueError raised?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant that you want to catch a
ValueError
explicitly in theexcept
clause.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't I do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the code I see:
Here's what I am saying it should look like:
Note the difference in the
except
statement.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, will update.