Exemplo n.º 1
0
def train(search=True):
    # read data
    x_train, y_train, feature_names = util.read_train_data()

    #todo correct
    x_train[np.isinf(x_train)] = 1
    y_train[np.isinf(y_train)] = 1

    np.nan_to_num(x_train)
    np.nan_to_num(y_train)

    x_train = x_train.astype(np.float32)
    y_train = y_train.astype(np.float32)

    # set model
    if search:
        model = find_best_model()
    else:
        model = XGBRegressor()

    # train
    timer = Timer()
    model.fit(x_train, y_train)
    timer.end()

    # save
    save_model(model)

    return model
Exemplo n.º 2
0
def train(search=True):
    # read data
    x_train, y_train, feature_names = util.read_train_data()

    # model
    if search:
        model = find_best_model()
    else:
        model = RandomForestRegressor()

    # train
    timer = Timer()
    model.fit(x_train, y_train)
    timer.end()

    if search:
        print("\nBest parameters:\n")
        for param in model.best_params_:
            print("{}: {}".format(param, model.best_params_[param]))
        print()

    # save
    save_model(model)

    return model
Exemplo n.º 3
0
def train():
    # read data
    x_train, y_train, feature_names = util.read_train_data()

    # model
    model = BayesianRidge()

    # train
    timer = Timer()
    model.fit(x_train, y_train)
    timer.end()

    # save
    save_model(model)

    return model
def train():
    # read data
    x_train, y_train, feature_names = util.read_train_data()

    # model
    model = LogisticRegression()

    # train
    timer = Timer()
    model.fit(x_train, y_train)
    timer.end()

    # save
    save_model(model)

    return model
def train(neurons=[10],
          epochs=50,
          retrain=None,
          optimizer="adadelta",
          train_path=settings.DATASET_TRAIN_PATH,
          test_path=settings.DATASET_TEST_PATH):

    # read data
    print(train_path)
    x_train, y_train, feature_names = util.read_train_data(path=train_path)
    x_test, y_test, feature_names = util.read_test_data(path=test_path)

    # get model
    if retrain is None:
        # get model
        input_size = x_train.shape[1]

        if len(y_train.shape) == 1:
            output_size = 1
        else:
            output_size = y_train.shape[1]

        model = get_model(input_size,
                          output_size,
                          neurons=neurons,
                          optimizer=optimizer)
    else:
        model = retrain

    # train
    timer = Timer()
    history = model.fit(x_train,
                        y_train,
                        validation_data=(x_test, y_test),
                        epochs=epochs,
                        batch_size=12)
    timer.end()
    # graphs
    #visualization.accuracy__graph(history.history)
    #visualization.model_loss_graph(history.history)

    # save model
    save_model(model)

    return model
Exemplo n.º 6
0
def test_models(init, final, sep=1, epochs=10):
    # read data
    x_train, y_train, _ = util.read_train_data()
    x_test, y_test, _ = util.read_test_data()

    historys = []
    for i in range(init, final + 1, sep):
        print("\nNeurons {} - start".format(i))

        model, neurons, history = _test_model([i], epochs, x_train, y_train,
                                              x_test, y_test)
        historys.append((neurons, history))

        save_model(model, sufix="_" + str(i))

        print("Neurons {} - done".format(i))

    pickle.dump(historys, open(HISTORYS_FILE, 'wb'))
Exemplo n.º 7
0
def train(max_depth=None, max_leaf_nodes=None, search=True):
    """

    :param max_depth:
    :param max_leaf_nodes:
    :return:
    """

    # read data
    x_train, y_train, feature_names = util.read_train_data()

    # set model
    if search:
        model = find_best_model()
    else:
        model = DecisionTreeRegressor(random_state=0,
                                      max_depth=max_depth,
                                      max_leaf_nodes=max_leaf_nodes)

    # train
    timer = Timer()
    model.fit(x_train, y_train)
    timer.end()

    if search:
        #print("\nAll Results:\n")
        #results = pd.DataFrame(model.cv_results_)
        #dskc_terminal.markdown_table(results)

        print("\nBest parameters:\n")
        for param in model.best_params_:
            print("{}: {}".format(param, model.best_params_[param]))
        print()

    # save graph
    # _save_tree_graph(model, feature_names)

    save_model(model)

    return model