def main(): parser = argparse.ArgumentParser( description='Ensembling HyperSpace models') parser.add_argument('--results_dir', type=str, help='Path to results directory.') args = parser.parse_args() results = load_results(args.results_dir) clfs = [] for _ in results: # Use default random forest for each of the ensemble models model = RandomForestClassifier() clfs.append(model) # Using the training and test sets from `optimize.py` X_train, _, X_test, y_train, _, y_test = load_data(0.25, 0.25) y_preds, y_proba = ensemble(clfs, X_train, y_train, X_test, y_test) acc_test = accuracy_score(y_test, y_preds) ll_test = log_loss(y_test, y_proba) print( f'\nEnsemble Test Accuracy: {acc_test:.4f}, Test Log Loss: {ll_test:.4f}' )
def run(results_dir, n_calls=200, n_runs=10): """Run benchmark for Branin function.""" models = ['GP', 'RF', 'GBRT', 'Rand'] bounds = [(-5.0, 10.0), (0.0, 15.0)] for model in models: model_dir = os.path.join(results_dir, model) if not os.path.exists(model_dir): os.makedirs(model_dir, exist_ok=True) for random_state in range(n_runs): directory = os.path.join(model_dir, 'run' + str(random_state)) if not os.path.exists(directory): os.makedirs(directory, exist_ok=True) checkpoint = load_results(directory) hyperdrive(branin, bounds, directory, n_iterations=n_calls, verbose=True, random_state=random_state, checkpoints=True, restart=checkpoint)
def main(): parser = argparse.ArgumentParser( description='Ensembling HyperSpace models') parser.add_argument('--results_dir', type=str, help='Path to results directory.') args = parser.parse_args() results = load_results(args.results_dir) clfs = [] for result in results: # Get domain from best model in each hyperspace hyperparams = result.x n_estimators = hyperparams[0] max_depth = hyperparams[1] model = RandomForestClassifier(n_estimators=n_estimators, max_depth=max_depth) clfs.append(model) # Using the training and test sets from `optimize.py` X_train, _, X_test, y_train, _, y_test = load_data(0.25, 0.25) y_preds, y_proba = ensemble(clfs, X_train, y_train, X_test, y_test) acc_test = accuracy_score(y_test, y_preds) ll_test = log_loss(y_test, y_proba) print( f'\nEnsemble Test Accuracy: {acc_test:.4f}, Test Log Loss: {ll_test:.4f}' )
def main(): parser = argparse.ArgumentParser(description='Setup experiment.') parser.add_argument('--results_dir', type=str, help='Path to results directory.') args = parser.parse_args() hparams = [(2, 10), # max_depth (10.0**-2, 10.0**0)] # learning_rate # Load results from previous runs checkpoint = load_results(args.results_dir) hyperdrive(objective=objective, hyperparameters=hparams, results_path=args.results_dir, model="GP", n_iterations=100, verbose=True, random_state=0, checkpoints=True, restart=checkpoint)
def main(): global train_x global train_y global test_x global test_y train_x = np.load('data/train_X.npy') train_y = np.load('data/train_Y.npy') test_x = np.load('data/test_X.npy') test_y = np.load('data/test_Y.npy') for task in range(4): le = preprocessing.LabelEncoder() le.fit(train_y[:, task]) train_y[:, task] = le.transform(train_y[:, task]) test_y[:, task] = le.transform(test_y[:, task]) max_vocab = np.max(train_x) max_vocab2 = np.max(test_x) if max_vocab2 > max_vocab: max_vocab = max_vocab2 print('max_vocab:', max_vocab) np.random.seed(0) global wv_len wv_len = 50 global wv_mat wv_mat = np.random.randn(max_vocab + 1, wv_len).astype('float32') * 0.1 #num_classes = np.max( train_y ) + 1 global num_classes num_classes = [] num_classes.append(np.max(train_y[:, 0]) + 1) num_classes.append(np.max(train_y[:, 1]) + 1) num_classes.append(np.max(train_y[:, 2]) + 1) num_classes.append(np.max(train_y[:, 3]) + 1) global validation_data validation_data = ({ 'Input': test_x }, { 'Dense0': test_y[:, 0], 'Dense1': test_y[:, 1], 'Dense2': test_y[:, 2], 'Dense3': test_y[:, 3] }) space = [(1, 10), (1, 10), (1, 10), (5, 500), (0.00001, 0.1)] savepoint = load_results(args.results_dir) hyperdrive(objective=objective, hyperparameters=space, results_path=args.results_dir, model="GP", n_iterations=25, checkpoints=True, verbose=True, random_state=0, restart=savepoint)