<jupyter_start><jupyter_text>Unzip datasets and prepare data:<jupyter_code>from collections import Counter

import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.decomposition import PCA

from multi_imbalance.datasets import load_datasets
from multi_imbalance.resampling.global_cs import GlobalCS
from multi_imbalance.utils.data import construct_flat_2pc_df

%matplotlib inline
sns.set_style('darkgrid')

df = load_datasets()['new_ecoli']
X, y = df['data'], df['target']
print(X[:5])
print(y[:5])<jupyter_output>[[0.49 0.29 0.48 0.5  0.56 0.24 0.35]
 [0.07 0.4  0.48 0.5  0.54 0.35 0.44]
 [0.56 0.4  0.48 0.5  0.49 0.37 0.46]
 [0.59 0.49 0.48 0.5  0.52 0.45 0.36]
 [0.23 0.32 0.48 0.5  0.55 0.25 0.35]]
[0 0 0 0 0]<jupyter_text>Resample data using Global CS algorithm<jupyter_code>clf = GlobalCS()
resampled_X, resampled_y = clf.fit_resample(X, y)<jupyter_output><empty_output><jupyter_text>Compare results by plotting data in 2 dimensions<jupyter_code>n = len(Counter(y).keys())
p = sns.color_palette("husl", n)

pca = PCA(n_components=2)
pca.fit(X)

fig, axs = plt.subplots(ncols=2, nrows=2)
fig.set_size_inches( 16, 10)
axs = axs.flatten()

axs[1].set_title("Base")
sns.countplot(y, ax=axs[0], palette=p)
X = pca.transform(X)
df = construct_flat_2pc_df(X, y)
sns.scatterplot(x='x1', y='x2', hue='y', style='y', data=df, alpha=0.7, ax=axs[1], legend='full', palette=p)


axs[3].set_title("MDO")
sns.countplot(resampled_y, ax=axs[2],palette=p)
resampled_X = pca.transform(resampled_X)
df = construct_flat_2pc_df(resampled_X, resampled_y)
sns.scatterplot(x='x1', y='x2', hue='y', style='y', data=df, alpha=0.7, ax=axs[3], legend='full', palette=p)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup