import validation_helpers train_fn = logistic_regression.train_log_reg test_fn = logistic_regression.test_log_reg hyperparams = { 'batch_size': [100, 200], 'learning_rate': [0.01, 0.025, 0.05], 'lambda_reg': [0, 0.001, 0.05], 'n_epochs': 100, 'validate_params': ["batch_size", "learning_rate", "lambda_reg"]} # Cross-validate here best_params, all_params = validation_helpers.validate_grid_search(train_fn, test_fn, False, train_samples, train_labels, valid_samples, valid_labels, hyperparams, num_repeat=1) # Average results due to non-deterministic nature of the model f1s = numpy.zeros((1, train_labels.shape[1])) precisions = numpy.zeros((1, train_labels.shape[1])) recalls = numpy.zeros((1, train_labels.shape[1])) num_repeat = 3 print 'All params', all_params print 'Best params', best_params for i in range(num_repeat): model = train_fn(train_labels, train_samples, best_params) _, _, _, _, f1_c, precision_c, recall_c = test_fn(valid_labels, valid_samples, model)
test_fn = logistic_regression.test_log_reg hyperparams = { 'batch_size': [100], 'learning_rate': [0.05, 0.1, 0.2], 'lambda_reg': [0, 0.05, 0.1, 0.5], 'n_epochs': 100, 'validate_params': ["batch_size", "learning_rate", "lambda_reg"] } # Cross-validate here best_params, all_params = validation_helpers.validate_grid_search( train_fn, test_fn, False, train_samples, train_labels, valid_samples, valid_labels, hyperparams, num_repeat=3) # Average results due to non-deterministic nature of the model f1 = 0 precision = 0 recall = 0 num_repeat = 3 for i in range(num_repeat): model = train_fn(train_labels, train_samples, best_params) f1_c, precision_c, recall_c, prediction, _, _, _ = test_fn(