Generate random subsets of a dataset. Given a 2D NumPy array and the number of subsets to generate, return random subsets of the data. Each subset is sampled with replacement and has the same number of rows as the original dataset.
import numpy as np
def generate_random_subsets(X, n_subsets, seed=None):
if seed is not None:
np.random.seed(seed)
n_samples = X.shape[0]
subsets = []
for _ in range(n_subsets):
indices = np.random.choice(n_samples, size=n_samples, replace=True)
subsets.append(X[indices])
return subsetsn_samples indices with replacement using np.random.choice.