ml4t-feature-selection
/ml4t-feature-selection
Select informative features using IC ranking, mutual information, or RFE - always within CV folds. Use when reducing feature dimensionality before training.
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 23.10.2026, without references to retired models or APIs.
Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.
What it does and when to use it
Select informative features using IC ranking, mutual information, or RFE - always within CV folds. Use when reducing feature dimensionality before training.
Original author description
Select informative features using IC ranking, mutual information, or RFE - always within CV folds. Use when reducing feature dimensionality before training.
How it works
- The Problem
- The Pattern
- Selection Methods
- Collinearity Removal (Pre-Selection)
- Selection Stability Diagnostic
- Guardrails
- Production Implementation
- Checklist
SKILL.md preview
---
name: ml4t-feature-selection
description: "Select informative features using IC ranking, mutual information, or RFE - always within CV folds. Use when reducing feature dimensionality before training."
when_to_use: "Use when a feature set exceeds 20 features or contains suspected noise"
dependencies: [lookahead-bias]
metadata:
book_chapters: "7, 8"
library: "ml4t-diagnostic"
paths: ["**/*feature*.py", "**/*label*.py", "**/*barrier*.py", "**/*store*.py", "**/*horizon*.py", "**/*meta_label*.py", "**/*microstructure*.py", "**/*regime*.py", "**/*selection*.py"]
---
# Feature Selection
Selecting features on the full dataset is a form of lookahead bias. The test set influences which features are kept, inflating out-of-sample performance. Feature selection must happen inside each CV fold.
## The Problem
With 50 features and a finite sample, some will correlate with forward returns by chance alone. If you rank features by IC on the full dataset and keep the top 10, those 10 are partly selected for noise. Out-of-sample, the noise component vanishes and the model underperforms expectations.
## The Pattern
### WRONG
```python
from scipy.stats import spearmanr
import numpy as np
# Feature selection on full dataset - leaks test-set information
ic_scores = {col: abs(spearmanr(X[col], y).statistic) for col in X.columns}
selected = sorted(ic_scores, key=ic_scores.get, reverse=True)[:20]
model.fit(X[selected], y)
```
### CORRECT
```python
from scipy.stats import spearmanr
from sklearn.model_selection import TimeSeriesSplit
import numpy as np
tscv = TimeSeriesSplit(n_splits=5)
for train_idx, test_idx in tscv.split(X):
X_train, y_train = X[train_idx], y[train_idx]
# Select features using ONLY training data
ic_scores = {
col: abs(spearmanr(X_train[:, i], y_train).statistic)
for i, col in enumerate(feature_names)
}
selected = sorted(ic_scores, key=ic_scores.get, reverse=True)[:20]
sel_idx = [feature_names.index(f) for f in selected]
model.fit(X_train[:, sel_idx], y_train)
preds = model.predict(X[test_idx][:, sel_idx])
```
## Selection Methods
| Method | Type | When to Use |
|--------|------|-------------|
| IC ranking | Univariate | Quick filter, large feature set |
| Mutual information | Univariate | Non-linear relationships |
| L1 regularization | Embedded | During training (Lasso, ElasticNet) |
| SHAP importance | Model-based | After training, interpretation |
| Recursive feature elimination | Wrapper | Small feature set, expensive |
## Collinearity Removal (Pre-Selection)
```python
import numpy as np
def remove_collinear(corr_matrix: np.ndarray, feature_names: list, threshold: float = 0.8) -> list:
"""Drop one feature from each highly correlated pair."""
to_drop = set()
for i in range(len(feature_names)):
for j in range(i + 1, len(feature_names)):
if abs(corr_matrix[i, j]) > threshold:
to_drop.add(feature_names[j])
return [f for f in feature_names if f not in to_drop]
```
## Selection Stability Diagnostic
```python
# Track which features are selected across folds
from collections import Counter
fold_selections = Counter()
for train_idx, _ in tscv.split(X):
selected = select_top_k(X[train_idx], y[train_idx], k=20)
fold_selections.update(selected)
# Features selected in <50% of folds are unstable - likely noise
stable = [f for f, count in fold_selections.items() if count >= len(list(tscv.split(X))) // 2]
```
## Guardrails
- **Selection inside CV is non-negotiable** - any global selection is lookahead bias
- **Stability across folds matters** - a feature selected in 1/5 folds is noise
- **IC > 0.1 is suspicious** - investigate for leakage before trusting
- **Collinearity removal is safe pre-CV** - it uses only feature-feature correlation, not the target
- **Log your search set** - each knob (lookback, threshold, feature family) multiplies candidates; apply Benjamini-Hochberg FDR when comparing selections
## Production Implementation
`ml4t-diagnostic` provides a validated feature selection pipeline:
```python
from ml4t.diagnostic.selection import FeatureSelector, SelectionReport
selector = FeatureSelector(outcome_results, correlation_matrix)
selector.filter_by_ic(threshold=0.02).filter_by_correlation(threshold=0.8)
report: SelectionReport = selector.get_selection_report()
selected_features = report.final_features
```
## Checklist
- [ ] Feature selection happens inside each CV fold, never on the full dataset
- [ ] Collinearity removed first (threshold 0.7-0.8)
- [ ] Selection stability checked across folds (>50% agreement)
- [ ] No feature with IC > 0.1 accepted without leakage investigation
- [ ] Selected feature set documented and versioned
Versions
The database has no other skills named ml4t-feature-selection.
Database snapshot: 13.11.2026 · package version b5285ce3d354 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 1 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100svm-model-importance-analysis
Use when you need a standardized R CLI workflow to run two-class SVM-RFE feature ranking on an expression-like matrix, choose an informative feature count from cross-validated error, and generate reproducible ranking and error plots. NOT for regression, multi-class… - 90feature-engineering
Feature Engineering. Create, extract and select model inputs - feature extraction (PCA, SVD, TF-IDF, embeddings, signal features), feature engineering (date parts, cyclical encoding, lags, rolling windows, ratios, interactions, binning, target encoding, frequency encoding,… - 95ml4t-feature-validation
Validate features before training - IC significance, stability, redundancy, and contamination checks. Use when auditing feature quality before model fitting. - 90feature-selection-stability-across-folds
Use when a selector such as Lasso, Boruta or RFE runs inside cross-validation and you need to know whether its output is a property of the signal or of each fold; the chance-corrected Nogueira stability index. - 90feature-engineering
Build features that are leakage-free, temporally correct, and reproducible between training and serving. Use when creating model inputs or auditing a suspiciously good offline score. - 100feature-selection
Selects the most relevant lags, window features, and exogenous variables using sklearn feature selectors (RFECV, SelectFromModel). Covers single-series and multi-series selection with force inclusion and subsampling. Use when the user has many features and wants to identify the most important ones.