CoCalc
Sharedimblearn-test.ipynbOpen in CoCalc
Author: Harald Schilly
Views : 1

imblearn on cocalc

kernel: python 3 ubuntu linux

import imblearn imblearn.__version__
'0.4.3'
from collections import Counter from sklearn.datasets import make_classification from imblearn.over_sampling import SMOTE # doctest: +NORMALIZE_WHITESPACE
# implementation of SMOTE - Synthetic Minority Over-sampling Technique
X, y = make_classification( n_classes=2, class_sep=2, weights=[0.1, 0.9], n_informative=3, n_redundant=1, flip_y=0, n_features=20, n_clusters_per_class=1, n_samples=1000, random_state=10) print('Original dataset shape %s' % Counter(y))
Original dataset shape Counter({1: 900, 0: 100})
sm = SMOTE(random_state=42) sm
SMOTE(k_neighbors=5, kind='deprecated', m_neighbors='deprecated', n_jobs=1, out_step='deprecated', random_state=42, ratio=None, sampling_strategy='auto', svm_estimator='deprecated')
X_res, y_res = sm.fit_resample(X, y) print('Resampled dataset shape %s' % Counter(y_res))
Resampled dataset shape Counter({0: 900, 1: 900})