Skip to content
Back to skills

Collinear Feature Removal

ASecurity

Removes redundant features by iterating pairwise Pearson correlations and dropping one member of each pair exceeding a threshold.

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
datapythongoperformance

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill collinear-feature-removal --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collinear Feature Removal?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collinear Feature Removal
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-collinear-feature-removal/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-collinear-feature-removal)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tabular-collinear-feature-removal
description: >
  Removes redundant features by iterating pairwise Pearson correlations and dropping one member of each pair exceeding a threshold.
---
# Collinear Feature Removal

## Overview

Highly correlated features add redundancy without improving model performance and can destabilize linear models and increase overfitting in tree models on wide datasets. This technique computes the full pairwise correlation matrix, identifies pairs above a threshold (typically 0.8–0.95), and drops one member of each pair. Unlike VIF or PCA, it's interpretable — you know exactly which features were removed and why.

## Quick Start

```python
import pandas as pd
import numpy as np

def remove_collinear(df, threshold=0.8):
    """Remove one feature from each pair with |correlation| > threshold."""
    corr_matrix = df.corr().abs()
    upper = corr_matrix.where(
        np.triu(np.ones(corr_matrix.shape), k=1).astype(bool)
    )
    to_drop = [col for col in upper.columns if any(upper[col] > threshold)]
    return df.drop(columns=to_drop), to_drop

train_reduced, dropped = remove_collinear(train[numeric_cols], threshold=0.8)
test_reduced = test.drop(columns=dropped)
print(f"Removed {len(dropped)} collinear features")
```

## Workflow

1. Compute absolute Pearson correlation matrix on numeric features
2. Extract upper triangle (avoid counting each pair twice)
3. For each column, check if any correlation exceeds the threshold
4. Drop the later-appearing column in each correlated pair
5. Apply same column drops to test set

## Key Decisions

- **Threshold**: 0.8 is aggressive; 0.95 is conservative. Sweep with CV to find optimal
- **Which to drop**: Default keeps the first column — alternatively keep the one with higher target correlation
- **Scope**: Apply only to numeric features; categorical correlations need Cramér's V
- **Ordering**: Run after feature engineering, before model training

## References

- [Introduction to Manual Feature Engineering](https://www.kaggle.com/code/willkoehrsen/introduction-to-manual-feature-engineering)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.