Module 13: Machine Learning in Neuroscience
Apply machine-learning workflows to connectomics features, with explicit controls for data leakage, bias, and interpretability.
Use this module
Capability target
Design and critique an ML analysis pipeline for connectomics that includes feature rationale, evaluation plan, leakage controls, and interpretation limits. Concretely: choose a split strategy from the leakage channels present in your data rather than from convention, pick metrics from the decision the model will support, quantify how much of your reported performance survives a harder split, and write a limitation statement specific enough that a reader knows which uses of your model you would refuse.
Why this module matters
ML accelerates connectomics analysis, and naive workflows produce misleading biological claims at the same speed. The characteristic failure is not a model that performs badly — it is a model that performs suspiciously well because the split leaked, and whose reported number then propagates into a paper as though it described generalization.
Connectomics is unusually leaky. Fragments of one neuron appear in many rows. Neighboring neurons share staining, imaging conditions, and section artifacts. Cell-type labels are often derived from connectivity, so a model predicting connectivity from cell type may be reading its own answer. The proofread subset is not a random sample of the volume: neurons get proofread because someone wanted them, which usually means they were large, central, or interesting. Every one of these is a channel by which test data informs training, and none of them is visible in a learning curve.
Concept set
1) Feature engineering defines the hypothesis space
- Technical: feature choices encode assumptions about what variation is biologically meaningful. For a neurite-fragment classifier a defensible starting set is skeleton path length, mean and variance of caliber, branch count, tortuosity, synapse count as presynaptic and as postsynaptic partner, and mitochondrial volume fraction — each of which corresponds to a cue a human annotator actually uses. Every feature you add also adds a way for the model to identify the dataset rather than the biology: raw intensity statistics, for instance, encode staining batch almost perfectly.
- Plain language: your model can only learn what your features allow, and it will learn the easiest thing they allow.
- Misconception guardrail: adding more features always improves science.
2) Evaluation must match the decision the model supports
- Technical: metrics should align with downstream use. A model that ranks a proofreading queue is evaluated by precision at k, where k is the number of segments a reviewer can actually inspect this week. A model gating automated merges is evaluated by false-positive rate at a high threshold, because a merge error is expensive and largely invisible afterwards. A model producing labels for population statistics is evaluated by calibration, not accuracy, because systematic label bias shifts a group mean while individual errors cancel.
- Plain language: high overall accuracy can still fail exactly where it matters.
- Misconception guardrail: one summary metric is enough.
3) Leakage and distribution shift are endemic
- Technical: the main channels are fragment-level duplication of one neuron across splits, spatial adjacency (neighbors share staining, alignment, and artifacts), proofreading provenance (the proofread set is selection-biased), preprocessing fitted on the full dataset before splitting, and label circularity where the target was derived from a feature. Each has a specific counter-split; see the table below.
- Plain language: the model may be cheating without any obvious sign.
- Misconception guardrail: a random split always gives a valid generalization estimate.
4) Base rates decide what accuracy means
- Technical: if a target class is 1% of your sample, a model that predicts “negative” for everything scores 99% accuracy and has zero utility. Report prevalence alongside every accuracy figure, and for rare classes report per-class recall with a confidence interval — with 40 positive examples, a recall of 0.75 has a 95% interval roughly spanning 0.60 to 0.86, which is usually too wide to support a biological claim.
- Plain language: with rare classes, accuracy mostly measures the base rate.
- Misconception guardrail: a 99% accurate classifier is a useful classifier.
5) Labels are a hypothesis, not ground truth
- Technical: cell-type labels come from expert judgment, and experts disagree at rates that vary by type and by dataset. Features are computed on a segmentation that contains merge and split errors, so a fraction of your rows describe objects that do not exist. Measure label agreement on a re-annotated subset before treating disagreement between model and label as model error, and pin the segmentation version used to compute features — features from an unpinned segmentation are not reproducible.
- Plain language: your ceiling is set by how well two experts agree, not by 100%.
- Misconception guardrail: the training labels are the truth the model is failing to reach.
Split strategy: what each choice blocks and what it costs
| Split strategy | Leakage channel it blocks | What it costs you |
|---|---|---|
| Random row split | None | Optimistic by a wide and unknown margin; useful only as an upper bound |
| Group by parent neuron | Fragments of one neuron on both sides | Fewer effective samples; requires reliable parent IDs at a pinned version |
| Spatial block (e.g. 100 µm tiles) | Shared staining, alignment, local artifacts | Fewer, noisier folds; block size is a judgment call you must defend |
| By proofreading batch or annotator | Annotator style and QC-round provenance | May confound with region if batches were assigned region by region |
| Held-out dataset or species | Domain shift | Smallest and hardest test; under-states in-domain performance |
| Decision the model supports | Metric that matches | Metric that misleads | What the right metric costs |
|---|---|---|---|
| Ranking a proofreading queue | Precision at k, with k = weekly reviewer capacity | Overall accuracy | You must know reviewer capacity before evaluating |
| Finding rare cell types | Per-class recall, precision at fixed recall | Macro accuracy | Confidence intervals are wide at small N |
| Gating automated merges | False-positive rate at a high threshold | F1 | Throughput falls sharply as the threshold rises |
| Population statistics from predicted labels | Calibration curve, label-noise correction | Accuracy | Requires a separately labeled calibration set |
Worked example: the classifier that scored 0.92 and taught nothing
The numbers below are illustrative — they show the shape of the reasoning, not results from a specific published dataset.
You have 4,000 labeled neurite fragments in five coarse classes and train a gradient-boosted model on the feature set from Concept 1. A random 80/20 split gives macro-F1 = 0.92. That number is the first thing to distrust, because 0.92 on a five-class morphological problem is better than trained human annotators typically agree with each other.
First question: where did the rows come from? The 4,000 fragments came from 600 neurons, so on average nearly seven fragments per neuron, and a random split puts fragments of the same neuron on both sides. The model can memorize a neuron’s caliber and branching signature and recognize its other fragments. Re-splitting grouped by parent neuron gives macro-F1 = 0.71. Twenty-one points of the original score were fragment duplication.
Second question: what else do neighbors share? Fragments from the same cortical column share staining, section artifacts, and alignment residual. Re-splitting into 100 µm spatial blocks gives 0.66. The assumption here is explicit and worth stating in the same sentence as the number: 100 µm blocks only block adjacency leakage if no relevant structure spans a block. Apical dendrites routinely span more than 100 µm, so this estimate is still slightly optimistic for dendrite-derived features.
Third question: does it transfer? Evaluated on fragments from a second dataset with different staining, macro-F1 = 0.41, and the drop is not uniform — one class falls to near chance while three barely move. This is the finding, not a disappointment: the model has learned three classes robustly and two only in-domain.
Fourth question: does the aggregate hide the use case? The intended use is ranking segments for proofreading. Per-class recall for the rarest class is 0.18 at the operating threshold, and that class is 4% of the sample, so it contributes almost nothing to macro-F1 either way. The metric that matters is precision at k = 500, the weekly review capacity — measured directly at 0.62, meaning roughly 310 of the 500 flagged segments contain a real error.
What gets reported. Not 0.92. Report 0.66 as the in-dataset generalization estimate, 0.41 as the cross-dataset estimate, precision@500 = 0.62 as the deployment metric, and per-class recall as a table so the weak classes are visible. The limitation statement says: supported use is prioritizing a review queue within this dataset; unsupported uses are assigning final labels, comparing class proportions across datasets, and any use on tissue with different staining without re-measurement.
What this example does not establish. It does not show that 0.66 is the true generalization performance — only that each successive control removed leakage the previous one missed, and the sequence had not yet converged. A fifth control, blocking by proofreading batch, might drop it again.
Hidden curriculum scaffold
- Unspoken ML norms trainees need stated explicitly:
- Justify the split strategy in writing before training anything.
- Report the prevalence of every class next to every accuracy figure.
- Show failure cases as examples, not only as aggregate metrics.
- Include model-card style limitations and intended use with every shared model.
- Mentoring supports:
- Provide a leakage checklist and require it filled in at proposal time, not at write-up.
- Require one “where the model fails” figure in every presentation.
- Review scientific usefulness separately from benchmark score.
Core workflow: connectomics ML protocol
- Write the biological decision the model will support, naming who acts on the output and what they do differently as a result.
- Enumerate leakage channels present in your data — fragment duplication, spatial adjacency, annotator provenance, label circularity — and choose the split that blocks the strongest one.
- Construct the feature set with a one-line rationale per feature, and record the segmentation version the features were computed from.
- Fit all preprocessing (scaling, imputation, feature selection) inside the training fold only.
- Train a trivial baseline first — majority class, or a single-feature threshold — and report it alongside every later model.
- Evaluate with the metric that matches the decision from step 1, plus per-class recall and prevalence.
- Run error analysis on the failures: sample 20-30 misclassified examples and classify the failure reason by hand.
- Write the model card: intended use, unsupported uses, evaluation splits, metrics with intervals, and the domain in which the numbers hold.
Pre-class preparation
- Read neuron type identification so you know what the labels mean before you model them.
- Bring a small labeled table of your own, or use the supplied fragment set.
- Be ready to state, in one sentence, the decision your model would support.
60-minute tutorial run-of-show
- 00:00-08:00 | Task framing and leakage examples Present the 0.92 result and ask the room to explain it. Collect hypotheses on the board before revealing the group-split number.
- 08:00-20:00 | Feature rationale workshop Each learner writes a one-line rationale per feature and marks any feature that could encode dataset identity rather than biology.
- 20:00-34:00 | Split strategy and baseline modeling Teams implement two splits — random and grouped — on the same data and report both scores. The gap is the exercise.
- 34:00-46:00 | Error analysis and biologically relevant metrics Learners compute per-class recall and prevalence, then precision at a k set by a stated review capacity.
- 46:00-56:00 | Model-card limitation writing Each learner drafts three unsupported uses for their own model and has a neighbor try to break them.
- 56:00-60:00 | Competency checkpoint Each learner names the leakage channel they consider most likely still present in their own work.
Studio activity: leakage-resistant ML mini-pipeline
Scenario: You must classify neurite fragments into coarse categories to prioritize a proofreading queue. You have roughly 4,000 labeled fragments drawn from about 600 neurons in one dataset, five classes with prevalences of approximately 38%, 27%, 19%, 12%, and 4%, and a reviewer team that can inspect 500 segments per week. A second, differently stained dataset is available as a held-out domain.
Tasks
- Propose a feature set with a one-line rationale per feature, and flag any feature that could encode dataset identity.
- Design the split, naming the leakage channel each choice blocks and the cost you accept for it.
- Train one baseline and one improved model, or write the pseudocode plan if compute is unavailable.
- Report two standard metrics, one biologically targeted metric tied to the 500-segment review capacity, and per-class recall with prevalence.
- Sample 20 misclassified fragments, classify the failure reason by hand, and propose the one data improvement that would fix the largest group.
- Draft a model limitation statement naming at least three unsupported uses.
Expected outputs
- Feature and split design sheet with the leakage channel named for each split choice.
- Metric table including per-class recall, prevalence, and precision at k = 500.
- Error-analysis tally of 20 hand-classified failures.
- Limitation statement with supported and unsupported uses.
Assessment rubric
- Minimum pass
- Feature and split decisions are justified against a named leakage channel.
- Metrics include at least one biologically targeted criterion tied to a real capacity or threshold.
- Limitation statement is specific and actionable.
- Strong performance
- Quantifies how much performance each successive split control removes.
- Uses error analysis to propose the next data improvement rather than the next model.
- Names the assumption behind the chosen block size or grouping in the same sentence as the number.
- Distinguishes an exploratory model from a deployment-ready one and states what would have to change.
- Common failure modes
- Leakage-prone random splits on spatially correlated data.
- Overfocus on aggregate accuracy with prevalence unreported.
- Claims of biological insight unsupported by model diagnostics.
- Features computed against an unpinned segmentation version.
ML in the connectomics pipeline
Machine learning is embedded at every stage of the reconstruction pipeline:
| Stage | ML task | Key methods | Training data source |
|---|---|---|---|
| Segmentation | Predict voxel affinities/boundaries | U-Net, FFN (Januszewski et al. 2018) | Manual ground-truth annotations |
| Synapse detection | Identify cleft locations + pre/post partners | 3D CNN on local patches | Expert-annotated synapse sets |
| Cell-type classification | Assign neuron type from morphology/connectivity | Random forest, GNN, clustering | Morphologically typed neurons |
| Error detection | Flag likely merge/split errors for proofreading | Classifier on segment features | Proofreading correction logs |
| Automated proofreading | Suggest corrections | Reinforcement learning, heuristic models | Before/after correction pairs |
Domain shift is the central challenge: A model trained on well-stained MICrONS data may fail on under-stained H01 regions, on different species (mouse → fly), or on tissue with pathology (near epileptic foci). Always evaluate on held-out data from the target domain, not just the training domain.
Common errors and how to recover
- Your held-out score is far higher than human inter-annotator agreement. Treat this as evidence of leakage, not of success. Recover by re-splitting grouped by parent neuron, then by spatial block, and record the score after each control. Report the sequence, not only the last number.
- Performance collapses on the second dataset. Do not tune on the second dataset — that converts your only honest test into another training set. Recover by reporting the collapse as a domain-shift result, then either collect a small labeled sample from the target domain for fine-tuning and keep a fresh holdout, or restrict the model’s stated domain to the training dataset.
- A rare class has near-zero recall but the model looks fine. Recover by reporting per-class recall and prevalence in every table. If the rare class is the scientific point, re-frame the task as detection at a fixed recall and report precision there, rather than as multi-class classification.
- Cross-validation folds disagree wildly after you switch to spatial blocks. This is the honest variance showing. Recover by reporting the fold-to-fold spread as an interval rather than the mean alone, and if the spread is unusable, say the dataset does not support the claim at that granularity.
- Feature computation cannot be reproduced six months later. Recover by re-deriving features from a pinned materialization version and comparing distributions with the archived feature table. If they differ, the earlier features came from a different segmentation and the earlier model’s metrics do not describe the current data.
- The model was trained on proofread neurons and deployed on unproofread ones. The proofread set is selection-biased and cleaner. Recover by evaluating on a random sample of unproofread segments with fresh labels, and expect the metrics to drop; report the drop as the deployment estimate.
- Reviewers ask “so what does this tell us biologically?” and you have only a metric. Recover by producing a feature-importance or ablation result tied to a cue an anatomist would recognize, and by stating what would have to be true for that cue to be causal rather than correlated.
What this module does not cover
- The segmentation and synapse-detection networks themselves. Architectures, training regimes, and augmentation are Module 14 and Technical Unit 08.
- Statistical inference on connectomes. Null models, motif significance, and the way effect sizes move as the null strengthens are Module 10, Module 20, and Technical Unit 09.
- Deep learning implementation. Optimizers, schedules, and distributed training are assumed background; this module is about validity, not throughput.
- What the labels mean. The anatomy behind cell-type categories is neuron type identification and Module 04.
- Data infrastructure. Pinning versions, sizing tables, and query cost are Module 12.
- Formal fairness and causal inference frameworks. These are relevant and out of scope here; the module handles leakage and shift operationally rather than theoretically.
Content library references
- Reconstruction pipeline — Where ML fits in the pipeline
- Error taxonomy — Error types ML must handle
- NeuroAI bridge — Bidirectional exchange between neuroscience and AI
- Neuron type identification — Morphological and connectivity-based classification
- Journal papers: computer vision and ML — Primary literature
Teaching resources
- Upstream data context: Module 12
- Downstream morphology/classification: Module 14
- Technical track context: Connectome Analysis and NeuroAI
- Quality context: Connectome Quality tool
References
- Januszewski M et al. (2018) “High-precision automated reconstruction of neurons with flood-filling networks.” Nature Methods 15(8):605-610.
- Lee K et al. (2019) “Superhuman accuracy on the SNEMI3D connectomics challenge.” arXiv:1706.00120.
- McInnes L et al. (2018) “UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction.” arXiv:1802.03426.
- Ronneberger O et al. (2015) “U-Net: Convolutional Networks for Biomedical Image Segmentation.” MICCAI 2015.
Quick practice prompt
For one candidate model, write:
- one plausible leakage pathway,
- one metric blind spot,
- one limitation you would report publicly.
Practice and progress
Check your understanding, then record your progress.
Feature Audit Microtask
You are about to add raw image intensity statistics to the feature set. What must the design sheet record?
Activity progress (self-reported)
State is saved locally in your browser for this module.
0% of self-reported activities checked
Checkpoint: not yet passed.
Scored items update from your answers, not from checkboxes. Compare your work with the lesson rubric: this tracker does not certify proficiency.
Teaching Materials
Slide Deck
Slides and session instructions for this module. Check the module status before teaching it.
Activity Worksheet
Learner worksheet aligned to the studio activity and rubric.