Skip to content

Commit 1d62b0c

Browse files
glemaitrechkoar
authored andcommitted
DOC: Remove seaborn dependencies (scikit-learn-contrib#264)
1 parent 9df7b06 commit 1d62b0c

34 files changed

+664
-891
lines changed

build_tools/circle/push_doc.sh

100644100755
File mode changed.

doc/whats_new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Enhancement
2222
been derived from scikit-learn. By `Guillaume Lemaitre`_.
2323
- Script for automatic build of conda packages and uploading. By
2424
`Guillaume Lemaitre`_
25+
- Remove seaborn dependence and improve the examples. By `Guillaume
26+
Lemaitre`_.
2527

2628
API changes summary
2729
~~~~~~~~~~~~~~~~~~~

examples/applications/plot_multi_class_under_sampling.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
1010
"""
1111

12+
# Authors: Guillaume Lemaitre <[email protected]>
13+
# License: MIT
14+
1215
from sklearn.datasets import load_iris
1316
from sklearn.svm import LinearSVC
1417
from sklearn.model_selection import train_test_split

examples/applications/plot_over_sampling_benchmark_lfw.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
1212
"""
1313

14+
# Authors: Christos Aridas
15+
# Guillaume Lemaitre <[email protected]>
16+
# License: MIT
17+
1418
import matplotlib.pyplot as plt
1519
import numpy as np
1620
from scipy import interp
@@ -69,6 +73,8 @@ def fit_sample(self, X, y):
6973
for sampler in samplers
7074
]
7175

76+
fig = plt.figure()
77+
ax = fig.add_subplot(1, 1, 1)
7278

7379
for name, pipeline in pipelines:
7480
mean_tpr = 0.0
@@ -86,14 +92,22 @@ def fit_sample(self, X, y):
8692
plt.plot(mean_fpr, mean_tpr, linestyle='--',
8793
label='{} (area = %0.2f)'.format(name) % mean_auc, lw=LW)
8894

89-
plt.xlim([-0.05, 1.05])
90-
plt.ylim([-0.05, 1.05])
91-
plt.xlabel('False Positive Rate')
92-
plt.ylabel('True Positive Rate')
93-
plt.title('Receiver operating characteristic example')
94-
plt.legend(loc="lower right")
95-
9695
plt.plot([0, 1], [0, 1], linestyle='--', lw=LW, color='k',
9796
label='Luck')
9897

98+
# make nice plotting
99+
ax.spines['top'].set_visible(False)
100+
ax.spines['right'].set_visible(False)
101+
ax.get_xaxis().tick_bottom()
102+
ax.get_yaxis().tick_left()
103+
ax.spines['left'].set_position(('outward', 10))
104+
ax.spines['bottom'].set_position(('outward', 10))
105+
plt.xlim([0, 1])
106+
plt.ylim([0, 1])
107+
plt.xlabel('False Positive Rate')
108+
plt.ylabel('True Positive Rate')
109+
plt.title('Receiver operating characteristic example')
110+
111+
plt.legend(loc="lower right")
112+
99113
plt.show()

