def _fit_model(population_df, peripheral_df, population_ph, peripheral_ph, seed, units):

    # ----------------------------------------------------------------
    
    predictor = predictors.LinearRegression()
    
    # ----------------------------------------------------------------
    
    model = models.MultirelModel(
        aggregation=[
            aggregations.Count,
            aggregations.Sum
        ],
        population=population_ph,
        peripheral=[peripheral_ph],
        loss_function=loss_functions.SquareLoss(),
        predictor=predictor,
        num_features=10,
        share_aggregations=1.0,
        max_length=3,
        num_threads=1,
        seed=seed,
        units=units
    ).send()

    # ----------------------------------------------------------------

    model = model.fit(
        population_table=population_df,
        peripheral_tables=[peripheral_df]
    )
    
    # ----------------------------------------------------------------

    features = model.transform(
        population_table=population_df,
        peripheral_tables=[peripheral_df]
    )

    # ----------------------------------------------------------------

    yhat = model.predict(
        population_table=population_df,
        peripheral_tables=[peripheral_df]
    )

    # ----------------------------------------------------------------

    scores = model.score(
        population_table=population_df,
        peripheral_tables=[peripheral_df]
    )

    # ----------------------------------------------------------------
    
    return model, features, yhat, scores
Esempio n. 2
0
def _fit_model(population_df, peripheral_df, population_ph, peripheral_ph,
               seed, units):

    # ----------------------------------------------------------------

    predictor = predictors.LinearRegression()

    # ----------------------------------------------------------------

    model = models.RelboostModel(population=population_ph,
                                 peripheral=[peripheral_ph],
                                 loss_function=loss_functions.SquareLoss(),
                                 predictor=predictor,
                                 num_features=10,
                                 max_depth=1,
                                 reg_lambda=0.0,
                                 shrinkage=0.3,
                                 num_threads=1,
                                 seed=seed,
                                 units=units).send()

    # ----------------------------------------------------------------

    model = model.fit(population_table=population_df,
                      peripheral_tables=[peripheral_df])

    # ----------------------------------------------------------------

    features = model.transform(population_table=population_df,
                               peripheral_tables=[peripheral_df])

    # ----------------------------------------------------------------

    yhat = model.predict(population_table=population_df,
                         peripheral_tables=[peripheral_df])

    # ----------------------------------------------------------------

    scores = model.score(population_table=population_df,
                         peripheral_tables=[peripheral_df])

    # ----------------------------------------------------------------

    return model, features, yhat, scores
# FROM POPULATION t1
# LEFT JOIN PERIPHERAL t2
# ON t1.join_key = t2.join_key
# WHERE (
#    ( t1.time_stamp - t2.time_stamp <= 0.5 )
# ) AND t2.time_stamp <= t1.time_stamp
# GROUP BY t1.join_key,
#          t1.time_stamp;

population_table, peripheral_table = datasets.make_numerical()

population_placeholder = population_table.to_placeholder()
peripheral_placeholder = peripheral_table.to_placeholder()
population_placeholder.join(peripheral_placeholder, "join_key", "time_stamp")

predictor = predictors.LinearRegression()

model = models.RelboostModel(population=population_placeholder,
                             peripheral=[peripheral_placeholder],
                             loss_function=loss_functions.SquareLoss(),
                             predictor=predictor,
                             num_features=10,
                             max_depth=1,
                             reg_lambda=0.0,
                             shrinkage=0.3,
                             num_threads=0).send()

# ----------------

model = model.fit(population_table=population_table,
                  peripheral_tables=[peripheral_table])