Exemplo n.º 1
0
def test_statsmodels_glm_negativebinomial_link_func():
    estimator = utils.StatsmodelsSklearnLikeWrapper(
        sm.GLM,
        dict(init=dict(
            family=sm.families.NegativeBinomial(sm.families.links.nbinom())),
             fit=dict(maxiter=1)))
    estimator = estimator.fit([[1], [2]], [0.1, 0.2])

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

    expected = ast.BinNumExpr(
        ast.NumVal(-1.0),
        ast.BinNumExpr(
            ast.NumVal(1.0),
            ast.BinNumExpr(
                ast.NumVal(1.0),
                ast.ExpExpr(
                    ast.BinNumExpr(
                        ast.NumVal(0.0),
                        ast.BinNumExpr(
                            ast.NumVal(0.0),
                            ast.BinNumExpr(ast.FeatureRef(0),
                                           ast.NumVal(-1.1079583217),
                                           ast.BinNumOpType.MUL),
                            ast.BinNumOpType.ADD), ast.BinNumOpType.SUB)),
                ast.BinNumOpType.SUB), ast.BinNumOpType.MUL),
        ast.BinNumOpType.DIV)

    assert utils.cmp_exprs(actual, expected)
Exemplo n.º 2
0
def test_statsmodels_glm_unknown_link_func():
    class ValidPowerLink(sm.families.links.Power):
        pass

    estimator = utils.StatsmodelsSklearnLikeWrapper(
        sm.GLM,
        dict(init=dict(family=sm.families.Tweedie(ValidPowerLink(2))),
             fit=dict(maxiter=1)))
    estimator = estimator.fit([[1], [2]], [0.1, 0.2])

    assembler = assemblers.StatsmodelsGLMModelAssembler(estimator)
    assembler.assemble()
Exemplo n.º 3
0
def test_statsmodels_glm_identity_link_func():
    estimator = utils.StatsmodelsSklearnLikeWrapper(
        sm.GLM,
        dict(init=dict(family=sm.families.Tweedie(sm.families.links.Power(1))),
             fit=dict(maxiter=1)))
    estimator = estimator.fit([[1], [2], [3]], [0.1, 0.2, 0.2])

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

    expected = ast.BinNumExpr(
        ast.NumVal(0.0),
        ast.BinNumExpr(ast.FeatureRef(0), ast.NumVal(0.0791304348),
                       ast.BinNumOpType.MUL), ast.BinNumOpType.ADD)

    assert utils.cmp_exprs(actual, expected)
Exemplo n.º 4
0
def test_statsmodels_glm_log_link_func():
    estimator = utils.StatsmodelsSklearnLikeWrapper(
        sm.GLM,
        dict(init=dict(family=sm.families.Poisson(sm.families.links.log())),
             fit=dict(maxiter=1)))
    estimator = estimator.fit([[1], [2]], [0.1, 0.2])

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

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

    assert utils.cmp_exprs(actual, expected)
Exemplo n.º 5
0
def test_statsmodels_glm_inverse_squared_link_func():
    estimator = utils.StatsmodelsSklearnLikeWrapper(
        sm.GLM,
        dict(
            init=dict(family=sm.families.Tweedie(sm.families.links.Power(-2))),
            fit=dict(maxiter=1)))
    estimator = estimator.fit([[1], [2]], [0.1, 0.2])

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

    expected = ast.BinNumExpr(
        ast.NumVal(1.0),
        ast.SqrtExpr(
            ast.BinNumExpr(
                ast.NumVal(0.0),
                ast.BinNumExpr(ast.FeatureRef(0), ast.NumVal(15.1237331741),
                               ast.BinNumOpType.MUL), ast.BinNumOpType.ADD)),
        ast.BinNumOpType.DIV)

    assert utils.cmp_exprs(actual, expected)
Exemplo n.º 6
0
def test_statsmodels_glm_negative_power_link_func():
    estimator = utils.StatsmodelsSklearnLikeWrapper(
        sm.GLM,
        dict(
            init=dict(family=sm.families.Tweedie(sm.families.links.Power(-3))),
            fit=dict(maxiter=1)))
    estimator = estimator.fit([[1], [2]], [0.1, 0.2])

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

    expected = ast.BinNumExpr(
        ast.NumVal(1.0),
        ast.PowExpr(
            ast.BinNumExpr(
                ast.NumVal(0.0),
                ast.BinNumExpr(ast.FeatureRef(0), ast.NumVal(71.0542398846),
                               ast.BinNumOpType.MUL), ast.BinNumOpType.ADD),
            ast.NumVal(0.3333333333)), ast.BinNumOpType.DIV)

    assert utils.cmp_exprs(actual, expected)