examples/combine/plot_smote_enn.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,23 @@
77
88
"""
99

10+
# Authors: Christos Aridas
11+
# Guillaume Lemaitre <[email protected]>
12+
# License: MIT
13+
1014
import matplotlib.pyplot as plt
11-
import seaborn as sns
1215
from sklearn.datasets import make_classification
1316
from sklearn.decomposition import PCA
1417

1518
from imblearn.combine import SMOTEENN
1619

1720
print(__doc__)
1821

19-
sns.set()
20-
21-
# Define some color for the plotting
22-
almost_black = '#262626'
23-
palette = sns.color_palette()
24-
25-
2622
# Generate the dataset
2723
X, y = make_classification(n_classes=2, class_sep=2, weights=[0.1, 0.9],
2824
n_informative=3, n_redundant=1, flip_y=0,
2925
n_features=20, n_clusters_per_class=1,
30-
n_samples=5000, random_state=10)
26+
n_samples=100, random_state=10)
3127

3228
# Instanciate a PCA object for the sake of easy visualisation
3329
pca = PCA(n_components=2)
@@ -42,18 +38,30 @@
4238
# Two subplots, unpack the axes array immediately
4339
f, (ax1, ax2) = plt.subplots(1, 2)
4440

45-
ax1.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0", alpha=0.5,
46-
edgecolor=almost_black, facecolor=palette[0], linewidth=0.15)
47-
ax1.scatter(X_vis[y == 1, 0], X_vis[y == 1, 1], label="Class #1", alpha=0.5,
48-
edgecolor=almost_black, facecolor=palette[2], linewidth=0.15)
41+
c0 = ax1.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0",
42+
alpha=0.5)
43+
c1 = ax1.scatter(X_vis[y == 1, 0], X_vis[y == 1, 1], label="Class #1",
44+
alpha=0.5)
4945
ax1.set_title('Original set')
5046

5147
ax2.scatter(X_res_vis[y_resampled == 0, 0], X_res_vis[y_resampled == 0, 1],
52-
label="Class #0", alpha=.5, edgecolor=almost_black,
53-
facecolor=palette[0], linewidth=0.15)
48+
label="Class #0", alpha=0.5)
5449
ax2.scatter(X_res_vis[y_resampled == 1, 0], X_res_vis[y_resampled == 1, 1],
55-
label="Class #1", alpha=.5, edgecolor=almost_black,
56-
facecolor=palette[2], linewidth=0.15)
50+
label="Class #1", alpha=0.5)
5751
ax2.set_title('SMOTE + ENN')
5852

53+
# make nice plotting
54+
for ax in (ax1, ax2):
55+
ax.spines['top'].set_visible(False)
56+
ax.spines['right'].set_visible(False)
57+
ax.get_xaxis().tick_bottom()
58+
ax.get_yaxis().tick_left()
59+
ax.spines['left'].set_position(('outward', 10))
60+
ax.spines['bottom'].set_position(('outward', 10))
61+
ax.set_xlim([-6, 8])
62+
ax.set_ylim([-6, 6])
63+
64+
f.legend((c0, c1), ('Class #0', 'Class #1'), loc='lower center',
65+
ncol=2, labelspacing=0.)
66+
plt.tight_layout(pad=3)
5967
plt.show()

examples/combine/plot_smote_tomek.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,23 @@
77
88
"""
99

10+
# Authors: Christos Aridas
11+
# Guillaume Lemaitre <[email protected]>
12+
# License: MIT
13+
1014
import matplotlib.pyplot as plt
11-
import seaborn as sns
1215
from sklearn.datasets import make_classification
1316
from sklearn.decomposition import PCA
1417

1518
from imblearn.combine import SMOTETomek
1619

1720
print(__doc__)
1821

19-
sns.set()
20-
21-
# Define some color for the plotting
22-
almost_black = '#262626'
23-
palette = sns.color_palette()
24-
25-
2622
# Generate the dataset
2723
X, y = make_classification(n_classes=2, class_sep=2, weights=[0.1, 0.9],
2824
n_informative=3, n_redundant=1, flip_y=0,
2925
n_features=20, n_clusters_per_class=1,
30-
n_samples=5000, random_state=10)
26+
n_samples=100, random_state=10)
3127

3228
# Instanciate a PCA object for the sake of easy visualisation
3329
pca = PCA(n_components=2)
@@ -42,18 +38,30 @@
4238
# Two subplots, unpack the axes array immediately
4339
f, (ax1, ax2) = plt.subplots(1, 2)
4440

45-
ax1.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0", alpha=0.5,
46-
edgecolor=almost_black, facecolor=palette[0], linewidth=0.15)
47-
ax1.scatter(X_vis[y == 1, 0], X_vis[y == 1, 1], label="Class #1", alpha=0.5,
48-
edgecolor=almost_black, facecolor=palette[2], linewidth=0.15)
41+
c0 = ax1.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0",
42+
alpha=0.5)
43+
c1 = ax1.scatter(X_vis[y == 1, 0], X_vis[y == 1, 1], label="Class #1",
44+
alpha=0.5)
4945
ax1.set_title('Original set')
5046

