File size: 8,493 Bytes
60b21d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | <!--
SPDX-FileCopyrightText: 2025 Stanford University, ETH Zurich, and the project authors (see CONTRIBUTORS.md)
SPDX-FileCopyrightText: 2025 This source file is part of the OpenTSLM open-source project.
SPDX-License-Identifier: MIT
-->
# Clinician ECG Evaluation
This directory contains tools for the clinician-based analysis of the ECG-QA-based model evaluation. It contains a random subset of 84 samples based on the total templates with suitable predictions (42 in total, 2 random samples from each).
## Dataset Structure
```
clinicianecg/
βββ README.md
βββ REVIEWER_INSTRUCTIONS.md
βββ data/
β βββ template_01/
β β βββ sample1/
β β β βββ ecg_plot.png
β β β βββ evaluation_info.txt
β β β βββ lead_I.csv
β β β βββ lead_II.csv
β β β βββ lead_III.csv
β β β βββ lead_aVF.csv
β β β βββ lead_aVL.csv
β β β βββ lead_aVR.csv
β β β βββ lead_V1.csv
β β β βββ lead_V2.csv
β β β βββ lead_V3.csv
β β β βββ lead_V4.csv
β β β βββ lead_V5.csv
β β β βββ lead_V6.csv
β β βββ sample2/
β β βββ ... (same structure)
β βββ template_02/
β β βββ ... (same structure)
β βββ ... (templates 03-42)
β βββ template_42/
βββ pipeline/
β βββ config.json
β βββ 1_dataset_analyzer.py
β βββ 2_excel_generator.py
β βββ 2.5_demo_responses.py
β βββ 3_response_analyzer.py
β βββ 4_model_performance_analysis.ipynb
β βββ requirements.txt
βββ reviewer_workbooks/
βββ review_assignments_summary.csv
βββ reviewer_assignments.pkl
βββ ECG_Assessment_[Reviewer_Name].xlsx (configurable number)
```
## Configuration
The pipeline uses a simple `config.json` file in the `pipeline/` directory to configure the evaluation setup:
```json
{
"reviewer_count": 6,
"reviews_per_sample": 2
}
```
- **`reviewer_count`**: Number of reviewers to generate (default: 6, generates Reviewer_A through Reviewer_F)
- **`reviews_per_sample`**: Number of reviews each sample receives (default: 2 for dual-review reliability)
You can modify these values to scale the evaluation system for different numbers of reviewers or review requirements.
**Notes:**
- All predictions are CORRECT (model answer matches expected answer)
- ECG data is downsampled to 100Hz for consistency
- Each sample includes clinical context, question, answer options, and model reasoning
- CSV files contain time series data for each of the 12 ECG leads
- Templates 01-42 each contain 2 samples for a total of 84 ECG cases
- All reviewer assignments and generated workbooks are stored in the `reviewer_workbooks/` directory
## Analysis Pipeline
The `pipeline/` directory contains a comprehensive workflow for analyzing ECG model performance through expert clinician review. The pipeline consists of several Python scripts and a Jupyter notebook that work together to facilitate data analysis, review generation, and performance evaluation.
### Pipeline Components
#### 1. Dataset Analyzer (`1_dataset_analyzer.py`)
The initial component that analyzes the ECG dataset and generates reviewer assignments:
- **Purpose**: Parses ECG evaluation files and creates a configurable review system for 84 ECG samples
- **Key Features**:
- Extracts metadata from `evaluation_info.txt` files (template ID, ECG ID, questions, answers)
- Assigns samples to reviewers with balanced workload distribution (number configurable via `config.json`)
- Ensures each sample receives the configured number of reviews for reliability assessment
- Generates reviewer assignment files in the `reviewer_workbooks/` folder (`reviewer_assignments.pkl`, `review_assignments_summary.csv`)
- **Output**: Structured assignment data for downstream processing in `reviewer_workbooks/` directory
#### 2. Excel Generator (`2_excel_generator.py`)
Creates professionally formatted Excel workbooks for clinician review:
- **Purpose**: Generates individual Excel files for each reviewer containing their assigned ECG samples
- **Key Features**:
- Embeds large, high-quality ECG plots directly in Excel sheets
- Creates structured assessment forms with dropdown menus for standardized responses
- Includes three assessment categories: ECG Pattern Recognition, Clinical Reasoning, Context Integration
- Applies professional styling and formatting for optimal reviewer experience
- Adapts to configurable number of reviewers
- **Output**: Individual Excel workbooks in `reviewer_workbooks/` directory (filename format: `ECG_Assessment_[Reviewer_Name].xlsx`)
#### 2.5. [Optional] Demo Response Generator (`2.5_demo_responses.py`)
Generates mock responses for testing and demonstration purposes:
- **Purpose**: Creates sample responses in Excel workbooks to test the analysis pipeline
- **Key Features**:
- Fills assessment questions with realistic mock responses
- Uses the same 3-option response scale as actual reviews
- Enables testing of the response analyzer without requiring completed reviews
- Useful for pipeline validation and demonstration
- **Output**: Excel workbooks populated with demo responses
#### 3. Response Analyzer (`3_response_analyzer.py`)
Comprehensive analysis of completed reviewer responses:
- **Purpose**: Parses completed Excel workbooks and generates statistical analysis of reviewer responses
- **Key Features**:
- Extracts responses from all reviewer Excel files
- Calculates inter-rater agreement statistics (Cohen's kappa, percentage agreement)
- Generates response distribution visualizations
- Creates completion status reports and summary statistics
- Exports analysis results to CSV and JSON formats
- **Output**: Statistical summaries, visualizations, and detailed response data
### Workflow Usage
#### Initial Setup
Before running the pipeline, set up the Python environment and install dependencies:
```bash
# Navigate to the project directory
cd /path/to/clinicianecg
# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
# Install required dependencies
pip install -r pipeline/requirements.txt
# Install Jupyter kernel for the virtual environment
python -m ipykernel install --user --name=clinicianecg --display-name="ECG Analysis"
```
#### Pipeline Execution
1. **Configuration**: (Optional) Modify the number of reviewers and reviews per sample
```bash
cd pipeline
# Edit config.json to adjust reviewer_count and reviews_per_sample as needed
# Default: 6 reviewers, 2 reviews per sample
```
2. **Setup**: Run the dataset analyzer to generate reviewer assignments
```bash
python3 1_dataset_analyzer.py
```
- Creates `../reviewer_workbooks/` directory
- Generates `reviewer_assignments.pkl` and `review_assignments_summary.csv`
- Reads ECG data from `../data/` directory
- Uses configuration from `config.json` for reviewer assignment
3. **Review Generation**: Create Excel workbooks for clinicians
```bash
python3 2_excel_generator.py
```
- Generates individual Excel files for each reviewer in `../reviewer_workbooks/`
- Files: `Reviewer_A_ECG_Review.xlsx`, `Reviewer_B_ECG_Review.xlsx`, etc.
3. **Testing** (Optional): Generate mock responses for pipeline testing
```bash
python3 2.5_demo_responses.py
```
- Fills Excel workbooks with sample responses for testing
4. **Analysis**: Extract and analyze completed reviewer responses
```bash
python3 3_response_analyzer.py
```
- Parses completed Excel workbooks from `../reviewer_workbooks/`
- Generates statistical summaries and visualizations in `../analysis_results/`
5. **Deep Analysis**: Open the Jupyter notebook for comprehensive analysis
```bash
# Start Jupyter Lab or Jupyter Notebook (from pipeline directory)
jupyter lab 4_model_performance_analysis.ipynb
# OR
jupyter notebook 4_model_performance_analysis.ipynb
```
- Select the "ECG Analysis" kernel when prompted
- Run cells for statistical analysis and visualization
- Notebook reads from `../analysis_results/` directory
### Requirements
See `pipeline/requirements.txt` for Python dependencies.
|