- Overview
- Features
- System Architecture
- Installation
- Usage
- API Documentation
- Data Processing Pipeline
- Model Training
- Contributing
- License
- Model Interpretability Features
NeuroLab is a sophisticated EEG (Electroencephalogram) data analysis platform that leverages machine learning to classify mental states in real-time. The system processes EEG signals to identify various mental states such as stress, calmness, and neutrality, making it valuable for applications in mental health monitoring, neurofeedback, and brain-computer interfaces.
- Real-time EEG Processing: Stream and analyze EEG data in real-time
- Multiple File Format Support: Compatible with .edf, .bdf, .gdf, and .csv formats
- Advanced Signal Processing: Comprehensive preprocessing and feature extraction pipeline
- Machine Learning Integration: Hybrid model approach with automated calibration
- RESTful API: FastAPI-powered endpoints for seamless integration
- Scalable Architecture: Modular design for easy extension and maintenance
- Automated Recommendations: AI-driven insights and recommendations
eeg-ds/
βββ api/ # API endpoints and routing
βββ config/ # Configuration files
βββ data/ # Raw data storage
βββ models/ # ML model implementations
βββ preprocessing/ # Data preprocessing modules
βββ processed/ # Processed data and trained models
βββ utils/ # Utility functions
βββ main.py # Application entry point
βββ requirements.txt # Project dependencies
-
Clone the Repository
git clone https://github.com/asimwe1/eeg-ds.git cd eeg-ds
-
Create a Virtual Environment (Optional but recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies
pip install -r requirements.txt
-
Environment Setup
cp .env.example .env # Configure your .env file with appropriate settings
uvicorn main:app --reload
import requests
# Upload EEG file for analysis
files = {'file': open('your_eeg_file.csv', 'rb')}
response = requests.post('http://neurai/upload', files=files)
# Real-time processing
data = {'eeg_data': your_eeg_data}
response = requests.post('http://neurai/realtime', json=data)
-
POST /upload
: Upload and process EEG files- Supports files up to 500MB
- Returns processed results and analysis
-
POST /realtime
: Real-time EEG data processing- Accepts streaming EEG data
- Returns immediate analysis results
-
POST /retrain
: Retrain the model with new data- Requires authenticated access
- Returns training metrics
-
GET /health
: System health check- Monitors system status
- Returns service metrics
-
Data Loading
- File validation and format checking
- Initial data structure verification
-
Preprocessing
- Artifact removal
- Signal filtering
- Normalization
-
Feature Extraction
- Temporal features
- Frequency domain analysis
- Statistical measures
-
State Classification
- Mental state prediction
- Confidence scoring
- Temporal smoothing
- Data preparation and splitting
- Feature engineering
- Model selection and hyperparameter tuning
- Cross-validation
- Model calibration
- Performance evaluation
- Accuracy
- Precision
- Recall
- F1 Score
- ROC-AUC
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
AI Model Maintainer - Mugisha Prosper
Project Link: Neurolabs Inc
The platform now includes comprehensive model interpretability capabilities:
- Explains model predictions by attributing feature importance values
- Helps understand which EEG features contribute most to each mental state classification
- Available via API endpoint:
/interpretability/explain?explanation_type=shap
- Provides local explanations for individual predictions
- Explains specific predictions by approximating the model locally
- Available via API endpoint:
/interpretability/explain?explanation_type=lime
- Can be included in real-time streaming responses with
include_interpretability=true
- Ensures model confidence scores accurately reflect true probabilities
- Implements temperature scaling, Platt scaling, and isotonic regression methods
- Available via API endpoint:
/interpretability/calibrate?method=temperature_scaling
- Improves reliability of mental state classifications
- Visual representation of model calibration
- Shows how predicted probabilities match observed frequencies
- Available via API endpoint:
/interpretability/reliability_diagram
# Install core dependencies
pip install -r requirements.txt
# Install interpretability packages (optional)
pip install shap lime
from utils.interpretability import ModelInterpretability
# Create interpreter with your model
interpreter = ModelInterpretability(model)
# Get SHAP explanations
shap_results = interpreter.explain_with_shap(X_data)
# Get LIME explanations
lime_results = interpreter.explain_with_lime(X_data, sample_idx=0)
# Calibrate model confidence
cal_results = interpreter.calibrate_confidence(X_val, y_val, method='temperature_scaling')
# Make predictions with calibrated confidence
predictions = interpreter.predict_with_calibration(X_test)
A FastAPI-based server for processing EEG data and detecting neurological events.
- EEG data storage and retrieval
- Session management
- Event detection and storage
- Real-time data processing
- RESTful API endpoints
- Python 3.8+
- MongoDB
- InfluxDB
- Clone the repository:
git clone <repository-url>
cd neurolab_model
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Configure environment variables:
Create a
.env
file in the root directory with the following variables:
MONGODB_URL=mongodb://localhost:27017
INFLUXDB_URL=http://localhost:8086
INFLUXDB_TOKEN=your-token-here
INFLUXDB_ORG=neurolab
-
Start MongoDB and InfluxDB services
-
Run the application:
python main.py
The server will start at http://localhost:8000
Once the server is running, you can access:
- Interactive API documentation:
http://localhost:8000/docs
- Alternative API documentation:
http://localhost:8000/redoc
POST /eeg/data
- Store a single EEG data pointPOST /eeg/session
- Store a complete EEG sessionGET /eeg/session/{session_id}
- Retrieve a sessionGET /eeg/data/{session_id}
- Retrieve EEG data for a time range
POST /events
- Store a detected eventGET /events/{session_id}
- Retrieve events for a time range
The application uses:
- FastAPI for the web framework
- Motor for async MongoDB operations
- InfluxDB Client for time-series data
- Pydantic for data validation
[Your License Here]