コード例 #1
0
def refactored_pipeline():
    """You should import the refactored methods here"""

    # Step 1
    # You should put the `load` method here:
    X_train, X_test, y_train, y_test = src.load()

    # Step 2
    # You should put the `train` method here:
    model, train_score = src.train(X_train, y_train)

    # Step 3
    # You should put the `evaluate` method here:
    test_score = src.evaluate(model, X_test, y_test)

    # Final Step
    # Return the train_score and test_score
    return train_score, test_score
コード例 #2
0
            agent = A2C(env_pool, net, device, optimizer, args.entropy_reg, writer,
                        args.rollout_len, args.normalize_advantage, args.gamma)
        elif args.agent == 'PPO':
            agent = PPO(env_pool, net, device, optimizer, args.entropy_reg, writer,
                        args.rollout_len, args.normalize_advantage,
                        args.ppo_batch_size, args.num_ppo_epochs, args.ppo_eps, args.gae_lambda,
                        args.gamma)
        else:
            raise BaseException('wrong agent')

    # training:
    if args.train_steps > 0:
        print('========================= training ===========================')
        agent.train(args.train_steps)
        try:
            os.mkdir('./checkpoints/' + args.environment + '/')
        except FileExistsError:
            pass
        checkpoint = 'checkpoints/' + args.environment + '/' + args.agent + '.pth'
        save(agent, checkpoint)
        print('Training done. Checkpoint saved in \'{}\''.format(checkpoint))

    if args.watch > 0:
        if args.train_steps == 0:
            checkpoint = 'checkpoints/' + args.environment + '/' + args.agent + '.pth'
            load(checkpoint, agent)
        print('========================= watching ===========================')
        for _ in range(args.watch):
            print(play_episode(environment, agent, True))
    environment.close()
コード例 #3
0
def test_load_return_length():
    """Test that load return an iterable of length 4"""
    output = src.load()
    assert output
コード例 #4
0
def test_evaluate():
    """Test that evaluate returns a float"""
    X_train, X_test, y_train, y_test = src.load()
    clf, score = src.train(X_train, y_train)
    test_score = src.evaluate(clf, X_test, y_test)
    assert isinstance(test_score, float)
コード例 #5
0
def test_train(C, gamma):
    """Test that train returns the expected types"""
    X_train, X_test, y_train, y_test = src.load()
    clf, score = src.train(X_train, y_train)
    assert isinstance(clf, svm.SVC)
    assert isinstance(score, float)
コード例 #6
0
def test_load_return_shape(size):
    """Test that the return shapes are correct"""
    X_train, X_test, y_train, y_test = src.load(train_size=size)
    num_samples = 1797
    assert X_train.shape == (int(num_samples * size), 64)
    assert X_test.shape == (int(num_samples * (1 - size)) + 1, 64)