Skip to content

Commit 43271c9

Browse files
MNT add new dataset example
1 parent 4348950 commit 43271c9

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
===============================
3+
Generate an imbalanced dataset
4+
===============================
5+
6+
An illustration of using the
7+
:func:`~imbalanced_ensemble.datasets.generate_imbalance_data`
8+
function to create an imbalanced dataset.
9+
"""
10+
11+
# Authors: Zhining Liu <[email protected]>
12+
# License: MIT
13+
14+
# %%
15+
print(__doc__)
16+
17+
from imbalanced_ensemble.datasets import generate_imbalance_data
18+
from imbalanced_ensemble.utils._plot import plot_2Dprojection_and_cardinality
19+
from collections import Counter
20+
21+
# %% [markdown]
22+
# Generate the dataset
23+
# --------------------
24+
#
25+
26+
# %%
27+
X_train, X_test, y_train, y_test = generate_imbalance_data(
28+
n_samples=1000, weights=[.7,.2,.1], test_size=.5,
29+
kwargs={'n_informative': 3},
30+
)
31+
32+
print ("Train class distribution: ", Counter(y_train))
33+
print ("Test class distribution: ", Counter(y_test))
34+
35+
# %% [markdown]
36+
# Plot the generated (training) data
37+
# ----------------------------------
38+
#
39+
40+
plot_2Dprojection_and_cardinality(X_train, y_train)

examples/datasets/plot_make_imbalance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
============================
3-
Create an imbalanced dataset
4-
============================
2+
===============================
3+
Make a dataset class-imbalanced
4+
===============================
55
66
An illustration of the :func:`~imbalanced_ensemble.datasets.make_imbalance` function to
77
create an imbalanced dataset from a balanced dataset. We show the ability of

0 commit comments

Comments
 (0)