Beispiel #1
0
def test_simple_sigmoid_output_transform():
    estimator = lightgbm.LGBMRegressor(n_estimators=2,
                                       random_state=1,
                                       max_depth=1,
                                       objective="cross_entropy")
    utils.get_bounded_regression_model_trainer()(estimator)

    assembler = assemblers.LightGBMModelAssembler(estimator)
    actual = assembler.assemble()

    expected = ast.BinNumExpr(
        ast.NumVal(1),
        ast.BinNumExpr(
            ast.NumVal(1),
            ast.ExpExpr(
                ast.BinNumExpr(
                    ast.NumVal(0),
                    ast.BinNumExpr(
                        ast.IfExpr(
                            ast.CompExpr(ast.FeatureRef(12), ast.NumVal(19.23),
                                         ast.CompOpType.GT),
                            ast.NumVal(4.0026305187),
                            ast.NumVal(4.0880438137)),
                        ast.IfExpr(
                            ast.CompExpr(ast.FeatureRef(12),
                                         ast.NumVal(14.895),
                                         ast.CompOpType.GT),
                            ast.NumVal(-0.0412703078),
                            ast.NumVal(0.0208393767)), ast.BinNumOpType.ADD),
                    ast.BinNumOpType.SUB)), ast.BinNumOpType.ADD),
        ast.BinNumOpType.DIV)

    assert utils.cmp_exprs(actual, expected)
Beispiel #2
0
def test_log1p_exp_output_transform():
    estimator = lgb.LGBMRegressor(n_estimators=2,
                                  random_state=1,
                                  max_depth=1,
                                  objective="cross_entropy_lambda")
    utils.get_bounded_regression_model_trainer()(estimator)

    assembler = LightGBMModelAssembler(estimator)
    actual = assembler.assemble()

    expected = ast.Log1pExpr(
        ast.ExpExpr(
            ast.BinNumExpr(
                ast.IfExpr(
                    ast.CompExpr(ast.FeatureRef(12), ast.NumVal(19.23),
                                 ast.CompOpType.GT),
                    ast.NumVal(0.6622623010380544),
                    ast.NumVal(0.6684065452877841)),
                ast.IfExpr(
                    ast.CompExpr(ast.FeatureRef(12), ast.NumVal(15.145),
                                 ast.CompOpType.GT),
                    ast.NumVal(0.1404975120475147),
                    ast.NumVal(0.14535916856709272)), ast.BinNumOpType.ADD)))

    assert utils.cmp_exprs(actual, expected)
Beispiel #3
0
def test_simple_sigmoid_output_transform():
    estimator = lightgbm.LGBMRegressor(n_estimators=2,
                                       random_state=1,
                                       max_depth=1,
                                       objective="cross_entropy")
    utils.get_bounded_regression_model_trainer()(estimator)

    assembler = assemblers.LightGBMModelAssembler(estimator)
    actual = assembler.assemble()

    expected = ast.BinNumExpr(
        ast.NumVal(1),
        ast.BinNumExpr(
            ast.NumVal(1),
            ast.ExpExpr(
                ast.BinNumExpr(
                    ast.NumVal(0),
                    ast.BinNumExpr(
                        ast.IfExpr(
                            ast.CompExpr(ast.FeatureRef(12), ast.NumVal(19.23),
                                         ast.CompOpType.GT),
                            ast.NumVal(4.0050691250),
                            ast.NumVal(4.0914737728)),
                        ast.IfExpr(
                            ast.CompExpr(ast.FeatureRef(12),
                                         ast.NumVal(15.065),
                                         ast.CompOpType.GT),
                            ast.NumVal(-0.0420531079),
                            ast.NumVal(0.0202891577)), ast.BinNumOpType.ADD),
                    ast.BinNumOpType.SUB)), ast.BinNumOpType.ADD),
        ast.BinNumOpType.DIV)

    assert utils.cmp_exprs(actual, expected)
Beispiel #4
0
def test_simple_sigmoid_output_transform():
    estimator = lightgbm.LGBMRegressor(n_estimators=2,
                                       random_state=1,
                                       max_depth=1,
                                       objective="cross_entropy")
    utils.get_bounded_regression_model_trainer()(estimator)

    assembler = assemblers.LightGBMModelAssembler(estimator)
    actual = assembler.assemble()

    expected = ast.BinNumExpr(
        ast.NumVal(1),
        ast.BinNumExpr(
            ast.NumVal(1),
            ast.ExpExpr(
                ast.BinNumExpr(
                    ast.NumVal(0),
                    ast.BinNumExpr(
                        ast.IfExpr(
                            ast.CompExpr(ast.FeatureRef(12), ast.NumVal(19.23),
                                         ast.CompOpType.GT),
                            ast.NumVal(4.002437528537838),
                            ast.NumVal(4.090096709787509)),
                        ast.IfExpr(
                            ast.CompExpr(ast.FeatureRef(12),
                                         ast.NumVal(14.895),
                                         ast.CompOpType.GT),
                            ast.NumVal(-0.0417499606641773),
                            ast.NumVal(0.02069953712454655)),
                        ast.BinNumOpType.ADD), ast.BinNumOpType.SUB)),
            ast.BinNumOpType.ADD), ast.BinNumOpType.DIV)

    assert utils.cmp_exprs(actual, expected)
Beispiel #5
0
def test_log1p_exp_output_transform():
    estimator = lightgbm.LGBMRegressor(n_estimators=2, random_state=1,
                                       max_depth=1,
                                       objective="cross_entropy_lambda")
    utils.get_bounded_regression_model_trainer()(estimator)

    assembler = assemblers.LightGBMModelAssembler(estimator)
    actual = assembler.assemble()

    expected = ast.Log1pExpr(
        ast.ExpExpr(
            ast.BinNumExpr(
                ast.IfExpr(
                    ast.CompExpr(
                        ast.FeatureRef(12),
                        ast.NumVal(19.23),
                        ast.CompOpType.GT),
                    ast.NumVal(0.6623502468),
                    ast.NumVal(0.6683497987)),
                ast.IfExpr(
                    ast.CompExpr(
                        ast.FeatureRef(12),
                        ast.NumVal(15.145),
                        ast.CompOpType.GT),
                    ast.NumVal(0.1405181490),
                    ast.NumVal(0.1453602134)),
                ast.BinNumOpType.ADD)))

    assert utils.cmp_exprs(actual, expected)
Beispiel #6
0
def regression_bounded(model, test_fraction=0.02):
    return (
        model,
        utils.get_bounded_regression_model_trainer(test_fraction),
        REGRESSION,
    )