Created
May 9, 2020 13:59
-
-
Save Wei-1/9e716bb18c727f5b60281a6fec897464 to your computer and use it in GitHub Desktop.
Multi-Input Oversampling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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