# Design notes — why the preprocessing modules do what they do Reference for the methodology behind `src/`. The code carries short contract docstrings; the reasoning lives here. Results and model performance are in the top-level [README.md](../README.md); the production contract is in [`production/classifier_symmetric/README.md`](../production/classifier_symmetric/README.md). --- ## `config.py` — why whole column families are excluded The `hist_*_FN[+-]k`, `*_before_founding` and `*_after_founding` columns are computed relative to a founding event and are **identically zero for every non-founder row** in `datasets_complete`. In RQ1 (full-profile founder vs. non-founder) a model would separate the classes on that artifact rather than on signal, so they are excluded from `RQ1_FEATURE_COLUMNS`. `RQ1_PREFOUNDING_PAIRS` handles the opposite direction. For founders, lifetime totals include **post**-founding activity (e.g. continuing to publish part-time after founding) — a reverse-causation confound that lets a model key off a downstream *effect* of founding. Non-founders have no equivalent issue: their full total is inherently "pre-founding". For the four metrics where a validated `_before_founding` split exists, `data._apply_prefounding_equivalent` swaps it in. ## `data.py` — leakage-safe loading for RQ1 and RQ2 **RQ1** reads `evaluation/datasets_complete`, drops identifier and leaky columns (`config.RQ1_DROP_COLUMNS`) and keeps the remaining full-career aggregates. **RQ2** ("founds within N years") reads the curated 13-column half-profile datasets (`datasets_halfprofiles_offset{1,2,3}`) as the positive class at each horizon, paired with non-founders from `datasets_complete` on the same curated columns, which are legitimate and non-degenerate for non-founders too. Non-founders are split 70/30 per institution **once** (fixed `random_state`) into a training pool (offsets 1–3) and a holdout pool reserved exclusively for the offset-3/5 horizon-validation sets, so no individual is ever seen in both training and horizon-generalization testing. ## `outliers.py` — two-stage multivariate outlier detection Replaces the original `publications < 1000` / `patents < 1000` guard inherited from the source notebooks. That guard does remove real rows (677 of them), but the underlying problem is worse than a long tail: several of the most extreme rows — "Hui Zhang" with 20,703 publications and 49,398 patents, "David Smith" with 16,713 publications — are almost certainly **common-name collisions**. Dimensions' name-based researcher matching merges dozens of distinct real people who share a common name into one aggregated profile; these are not genuinely hyper-prolific individuals. A single hand-picked threshold on one or two columns cannot reliably separate "very productive but real" from "impossible amalgamation of several people", so outlier handling is two-staged: 1. A generous, documented **sanity ceiling** — any individual researcher with more than 5,000 lifetime publications or patents is implausible even for extreme large-collaboration physics — to drop flagrant collisions outright. 2. An **Isolation Forest** fit in log-space on the remaining rows across the full numeric feature set (not just publications/patents), to catch subtler multivariate anomalies — e.g. an internally inconsistent feature combination that no single-column cutoff would flag. ## `yearly_counts.py` — per-person, per-year activity from the raw exports The raw files in `dimensions_data/` are per-person record lists: each row is one (record × tracked person) pair, keyed by `author_people`. They cover the **founder cohort only** — non-founders were extracted live from the Dimensions API, their per-record data was never saved, and the API key has since expired. These exact yearly counts are used two ways: 1. Exact truncation of founder features at the founding year, replacing the coarser `*_before_founding` splits. 2. Fitting the empirical career-trajectory curves in `career_curves.py`, which calibrate the truncation of non-founder lifetime totals at a pseudo-founding year — validated against the founders' exact counts, where both are known. **Grants cap.** The `grants` feature counts grant IDs acknowledged on a person's publications, so a single consortium paper can contribute 100+ "grants". The module also emits a capped variant crediting at most `GRANTS_PER_PAPER_CAP` distinct grant IDs per publication, mirroring the hyperauthorship cap in the production profiling module. The empirical distribution of grants per linked paper is p50 = 3, p90 ≈ 6–14 depending on institution, with a consortium tail reaching 409. The cap sits above ordinary multi-grant papers and below the consortium artifacts (~100+/paper) that inflated `grants` roughly 100×. ## `career_curves.py` — index-date truncation of lifetime totals The symmetric redesign needs every person's activity counts **as of an index year** (real founding year for founders, sampled pseudo-founding year for non-founders). Exact per-year records exist only for founders; non-founders have lifetime totals plus first/last activity years. We therefore estimate, from the founders' raw trajectories, the average cumulative-share curve ``` F(u) = expected fraction of lifetime output accumulated by career fraction u u = (index_year - first_year) / (last_year + 1 - first_year) ``` separately per activity type (pubs / patents / grants) and career-length stratum, and truncate totals as `total_at_index = total * F(u)`. **Critical symmetry rule:** this construction is applied to **both** classes. Founders' exact counts are used only to (a) fit the curves and (b) quantify the approximation error against ground truth (`validate_on_founders`, log-space R² 0.89–0.94). If founders got exact counts while non-founders got smoothed ones, the residual noise texture alone would separate the classes — the exact artifact this redesign removes. ## `symmetric.py` — the landmark design Replaces the asymmetric RQ1/RQ2 preprocessing in `data.py`, where founders' lifetime totals were truncated at their founding year while non-founders kept full-career totals. That made observation-window length a function of the label: the classifier's dominant feature (`publications`) partly encoded the truncation rather than productivity — probability of founding fell monotonically with output, and the 0.918 → 0.976 ROC-AUC "improvement" of the asymmetric fix was a class-separability artifact. 1. **Index year.** Founders get their cleaned founding year; non-founders a pseudo-founding year sampled from the founders' empirical career-age-at-founding distribution, matched on career-start cohort (landmark / matched index-date design, cf. immortal-time bias). 2. **Identical feature construction for both classes**, as deterministic functions of (lifetime totals, first/last activity years, index year) via `career_curves.py`. Founders' exact per-year records are used only to fit and validate those curves — never as a founder-only feature pathway. 3. **Citation features excluded** (h-index, i10, g-index, citation sums/means): citations cannot be historicized to the index year for either class, and their full-career values are window-contaminated. 4. **`grants` de-inflated** with the per-paper cap from `yearly_counts.py`, applied through a ratio curve so both classes go through the same mapping. Two further filters, both applied to **both** classes: - **Population definition.** The coach-facing tool scores academics, so the modelled population requires a minimal academic record at the index date (≥ 4 publications). Without it, a sampling-frame clash dominates the thin-profile region: founders come from company databases (people with 1–3 lifetime papers included), non-founders from institutional researcher lists (thin profiles underrepresented), making "long career + tiny record" read as 65–72% founder. Those people are out of scope for the product, not evidence. - **Plausibility filter.** Profiles with a > 60-year publishing span or a sustained lifetime rate above 25 papers/year are name-collision aggregates (e.g. an "M Nakamura" spanning 1919–2023 with 28k papers). These concentrate in the non-founder class — matched by name alone, vs company + name for founders — so left in they asymmetrically inflate non-founder output. ## `sequence_data.py` — founder-only sequence dataset Task: predict career-relative founding timing from pre-founding activity, using the `hist_{pub,pat,grant}_FN-1..FN-20` columns (chronological yearly counts in the 20 years strictly before founding). **Non-founders are not included.** Their equivalent columns are computed with `founded_year` hardcoded to literal year 0 in `extraction/non_founders_scripts.ipynb` (`generate_history(..., nonstartup=True)` forces `founded_year = 0`), so they are all-zero placeholders anchored at 1 BCE/1 CE — not real "N years before some reference point" sequences. There is no valid apples-to-apples non-founder sequence in the extracted data; see `experiments/run_sequence_reconstruction_spike.py` for an attempt to build one from the raw per-paper/per-patent data instead. **Target:** `founding_age = founded_on (year) - first_publication_year`, i.e. how many years into their publishing career a founder started their company. Only well-posed when `founding_age <= WINDOW` (20): the input window is a fixed 20-year lookback, so a longer real pre-founding career would look identical to a ≥ 20-year case regardless of the true value. This is a structural right-censoring limit of the fixed window, not a modeling failure, so those rows are excluded from the regression task by default and the excluded count is always reported. ## `run_rq1_robustness.py` — `scale_pos_weight` under StratifiedKFold StratifiedKFold keeps each fold's class ratio approximately equal to the full-data ratio, so a single overall `scale_pos_weight` is a good per-fold approximation for xgboost — which, unlike RF/LightGBM's `class_weight="balanced"`, needs it set explicitly to correct for the ~37% founder rate.