Fix pipeline data leakage, merge fan-out, and repo hygiene - #1
Open
skylarliu1 wants to merge 3 commits into
Open
Fix pipeline data leakage, merge fan-out, and repo hygiene#1skylarliu1 wants to merge 3 commits into
skylarliu1 wants to merge 3 commits into
Conversation
- .gitignore: venvfit/, .DS_Store, __pycache__, .ipynb_checkpoints, Data/Raw/, Data/Processed/ - requirements.txt: packages from README Requirements, pinned to venvfit versions - git rm --cached Data/Raw + Data/Processed (regenerable via download_data.py / data_cleaning.py / the notebooks) to relieve Git-LFS bandwidth. Local files kept. - src/split.py: canonical frozen train/test split shared by all notebooks (row-level, stratified on fit_label, test_size=0.20, random_state=42) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…e keys
DBSCAN, GMM, K-means, LDA now load the frozen split from src/split.py and fit
their scaler / model / PCA / coherence-sweep on the training rows only. Every
row (train + test) is then *transformed*:
- GMM / K-means: predict / predict_proba
- DBSCAN (no predict): nearest fitted core sample within eps, else -1
- LDA: dictionary + LdaModel built from train reviews; test reviews scored
with get_document_topics (inference only). Train-only coherence sweep now
selects k=9 (was k=11 on the full corpus).
Merge-key hygiene (fixes the row fan-out that produced the bogus
"266,286-sample test set"):
- dbscan_df.csv -> one row per user_id
- gmm_df.csv -> unique (user_id, item_id)
- kmeans_clusters.csv -> unique (user_id, item_id)
- renttherunway_lda_topics.csv -> unique (user_id, item_id, fit, fit_label)
Also fixes a pre-existing figure-path bug (Notebooks/Figures/... -> Figures/...)
exposed by the repo restructure. Regenerated Figures/Unsupervised_Outputs/*.
README: add "Reproducing the Pipeline" run order + train/test-discipline note.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ures
All 7 classifiers (+ Model_Comparison) now:
- load df via src/split.load_rtr_with_split()
- de-duplicate each unsupervised artifact on its merge key, then assert the
merged table is still 192,544 rows (no fan-out)
- derive X_train/X_test from df["split"] instead of a fresh train_test_split
Effect of removing the leakage (test set 266,286 -> 38,509 rows):
model leaky acc / macroF1 -> fixed acc / macroF1
CART 0.73 / 0.67 -> 0.50 / 0.38
Random Forest 0.76 / 0.70 -> 0.53 / 0.40
Bagging 0.77 / 0.72 -> 0.52 / 0.40
KNN 0.91 / 0.87 -> 0.69 / 0.34
Kernel SVM 0.85 / 0.78 -> 0.52 / 0.40
Linear SVM 0.68 / 0.39 -> 0.74 / 0.29
Naive Bayes 0.46 / 0.41 -> 0.42 / 0.35
Model_Comparison now shows the rich RTR feature set is WORSE than the simple
3-feature baseline for every model (macro-F1 delta -0.23 to -0.40); its
"KNN on rich features wins" conclusion no longer holds. Each write-up cell gets
a banner with the fixed numbers; the prose still needs a human rewrite.
Also: fix Model_Comparison's Data path (../ -> ../../, restructure bug).
Repo hygiene: stop tracking Models/ (regenerable; bagging_simple_classifier
alone is 160 MB and was the lone Git-LFS entry). Added to .gitignore, removed
the .gitattributes LFS rule. Local files kept.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
What this fixes
1. Data leakage in every supervised notebook (primary)
All 7 classifiers merged the unsupervised artifacts (
dbscan_df.csv,gmm_df.csv,kmeans_clusters.csv,renttherunway_lda_topics.csv) intodfbeforetrain_test_split(). Those artifacts were produced by models (DBSCAN,GMM,K-means,LDA) fit on the entire RTR dataset, so test-row cluster labels andtopic vectors were informed by the test set.
Fix: new
src/split.pydefines one frozen split (row-level, stratified onfit_label,test_size=0.20,random_state=42). Every Phase 1 notebook now fitsits scaler / model / PCA / model-selection sweep on the training partition only
and merely transforms every row:
predict/predict_probapredict)eps, else-1Dictionary+LdaModelbuilt from train reviews; test reviews scored withget_document_topics(inference only). Train-only coherence sweep now picks k=9 (was k=11 on the full corpus).Every Phase 2 notebook takes its train/test partition from
df["split"]instead ofa fresh
train_test_split.2. Row-count fan-out bug
dbscan_df.csvwas transaction-grained but keyed only onuser_id(~70k duplicatekeys).
df.merge(dbscan, on="user_id")fanned 192,544 → 1,156,140 rows, whichis where the "test set of 266,286 samples" came from. The other three merges added
smaller fan-out from 266 genuine duplicate
(user_id, item_id)transactions inrenttherunway_clean.csv.Fix: each artifact is de-duplicated on its merge key at the source
(
dbscan_df.csv→ one row peruser_id; the others → unique(user_id, item_id[, fit, fit_label])),and each supervised notebook re-asserts
len(df) == 192_544after the merges.Clean 20% test set is now 38,509 rows.
3. Repo hygiene
.gitignore(venvfit/,.DS_Store,__pycache__/,Data/,Models/).requirements.txt(pinned to the project venv).git rm --cachedData/Raw/,Data/Processed/(regenerable viadownload_data.py/data_cleaning.py/ the notebooks) andModels/(regenerable by re-running Phase 2;
bagging_simple_classifier.joblibalone is160 MB and was the repo's only Git-LFS entry — its
.gitattributesrule isremoved). Local files are kept; this is a normal commit, not a history
rewrite.
venvfit/stays in history as-is per the brief.README.md: added a "Reproducing the Pipeline" run-order section.DBSCAN,K-means, andModel_Comparison(../→../../, exposed by the earlier repo restructure).Impact on results
Removing the leakage (and the fan-out) collapses every model to near the
majority-class base rate:
Model_Comparisonnow shows the rich RTR feature set is worse than the simple3-feature (weight/age/height) baseline for every model (macro-F1 Δ −0.23 to
−0.40). Its "KNN on rich features is the strongest overall performer" conclusion no
longer holds.
Follow-ups for reviewers (not done here)
write-ups have a
paragraphs, per-class tables, and confusion-count callouts still describe the
leaky results and need a human rewrite.
user_id, soa user with rows on both sides still leaks (weaker form). Kept a plain row-level
split here to stay comparable; consider
GroupShuffleSplitonuser_id.predictvsargmax(predict_proba).Model_Comparisonscores the RTR modelsfrom the saved probability files, which disagrees with each notebook's own
predict()for theclass_weight="balanced"models (e.g. Kernel SVM: 0.52 vs0.74 acc). Pre-existing; worth reconciling.
Data/andModels/are no longer in git — runsrc/download_data.py→src/data_cleaning.py→ the notebooks (order in the README) to regenerate.How it was verified
src/split.py→ 154,035 train / 38,509 test (exactly 20%, stratified). All 11notebooks (4 unsupervised + 7 supervised) +
Model_Comparisonwere executedend-to-end on
venvfitwith avenvfitkernel; each supervised notebook printstrain rows: 154,035 / test rows: 38,509and its merge-fan-out assertion passes.🤖 Generated with Claude Code