Exemplo n.º 1
0
def load_model(MODEL_TYPE):
    curr_model = None
    if MODEL_TYPE == "SVM":
        print("LOADING SVM...")
        curr_model = load("svm.joblib")
    elif MODEL_TYPE == "LR":
        print("LOADING LR...")
        lr = LogReg(74)  #(env.matches.shape[1])
        lr.load_weights("weights/weights-improvement-100-0.31.hdf5")
        curr_model = lr
    elif MODEL_TYPE == "DT":
        print("LOADING DT...")
        curr_model = load("dt.joblib")
    elif MODEL_TYPE == "GB":
        print("LOADING GB...")
        curr_model = load("gb.joblib")
    elif MODEL_TYPE == "RF":
        print("LOADING RF...")
        curr_model = load("rfc.joblib")
    elif MODEL_TYPE == "NB":
        print("LOADING NB...")
        curr_model = load("nb.joblib")
    elif MODEL_TYPE == "AB":
        print("LOADING AB...")
        curr_model = load("ab.joblib")
    elif MODEL_TYPE == "DQN":
        print("LOADING DQN...")
        BetNet = DQNAgent(75)
        BetNet.load("weights/betnet-weights-dqn.h5")
        curr_model = BetNet
    else:
        print("LOADING NN...")
        BetNet = Network(74)  #(env.matches.shape[1])
        BetNet.load_weights(
            'weights/Adadelta/test9_400_Best/weights-improvement-400-0.48.hdf5'
        )  #PCA("weights/Adadelta/test13_100iter_reglast2/weights-improvement-100-0.52.hdf5")  # Most recent weights
        curr_model = BetNet
    return curr_model
Exemplo n.º 2
0
elif MODEL_TYPE == "NB":
    print("LOADING NB...")
    curr_model = load("nb.joblib")
elif MODEL_TYPE == "AB":
    print("LOADING AB...")
    curr_model = load("ab.joblib")
elif MODEL_TYPE == "DQN":
    print("LOADING DQN...")
    BetNet = DQNAgent(75)
    BetNet.load("weights/betnet-weights-dqn.h5")
    curr_model = BetNet
else:
    print("LOADING NN...")
    BetNet = Network(env.matches.shape[1])
    BetNet.load_weights(
        "weights/Adadelta/test13_100iter_reglast2/weights-improvement-100-0.52.hdf5"
    )  # Most recent weights
    curr_model = BetNet

###############################################################################


#GETS THE PREDICTION VEC GIVEN MODEL
def generatePrediction(mt, curr_model, to_process):
    prediction = None
    if mt == "SVM" or mt == "DT" or mt == "GB" or mt == "NB" or mt == "RF" or mt == "AB":
        temp_pred = curr_model.predict(np.asarray(to_process))
        hardmax = np.zeros((1, 3))
        hardmax[0][temp_pred[0]] = 1
        prediction = hardmax[0]
    elif mt == "LR":
Exemplo n.º 3
0
# If you want, you can experiment with the parameters or use a different policy. Another popular one
# is Boltzmann-style exploration:
# policy = BoltzmannQPolicy(tau=1.)
# Feel free to give it a try!

dqn = DQNAgent(model=model, nb_actions=nb_actions, policy=policy, window_length=WINDOW_LENGTH, memory=memory,
               processor=processor, nb_steps_warmup=50000, gamma=.99, delta_range=(-1., 1.),
               target_model_update=10000, train_interval=4)
dqn.compile(Adam(lr=.00025), metrics=['mae'])

if args.mode == 'train':
    # Okay, now it's time to learn something! We capture the interrupt exception so that training
    # can be prematurely aborted. Notice that you can the built-in Keras callbacks!
    weights_filename = 'dqn_{}_weights.h5f'.format(args.env_name)
    checkpoint_weights_filename = 'dqn_' + args.env_name + '_weights_{step}.h5f'
    log_filename = 'dqn_{}_log.json'.format(args.env_name)
    callbacks = [ModelIntervalCheckpoint(checkpoint_weights_filename, interval=250000)]
    callbacks += [FileLogger(log_filename, interval=100)]
    dqn.fit(env, callbacks=callbacks, nb_steps=1750000, log_interval=10000)

    # After training is done, we save the final weights one more time.
    dqn.save_weights(weights_filename, overwrite=True)

    # Finally, evaluate our algorithm for 10 episodes.
    dqn.test(env, nb_episodes=10, visualize=False)
elif args.mode == 'test':
    weights_filename = 'dqn_{}_weights.h5f'.format(args.env_name)
    if args.weights:
        weights_filename = args.weights
    dqn.load_weights(weights_filename)
    dqn.test(env, nb_episodes=10, visualize=True)