feat: sanitize wide/sparse datasets before clustering#5
Merged
Conversation
Wide, sparse feature exports (e.g. 152-col scanner CSV where 66 cols are ~99% null and 55 are constant) stalled the pipeline: NaN/inf crashed the scaler/PCA in feature selection and constant/rank-deficient columns slowed the VIF gate. - skills/data_cleaner.py: new pure skill — drop all-null, mostly-null (>max_null_frac), constant, and duplicate columns; median-impute remaining NaN and treat +/-inf as missing. - orchestrator: prune low-value columns at load for both the raw-CSV and pre-engineered-parquet paths; emit a data_cleaning event. - feature_selector: defensive NaN/inf imputation before scaling; generic high-dim guard (max_features_for_vif) keeps top-N by PCA+AE importance before the VIF gate so cost stays bounded on wide dense matrices. - config.yaml: data_cleaning (enabled/max_null_frac/drop_constant) and max_features_for_vif knobs; docs in skill.md + docs/skills/data_cleaner.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a deterministic data-cleaning skill and wires it into the pipeline to prevent wide/sparse datasets (NaN/inf, all-null/mostly-null/constant columns) from stalling or crashing downstream feature selection (scaling/PCA/AE/VIF), plus a runtime guard to bound VIF cost on high-dimensional dense matrices.
Changes:
- Introduces
skills/data_cleaner.pywith column-pruning and numeric imputation utilities, plus docs. - Applies load-time column pruning in
Orchestratorfor both raw-CSV and pre-engineered-parquet inputs and emits adata_cleaningevent. - Adds defensive NaN/inf handling in
FeatureSelectionAgentand amax_features_for_vifprefilter to cap VIF runtime.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| skills/data_cleaner.py | New skill implementing column pruning + optional numeric imputation with reporting. |
| skills/init.py | Exposes the new data cleaner functions via the skills package API. |
| skill.md | Documents the new data_cleaner skill and how it’s used in the pipeline. |
| docs/skills/data_cleaner.md | Adds dedicated skill contract/docs for data cleaning behavior and config. |
| config.yaml | Adds data_cleaning configuration and max_features_for_vif knob. |
| agents/orchestrator.py | Prunes low-value columns immediately after dataset load and emits a bus event. |
| agents/feature_selector.py | Adds NaN/inf imputation before scaling and caps VIF cost via prefiltering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+85
to
+92
| work = df | ||
|
|
||
| # ── 1. Duplicate column names (keep first) ──────────────────────────────── | ||
| if drop_duplicate: | ||
| dup_mask = work.columns.duplicated() | ||
| if dup_mask.any(): | ||
| report["dropped_duplicate"] = [str(c) for c in work.columns[dup_mask]] | ||
| work = work.loc[:, ~dup_mask] |
| ------- | ||
| (filled_df, report) where report['imputed'] maps column → fill value. | ||
| """ | ||
| report: dict = {"strategy": strategy, "imputed": {}, "n_inf_replaced": 0} |
Comment on lines
+189
to
+190
| if verbose and report["imputed"]: | ||
| print(f" [DataCleaner] Median-imputed NaNs in {len(report['imputed'])} numeric column(s).") |
Comment on lines
+549
to
+555
| cleaned, report = drop_low_value_columns( | ||
| df, | ||
| max_null_frac=float(dc_cfg.get('max_null_frac', 0.5)), | ||
| drop_constant=bool(dc_cfg.get('drop_constant', True)), | ||
| protect_cols=protect, | ||
| verbose=False, | ||
| ) |
| corr_threshold: float = 0.85, | ||
| ae_bottleneck_cap: int = 32, | ||
| ae_max_iter: int = 200, | ||
| max_features_for_vif: int = 150, |
| # feature names so the LLM still selects interpretable columns. | ||
| import pandas as pd | ||
| X_for_vif = pd.DataFrame(X_scaled, columns=feature_names) | ||
| cap = self.max_features_for_vif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wide, sparse feature exports (e.g. 152-col scanner CSV where 66 cols are ~99% null and 55 are constant) stalled the pipeline: NaN/inf crashed the scaler/PCA in feature selection and constant/rank-deficient columns slowed the VIF gate.