X, y = load_data(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X,y,
test_size=0.3, random_state=123,
shuffle=True)
def sample(X,y):
# code attempt
train_index = sorted(np.random.permutation(len(X)))
test_index = [i for i in range(0,len(X)) if i not in train_index]
for i in range(0,len(X)):
# train, validation set split
x_trn, x_val = X[train_index], X[test_index]
y_trn, y_val = y[train_inex], y[test_index]
return x_trn , x_val, y_trn, y_val
then call it as sample(X_train, y_train)
Fill in the code to uniformly draw samples with replacement from the training data. The size of the sampled dataset should be equal to the training dataset size.
CodePudding user response:
Based on what the assignment says, this is all you need. You pick indicies at random, then return the points at those indices.
def sample(X,y):
picks = np.random.randint(0,len(X),len(X))
return X[picks], y[picks]