5147
ax2.scatter(X_res_vis[y_resampled == 0, 0], X_res_vis[y_resampled == 0, 1],
52-
label="Class #0", alpha=.5, edgecolor=almost_black,
53-
facecolor=palette[0], linewidth=0.15)
48+
label="Class #0", alpha=0.5)
5449
ax2.scatter(X_res_vis[y_resampled == 1, 0], X_res_vis[y_resampled == 1, 1],
55-
label="Class #1", alpha=.5, edgecolor=almost_black,
56-
facecolor=palette[2], linewidth=0.15)
50+
label="Class #1", alpha=0.5)
5751
ax2.set_title('SMOTE + Tomek')
5852

53+
# make nice plotting
54+
for ax in (ax1, ax2):
55+
ax.spines['top'].set_visible(False)
56+
ax.spines['right'].set_visible(False)
57+
ax.get_xaxis().tick_bottom()
58+
ax.get_yaxis().tick_left()
59+
ax.spines['left'].set_position(('outward', 10))
60+
ax.spines['bottom'].set_position(('outward', 10))
61+
ax.set_xlim([-6, 8])
62+
ax.set_ylim([-6, 6])
63+
64+
plt.figlegend((c0, c1), ('Class #0', 'Class #1'), loc='lower center',
65+
ncol=2, labelspacing=0.)
66+
plt.tight_layout(pad=3)
5967
plt.show()

examples/datasets/plot_make_imbalance.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,27 @@
77
88
"""
99

10+
# Authors: Dayvid Oliveira
11+
# Christos Aridas
12+
# Guillaume Lemaitre <[email protected]>
13+
# License: MIT
14+
1015
import matplotlib.pyplot as plt
11-
import seaborn as sns
1216
from sklearn.datasets import make_moons
1317

1418
from imblearn.datasets import make_imbalance
1519

1620
print(__doc__)
1721

18-
sns.set()
1922

20-
# Define some color for the plotting
21-
almost_black = '#262626'
22-
palette = sns.color_palette()
23+
def plot_decoration(ax):
24+
ax.spines['top'].set_visible(False)
25+
ax.spines['right'].set_visible(False)
26+
ax.get_xaxis().tick_bottom()
27+
ax.get_yaxis().tick_left()
28+
ax.spines['left'].set_position(('outward', 10))
29+
ax.spines['bottom'].set_position(('outward', 10))
30+
ax.set_xlim([-4, 4])
2331

2432

2533
# Generate the dataset
@@ -30,27 +38,20 @@
3038

3139
axs = [a for ax in axs for a in ax]
3240

33-
axs[0].scatter(X[y == 0, 0], X[y == 0, 1], label="Class #0",
34-
alpha=0.5, edgecolor=almost_black, facecolor=palette[0],
35-
linewidth=0.15)
36-
axs[0].scatter(X[y == 1, 0], X[y == 1, 1], label="Class #1",
37-
alpha=0.5, edgecolor=almost_black, facecolor=palette[2],
38-
linewidth=0.15)
41+
axs[0].scatter(X[y == 0, 0], X[y == 0, 1], label="Class #0", alpha=0.5)
42+
axs[0].scatter(X[y == 1, 0], X[y == 1, 1], label="Class #1", alpha=0.5)
3943
axs[0].set_title('Original set')
44+
plot_decoration(axs[0])
4045

4146
ratios = [0.9, 0.75, 0.5, 0.25, 0.1]
4247
for i, ratio in enumerate(ratios, start=1):
4348
ax = axs[i]
4449

4550
X_, y_ = make_imbalance(X, y, ratio=ratio, min_c_=1)
46-
47-
ax.scatter(X_[y_ == 0, 0], X_[y_ == 0, 1], label="Class #0",
48-
alpha=0.5, edgecolor=almost_black, facecolor=palette[0],
49-
linewidth=0.15)
50-
ax.scatter(X_[y_ == 1, 0], X_[y_ == 1, 1], label="Class #1",
51-
alpha=0.5, edgecolor=almost_black, facecolor=palette[2],
52-
linewidth=0.15)
53-
ax.set_title('make_imbalance ratio ({})'.format(ratio))
51+
ax.scatter(X_[y_ == 0, 0], X_[y_ == 0, 1], label="Class #0", alpha=0.5)
52+
ax.scatter(X_[y_ == 1, 0], X_[y_ == 1, 1], label="Class #1", alpha=0.5)
53+
ax.set_title('ratio = {}'.format(ratio))
54+
plot_decoration(ax)
5455

5556
plt.tight_layout()
5657
plt.show()

examples/ensemble/plot_balance_cascade.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,23 @@
77
88
"""
99

