Skip to content

Instantly share code, notes, and snippets.

@Wei-1
Created May 9, 2020 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wei-1/9e716bb18c727f5b60281a6fec897464 to your computer and use it in GitHub Desktop.
Save Wei-1/9e716bb18c727f5b60281a6fec897464 to your computer and use it in GitHub Desktop.
Multi-Input Oversampling
# Sometime we will have multiple input data in different dimensions
# such as wide & deep neural network suggestion model
import numpy as np
from imblearn.over_sampling import RandomOverSampler as ros
Xab = {"a":np.random.random_sample, "b": np.random.random_sample}
Y = [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
X_i = [[i] for i in range(len(Y))]
X_a = np.array([Xab['a'](1) for y in Y])
X_b = np.array([Xab['b'](2) for y in Y])
# Basically, we use a X_ri in as the resample index to keep the relationship
# in our multiple input data
X_ri, Y_r1 = ros().fit_sample(X_i, Y)
X_a_r = X_a[[i[0] for i in X_ri]]
X_b_r = X_b[[i[0] for i in X_ri]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment