-
-
Notifications
You must be signed in to change notification settings - Fork 554
/
test_bar.py
147 lines (121 loc) · 4.08 KB
/
test_bar.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# tests.test_contrib.test_missing.test_bar
# Tests for the alpha selection visualizations.
#
# Author: Nathan Danielsen <nathan.danielsen@gmail.com>
# Created: Thu Mar 29 12:13:04 2018 -0500
#
# Copyright (C) 2018 The scikit-yb developers
# For license information, see LICENSE.txt
#
# ID: test_bar.py [1443e16] ndanielsen@users.noreply.github.com $
"""
Tests for the MissingValuesBar visualizations.
"""
##########################################################################
## Imports
##########################################################################
import os
import pytest
import numpy as np
from tests.base import VisualTestCase
from sklearn.datasets import make_classification
from yellowbrick.contrib.missing.bar import *
try:
import pandas as pd
except ImportError:
pd = None
@pytest.fixture(scope="class")
def missing_bar_tolerance(request):
request.cls.tol = 0.5 if os.name == "nt" else 0.01
##########################################################################
## Feature Importances Tests
##########################################################################
@pytest.mark.usefixtures("missing_bar_tolerance")
class TestMissingBarVisualizer(VisualTestCase):
"""
FeatureImportances visualizer
"""
@pytest.mark.skipif(pd is None, reason="pandas is required")
def test_missingvaluesbar_pandas(self):
"""
Integration test of visualizer with pandas
"""
X, y = make_classification(
n_samples=400,
n_features=20,
n_informative=8,
n_redundant=8,
n_classes=2,
n_clusters_per_class=4,
random_state=854,
)
# add nan values to a range of values in the matrix
X[X > 1.5] = np.nan
X_ = pd.DataFrame(X)
features = [str(n) for n in range(20)]
viz = MissingValuesBar(features=features)
viz.fit(X_)
viz.finalize()
self.assert_images_similar(viz, tol=self.tol)
def test_missingvaluesbar_numpy(self):
"""
Integration test of visualizer with numpy without target y passed in
"""
X, y = make_classification(
n_samples=400,
n_features=20,
n_informative=8,
n_redundant=8,
n_classes=2,
n_clusters_per_class=4,
random_state=856,
)
# add nan values to a range of values in the matrix
X[X > 1.5] = np.nan
features = [str(n) for n in range(20)]
viz = MissingValuesBar(features=features)
viz.fit(X)
viz.finalize()
self.assert_images_similar(viz, tol=self.tol)
def test_missingvaluesbar_numpy_with_y_target(self):
"""
Integration test of visualizer with numpy without target y passed in
but no class labels
"""
X, y = make_classification(
n_samples=400,
n_features=20,
n_informative=8,
n_redundant=8,
n_classes=2,
n_clusters_per_class=4,
random_state=856,
)
# add nan values to a range of values in the matrix
X[X > 1.5] = np.nan
features = [str(n) for n in range(20)]
viz = MissingValuesBar(features=features)
viz.fit(X, y)
viz.finalize()
self.assert_images_similar(viz, tol=self.tol)
def test_missingvaluesbar_numpy_with_y_target_with_labels(self):
"""
Integration test of visualizer with numpy without target y passed in
but no class labels
"""
X, y = make_classification(
n_samples=400,
n_features=20,
n_informative=8,
n_redundant=8,
n_classes=2,
n_clusters_per_class=4,
random_state=856,
)
# add nan values to a range of values in the matrix
X[X > 1.5] = np.nan
features = [str(n) for n in range(20)]
viz = MissingValuesBar(features=features, classes=["class A", "class B"])
viz.fit(X, y)
viz.finalize()
self.assert_images_similar(viz, tol=self.tol)