Generate Random Subsets of a Dataset

Data Preparation & Feature Engineering DS practice problem on Onlearn.

Difficulty: medium.

Topics: Understanding Generate Random Subsets of a Dataset, Sampling with Replacement, Sampling without Replacement, Bootstrapping, Numpy Fancy Indexing, Subset Cardinality, Data Preparation, Statistical Sampling, Ensemble Learning, Computational Complexity, Array Manipulation, Resampling Techniques, Data Partitioning, Bootstrap Aggregation, Randomized Algorithms, Vectorized Indexing.

Write a Python function to generate random subsets of a given dataset. The function should take in a 2D numpy array X, a 1D numpy array y, an integer n subsets, and a boolean replacements. It should return a list of n subsets random subsets of the dataset, where each subset is a tuple of (X subset, y subset). If replacements is True, the subsets should be created with replacements; otherwise, without replacements.