Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Remove constant (zero-variance) features during feature engineering so your model doesn’t waste capacity on columns that never change. You’ll scan a 2D dataset and drop any feature whose values are identical across all samples.
Constant-feature detection can be defined as:
Implement the function
Rules:
kept_indices.sklearn).Output:
| Argument | Type |
|---|---|
| X | np.ndarray |
| Return Name | Type |
|---|---|
| value | tuple |
Input/output are NumPy arrays (indices can be list/array).
Use NumPy only; no sklearn utilities.
Check exact equality; no tolerance needed.
Operate column-wise via axis=0.
A column is constant if all values equal its first-row value: np.all(X == X[0], axis=0).
Use the boolean mask to build kept_indices, then slice: X_filtered = X[:, kept_indices]; return (X_filtered, kept_indices).