10+
# Authors: Christos Aridas
11+
# Guillaume Lemaitre <[email protected]>
12+
# License: MIT
13+
1014
import matplotlib.pyplot as plt
11-
import numpy as np
12-
import seaborn as sns
1315
from sklearn.datasets import make_classification
1416
from sklearn.decomposition import PCA
1517

1618
from imblearn.ensemble import BalanceCascade
1719

1820
print(__doc__)
1921

20-
sns.set()
21-
22-
# Define some color for the plotting
23-
almost_black = '#262626'
24-
palette = sns.color_palette()
25-
26-
2722
# Generate the dataset
28-
X, y = make_classification(n_classes=2, class_sep=2, weights=[0.1, 0.9],
23+
X, y = make_classification(n_classes=2, class_sep=2, weights=[0.3, 0.7],
2924
n_informative=3, n_redundant=1, flip_y=0,
3025
n_features=20, n_clusters_per_class=1,
31-
n_samples=5000, random_state=10)
26+
n_samples=200, random_state=10)
3227

3328
# Instanciate a PCA object for the sake of easy visualisation
3429
pca = PCA(n_components=2)
@@ -45,18 +40,27 @@
4540
# Two subplots, unpack the axes array immediately
4641
f, (ax1, ax2) = plt.subplots(1, 2)
4742

48-
ax1.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0", alpha=0.5,
49-
edgecolor=almost_black, facecolor=palette[0], linewidth=0.15)
50-
ax1.scatter(X_vis[y == 1, 0], X_vis[y == 1, 1], label="Class #1", alpha=0.5,
51-
edgecolor=almost_black, facecolor=palette[2], linewidth=0.15)
43+
ax1.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0", alpha=0.5)
44+
ax1.scatter(X_vis[y == 1, 0], X_vis[y == 1, 1], label="Class #1", alpha=0.5)
5245
ax1.set_title('Original set')
5346

54-
ax2.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0", alpha=0.5,
55-
edgecolor=almost_black, facecolor=palette[0], linewidth=0.15)
47+
ax2.scatter(X_vis[y == 0, 0], X_vis[y == 0, 1], label="Class #0", alpha=0.5)
5648
for iy, e in enumerate(X_res_vis):
5749
ax2.scatter(e[y_resampled[iy] == 1, 0], e[y_resampled[iy] == 1, 1],
58-
label="Class #1", alpha=0.5, edgecolor=almost_black,
59-
facecolor=np.random.rand(3,), linewidth=0.15)
50+
label="Class #1 - set #{}".format(iy), alpha=0.5)
6051
ax2.set_title('Balance cascade')
6152

53+
# make nice plotting
54+
for ax in (ax1, ax2):
55+
ax.spines['top'].set_visible(False)
56+
ax.spines['right'].set_visible(False)
57+
ax.get_xaxis().tick_bottom()
58+
ax.get_yaxis().tick_left()
59+
ax.spines['left'].set_position(('outward', 10))
60+
ax.spines['bottom'].set_position(('outward', 10))
61+
ax.set_xlim([-6, 8])
62+
ax.set_ylim([-6, 6])
63+
ax.legend()
64+
65+
plt.tight_layout()
6266
plt.show()

0 commit comments

Comments
 (0)