A Python-based machine learning pipeline designed to fetch, preprocess, and decode cognitive states from functional Magnetic Resonance Imaging (fMRI) data.
This project serves as a foundational step toward advanced brain decoding tasks (such as reconstructing complex thoughts and sentences from fMRI imagery) by implementing spatial masking, dimensionality reduction, and optimized predictive modeling.
- Data Preprocessing (
fmri_visualizer.py&fmri_animator.py):- Downloads the Haxby dataset (visual stimuli).
- Converts 4D spatiotemporal tensors into 3D mean volumes and animated time-series.
- Predictive Modeling (
fmri_decoder.py):- Applies spatial brain masks to eliminate scanner noise.
- Trains a Linear Support Vector Machine (SVM) to classify cognitive states (e.g., looking at a 'face' vs. a 'cat').
- Pipeline Optimization (
fmri_optimizer.py&fmri_visualize_optimized.py):- Compares Ensemble Learning (Random Forest) with Linear SVMs.
- Implements ANOVA-based Feature Selection to isolate the top 5% most statistically significant voxels in the visual cortex.
- Reverses the mathematical transformation to project the optimized model weights back into 3D neuroanatomical space.
To ensure scientifically valid and unbiased results, this pipeline implements strict Scikit-Learn Pipeline architectures to prevent data leakage during preprocessing.
- Methodology: Stratified 5-Fold Cross-Validation with nested loops for hyperparameter tuning.
- Peak Accuracy: 70.90% (Random guessing baseline: ~50.00%)
-
Optimal Strategy: Combining standard scaling, VarianceThreshold (to remove constant background voxels), and ANOVA Feature Selection (Top 5%) prior to Linear SVM classification proved vastly superior to Ensemble methods (Random Forests) in this high-dimensional
$P \gg N$ neuroimaging space.
- Languages: Python
- Neuroimaging Libraries: Nilearn, Nibabel
- Machine Learning: Scikit-learn (SVM, Random Forest, GridSearchCV, Pipelines)
- Data Processing & Visualization: NumPy, Pandas, Matplotlib
The optimized model successfully filtered out scanner noise and background voxels. By utilizing ANOVA-based Feature Selection within a strict non-leaking pipeline, the model achieved its highest accuracy by localizing weights primarily to the occipital and temporal regions associated with visual processing.


