Generate Sorted Polynomial Features

Data Preparation & Feature Engineering DS practice problem on Onlearn.

Difficulty: medium.

Topics: Understanding Generate Sorted Polynomial Features, Interaction Terms, Broadcasting, Lexicographical Ordering, Degree Constraints, Vectorized Operations, Data Preprocessing, Feature Engineering, Numerical Computing, Linear Algebra, Combinatorics, Polynomial Expansion, Array Manipulation, Feature Transformation, Sorting Algorithms, Dimensionality Management.

Write a Python function that takes a 2 D NumPy array X and an integer degree , generates all polynomial feature combinations of the columns of X up to the given degree inclusive , then sorts the resulting features for each sample from lowest to highest value . The function should return a new 2 D NumPy array whose rows correspond to the input samples and whose columns are the ascending sorted polynomial features.