def train_optimal_action_given_history_obs(
        model,
        target_history,
        target_stocks,
        window_length,
        weight_path='weights/imitation_3_stocks.h5'):
    nb_classes = len(target_stocks) + 1
    (X_train, y_train), (X_validation,
                         y_validation) = create_imitation_dataset(
                             target_history, window_length)
    Y_train = np_utils.to_categorical(y_train, nb_classes)
    Y_validation = np_utils.to_categorical(y_validation, nb_classes)
    X_train = np.expand_dims(X_train, axis=-1)
    X_validation = np.expand_dims(X_validation, axis=-1)
    continue_train = True
    while continue_train:
        model.fit(X_train,
                  Y_train,
                  batch_size=128,
                  epochs=100,
                  validation_data=(X_validation, Y_validation),
                  shuffle=True)
        save_weights = input('Type True to save weights\n')
        if save_weights:
            model.save(weight_path)
        continue_train = input(
            "True to continue train, otherwise stop training...\n")
                        required=True)

    args = vars(parser.parse_args())

    pprint.pprint(args)

    assert args['predictor_type'] in ['CNN', 'LSTM']

    window_length = int(args['window_length'])

    model_path = 'weights/{}.h5'.format(
        get_model_name(args['predictor_type'], window_length))

    if args['predictor_type'] == 'CNN':
        model = StockCNN(nb_classes, window_length, model_path)
    else:
        model = StockLSTM(nb_classes, window_length, model_path)

    model.build_model(load_weights=False)
    (X_train, y_train), (X_validation,
                         y_validation) = create_imitation_dataset(
                             target_history, window_length)
    Y_train = np_utils.to_categorical(y_train, nb_classes)
    Y_validation = np_utils.to_categorical(y_validation, nb_classes)

    if args['predictor_type'] == 'CNN':
        X_train = np.expand_dims(X_train, axis=-1)
        X_validation = np.expand_dims(X_validation, axis=-1)

    model.train(X_train, Y_train, X_validation, Y_validation)