> ## Documentation Index
> Fetch the complete documentation index at: https://docs.predictaa.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Domain aware ml

# Domain-Aware ML (Mixture of Experts)

Specialized ML models for different market categories.

***

## Overview

Instead of one generic model, Predicta uses **domain-specific specialist models** for better accuracy:

| Domain          | Model                       | Domain Features                      |
| --------------- | --------------------------- | ------------------------------------ |
| `crypto`        | `crypto_model.keras`        | BTC correlation, gas, funding rate   |
| `sports`        | `sports_model.keras`        | Team ELO, injuries, weather          |
| `politics`      | `politics_model.keras`      | Polling, incumbency, news sentiment  |
| `entertainment` | `entertainment_model.keras` | Social mentions, trending score      |
| `science`       | `science_model.keras`       | Historical success, regulatory stage |
| `generic`       | `generic_model.keras`       | Fallback for rare categories         |

***

## Architecture

```
Market → [Domain Router] → Category → [Specialist Model] → P(YES)
              │                             │
         Keywords/Tags              10-dim domain features
         Polymarket tags            + GRU + Attention encoder
```

***

## Files

| File                                     | Purpose                          |
| ---------------------------------------- | -------------------------------- |
| `cortex/domain_router.py`                | Classify markets into domains    |
| `cortex/domain_features.py`              | Extract domain-specific features |
| `cortex/training/bootstrap_by_domain.py` | Create domain-separated datasets |
| `cortex/training/train_domain_model.py`  | Train specialist models          |
| `cortex/inference_server.py`             | `/predict_domain` endpoint       |

***

## Usage

### 1. Generate Datasets

```bash theme={null}
cd cortex/training
python bootstrap_by_domain.py

# Output:
# data/crypto_dataset.pkl
# data/sports_dataset.pkl
# data/politics_dataset.pkl
# data/generic_dataset.pkl
```

### 2. Train Models

```bash theme={null}
python train_domain_model.py --domain crypto
python train_domain_model.py --domain sports
python train_domain_model.py --domain all

# Output:
# models/crypto_model.keras
# models/sports_model.keras
```

### 3. Inference

Models auto-load on server startup. Use the new endpoint:

```bash theme={null}
POST /predict_domain
{
  "token_id": "...",
  "title": "Will Bitcoin reach $100k?",
  "volume": 1500000,
  "tags": ["crypto"]
}
```

Response includes domain routing info:

```json theme={null}
{
  "probability": 0.72,
  "uncertainty": 0.04,
  "domain": "crypto",
  "domain_confidence": 0.85,
  "model_used": "crypto_model"
}
```

***

## Fallback Behavior

1. If router confidence \< 50% → Use `generic_model`
2. If domain model missing → Use `generic_model`
3. If generic missing → Use legacy model
4. If all fail → HTTP 503
