selection¶
Feature selection methods.
Experimental
This module is experimental and may change in future versions.
selection
¶
@module: sce.selection @depends: numpy, pandas, scipy, sklearn @exports: LMFeatureSelector, compute_lm_statistics, select_significant_features @paper_ref: Section 4.2 Feature Selection @data_flow: features -> LM statistics -> p-value filtering -> selected_features @status: EXPERIMENTAL - Test coverage 17%. Not recommended for production use.
Feature selection using Linear Model statistics. Two-stage approach: 1. LM p-value filtering for statistical significance 2. Optional XGBoost importance ranking for predictive power
⚠️ WARNING: This module has minimal test coverage (17%) and is considered experimental. Use at your own risk. Core SCE functionality in engine.py and stats.py is fully tested and production-ready.
LMStatistics
dataclass
¶
LMFeatureSelector
¶
Bases: BaseEstimator, TransformerMixin
Sklearn-compatible feature selector based on LM p-values.
Example
selector = LMFeatureSelector(p_threshold=0.05) X_selected = selector.fit_transform(X, y)
Source code in sce/selection.py
fit
¶
Fit selector to find significant features.
Source code in sce/selection.py
transform
¶
Return only selected features.
Source code in sce/selection.py
compute_lm_statistics
¶
compute_lm_statistics(X: DataFrame, y: Series, features: Optional[List[str]] = None) -> LMStatistics
Compute Linear Model statistics for features.
Fits OLS regression and computes: - Standardized coefficients (β) - Standard errors SE(β) - T-statistics - P-values - Correlations with target
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Feature matrix |
required |
y
|
Series
|
Target variable |
required |
features
|
Optional[List[str]]
|
Subset of features to analyze (default: all) |
None
|
Returns:
| Type | Description |
|---|---|
LMStatistics
|
LMStatistics with per-feature statistics |
Source code in sce/selection.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
select_significant_features
¶
select_significant_features(X: DataFrame, y: Series, features: List[str], p_threshold: float = 0.05, method: str = 'backward') -> Tuple[List[str], pd.DataFrame]
Select statistically significant features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame
|
Feature matrix |
required |
y
|
Series
|
Target variable |
required |
features
|
List[str]
|
Features to consider |
required |
p_threshold
|
float
|
P-value threshold for significance |
0.05
|
method
|
str
|
"backward" (stepwise elimination) or "filter" (simple threshold) |
'backward'
|
Returns:
| Type | Description |
|---|---|
Tuple[List[str], DataFrame]
|
Tuple of (selected_features, elimination_history) |
Source code in sce/selection.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |