-
Notifications
You must be signed in to change notification settings - Fork 331
/
Copy pathtest_ipython.py
69 lines (54 loc) · 1.84 KB
/
test_ipython.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
import pytest
pytest.importorskip('IPython')
import numpy as np
from sklearn.linear_model import LogisticRegression
from IPython.display import HTML
import eli5
from .utils import write_html
def test_show_weights():
clf = LogisticRegression()
X = [[0, 0], [1, 1], [0, 1]]
y = ['a', 'b', 'a']
clf.fit(X, y)
html = eli5.show_weights(clf)
# write_html(clf, html.data, '')
assert isinstance(html, HTML)
assert 'y=b' in html.data
assert 'Explained as' not in html.data
# explain_weights arguments are supported
html = eli5.show_weights(clf, target_names=['A', 'B'])
assert 'y=B' in html.data
# format_as_html arguments are supported
html = eli5.show_weights(clf, show=['method'])
assert 'y=b' not in html.data
assert 'Explained as' in html.data
def test_show_prediction():
clf = LogisticRegression(C=100)
X = [[0, 0], [1, 1], [0, 1]]
y = ['a', 'b', 'a']
clf.fit(X, y)
doc = np.array([0, 1])
html = eli5.show_prediction(clf, doc)
write_html(clf, html.data, '')
assert isinstance(html, HTML)
assert 'y=a' in html.data
assert 'BIAS' in html.data
assert 'x1' in html.data
# explain_prediction arguments are supported
html = eli5.show_prediction(clf, doc, feature_names=['foo', 'bar'])
write_html(clf, html.data, '')
assert 'x1' not in html.data
assert 'bar' in html.data
# format_as_html arguments are supported
html = eli5.show_prediction(clf, doc, show=['method'])
write_html(clf, html.data, '')
assert 'y=a' not in html.data
assert 'BIAS' not in html.data
assert 'Explained as' in html.data
# top target is used
html = eli5.show_prediction(clf, np.array([1, 1]))
write_html(clf, html.data, '')
assert 'y=b' in html.data
assert 'BIAS' in html.data
assert 'x1' in html.data