PIXELBANKv8.2.1
Menu

Random Feature Subspace

Implement random feature subspace selection used in Random Forests.

Given a dataset with mm features and a list of pre-selected feature indices (to make the output deterministic), return the data with only the selected columns.

In a real Random Forest, m\sqrt{m} features are randomly selected at each split. Here, the indices are given.

Return the subsampled feature matrix.

Example:

Input:
X = [[1, 2, 3, 4], [5, 6, 7, 8]]
selected_features = [0, 2]
Output:
[[1, 3], [5, 7]]
Reasoning:
  • The input dataset X is a 2x4 matrix: [[1, 2, 3, 4], [5, 6, 7, 8]].
  • The selected_features list contains the indices of the features to be selected: [0, 2].
  • We select the columns at indices 0 and 2 from the input dataset X, which correspond to the values [1, 3] in the first row and [5, 7] in the second row.
  • The resulting subsampled feature matrix is a 2x2 matrix: [[1, 3], [5, 7]].

Constraints:

  • X: 2D list (n_samples x m_features)
  • selected_features: list of column indices to keep
  • Return 2D list with only the selected columns, preserving row order
Editor

Test Results

0/0
Run code to see test results.