Exemple #1
0
def test_too_few_evals():
    X, IncreaseFeature1, IncreaseFeature2, IncreaseFeature3, passed = create_basic_scenario()
    possible_actions = [
        [IncreaseFeature1(i) for i in range(1,10)],
        IncreaseFeature2(5),
        [IncreaseFeature3(i) for i in range(1,20)]
    ]
    optimizer = shap.ActionOptimizer(passed, possible_actions)
    with pytest.raises(ConvergenceError):
        optimizer(X.iloc[0], max_evals=3)
Exemple #2
0
def test_run_out_of_group():
    X, IncreaseFeature1, IncreaseFeature2, IncreaseFeature3, passed = create_basic_scenario()
    possible_actions = [
        [IncreaseFeature1(i) for i in range(1,10)],
        IncreaseFeature2(5),
        [IncreaseFeature3(1)]
    ]
    optimizer = shap.ActionOptimizer(passed, possible_actions)
    actions = optimizer(X.iloc[0])
    print(actions)
    assert len(actions) == 3
Exemple #3
0
def test_basic_run():
    X, IncreaseFeature1, IncreaseFeature2, IncreaseFeature3, passed = create_basic_scenario()
    possible_actions = [
        [IncreaseFeature1(i) for i in range(1,10)],
        IncreaseFeature2(5),
        [IncreaseFeature3(i) for i in range(1,20)]
    ]
    optimizer = shap.ActionOptimizer(passed, possible_actions)
    actions = optimizer(X.iloc[0])
    assert len(actions) == 2
    assert sum(a.cost for a in actions) == 27 # ensure we got the optimal answer
Exemple #4
0
def test_bad_action():
    with pytest.raises(InvalidAction):
        shap.ActionOptimizer(None, [None])