|
| 1 | +# Copyright (c) 2023 The InterpretML Contributors |
| 2 | +# Distributed under the MIT software license |
| 3 | + |
| 4 | +from interpret.glassbox import ( |
| 5 | + ExplainableBoostingClassifier, |
| 6 | + ExplainableBoostingRegressor, |
| 7 | +) |
| 8 | +from interpret.utils import make_synthetic |
| 9 | +from interpret.develop import get_option, set_option |
| 10 | +from interpret.utils._native import Native |
| 11 | + |
| 12 | + |
| 13 | +def test_identical_classification(): |
| 14 | + original = get_option("acceleration") |
| 15 | + set_option("acceleration", 0) |
| 16 | + |
| 17 | + total = 0.0 |
| 18 | + seed = 0 |
| 19 | + for n_classes in range(Native.Task_Regression, 4): |
| 20 | + if n_classes < 2 and n_classes != Native.Task_Regression: |
| 21 | + continue |
| 22 | + |
| 23 | + classes = None if n_classes == Native.Task_Regression else n_classes |
| 24 | + |
| 25 | + for iteration in range(2): |
| 26 | + X, y, names, types = make_synthetic( |
| 27 | + seed=seed, classes=classes, output_type="float", n_samples=257 |
| 28 | + ) |
| 29 | + |
| 30 | + ebm_type = ( |
| 31 | + ExplainableBoostingClassifier |
| 32 | + if 0 <= n_classes |
| 33 | + else ExplainableBoostingRegressor |
| 34 | + ) |
| 35 | + ebm = ebm_type(names, types, random_state=seed, max_rounds=10) |
| 36 | + ebm.fit(X, y) |
| 37 | + |
| 38 | + pred = ebm._predict_score(X) |
| 39 | + total += sum(pred.flat) |
| 40 | + |
| 41 | + seed += 1 |
| 42 | + |
| 43 | + expected = 604.4169336846871 |
| 44 | + |
| 45 | + if total != expected: |
| 46 | + assert total == expected |
| 47 | + |
| 48 | + set_option("acceleration", original) |
0 commit comments