# Otherwise, use default number
try:
    train_test_split_folds = int(options["-t"])
except:
    train_test_split_folds = default_train_test_split_folds

# We are using Stratified Shuffle Split, the same cross-validation method as
# used in the tester
shuffler = StratifiedShuffleSplit(labels, train_test_split_folds,
                                  random_state = 42)

# Run through all the train-test splits, train, test and measure key metrics
if gridsearchcv == "out":
    if len(search_grid)>0:
        # Specify CV option
        wrapped_algorithm.cv = shuffler
        # Fit classifier
        clf.fit(features, labels)
        # Get the best parameters of cross validation
        params = wrapped_algorithm.best_params_
        # Convert them to a JSON object with every parameter in a
        # one-element array
        grid_json = json.dumps(params, ensure_ascii=True)
        # Write them to the csv file
        with open(gridsearchcv_file_name, 'ab') as csvfile:
            writer = csv.writer(csvfile, delimiter=",")
            writer.writerow([feature_scaling, feature_selection,
                             clf_id, grid_json])
        # Print clf pipeline on the screen so we see what the script is using.
        pprint.pprint(clf)
        # Print parameters we found