Beispiel #1
0
def test_sklearn_glm_unknown_link_func():
    estimator = linear_model.TweedieRegressor(
        power=1, link="this_link_func_does_not_exist", max_iter=10)
    estimator = estimator.fit([[1], [2]], [0.1, 0.2])

    assembler = assemblers.SklearnGLMModelAssembler(estimator)
    assembler.assemble()
Beispiel #2
0
def test_sklearn_glm_identity_link_func():
    estimator = linear_model.TweedieRegressor(power=0,
                                              link="identity",
                                              max_iter=10)
    estimator = estimator.fit([[1], [2]], [0.1, 0.2])

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

    expected = ast.BinNumExpr(
        ast.NumVal(0.12),
        ast.BinNumExpr(ast.FeatureRef(0), ast.NumVal(0.02),
                       ast.BinNumOpType.MUL), ast.BinNumOpType.ADD)

    assert utils.cmp_exprs(actual, expected)
Beispiel #3
0
def test_sklearn_glm_log_link_func():
    estimator = linear_model.TweedieRegressor(power=1, link="log", fit_intercept=False, max_iter=10)
    estimator = estimator.fit([[1], [2]], [0.1, 0.2])

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

    expected = ast.ExpExpr(
        ast.BinNumExpr(
            ast.NumVal(0.0),
            ast.BinNumExpr(
                ast.FeatureRef(0),
                ast.NumVal(-0.4619711397),
                ast.BinNumOpType.MUL),
            ast.BinNumOpType.ADD))

    assert utils.cmp_exprs(actual, expected)