Skip to content

Commit 1f88630

Browse files
committed
iter
1 parent 1f850ee commit 1f88630

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

examples/over-sampling/plot_comparison_over_sampling.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
The following example attends to make a qualitative comparison between the
77
different over-sampling algorithms available in the imbalanced-learn package.
8-
98
"""
109

1110
# Authors: Guillaume Lemaitre <[email protected]>
@@ -19,6 +18,7 @@
1918
from sklearn.datasets import make_classification
2019
from sklearn.svm import LinearSVC
2120

21+
from imblearn import FunctionSampler
2222
from imblearn.pipeline import make_pipeline
2323
from imblearn.over_sampling import ADASYN
2424
from imblearn.over_sampling import (
@@ -29,10 +29,13 @@
2929
KMeansSMOTE,
3030
)
3131
from imblearn.over_sampling import RandomOverSampler
32-
from imblearn.base import BaseSampler
3332

3433
print(__doc__)
3534

35+
import seaborn as sns
36+
37+
sns.set_context("poster")
38+
3639

3740
###############################################################################
3841
# The following function will be used to create toy dataset. It using the
@@ -68,13 +71,7 @@ def create_dataset(
6871
def plot_resampling(X, y, sampling, ax):
6972
X_res, y_res = sampling.fit_resample(X, y)
7073
ax.scatter(X_res[:, 0], X_res[:, 1], c=y_res, alpha=0.8, edgecolor="k")
71-
# make nice plotting
72-
ax.spines["top"].set_visible(False)
73-
ax.spines["right"].set_visible(False)
74-
ax.get_xaxis().tick_bottom()
75-
ax.get_yaxis().tick_left()
76-
ax.spines["left"].set_position(("outward", 10))
77-
ax.spines["bottom"].set_position(("outward", 10))
74+
sns.despine(ax=ax, offset=10)
7875
return Counter(y_res)
7976

8077

@@ -170,19 +167,9 @@ def plot_decision_function(X, y, clf, ax):
170167
# Instead of repeating the same samples when over-sampling, we can use some
171168
# specific heuristic instead. ADASYN and SMOTE can be used in this case.
172169

173-
174-
# Make an identity sampler
175-
class FakeSampler(BaseSampler):
176-
177-
_sampling_type = "bypass"
178-
179-
def _fit_resample(self, X, y):
180-
return X, y
181-
182-
183170
fig, axs = plt.subplots(2, 2, figsize=(15, 15))
184171
X, y = create_dataset(n_samples=10000, weights=(0.01, 0.05, 0.94))
185-
sampler = FakeSampler()
172+
sampler = FunctionSampler()
186173
clf = make_pipeline(sampler, LinearSVC())
187174
plot_resampling(X, y, sampler, axs[0, 0])
188175
axs[0, 0].set_title(f"Original data - y={Counter(y)}")

0 commit comments

Comments
 (0)