Files
iddaai-be/mds/V21_AI_ENGINE_IMPROVEMENTS.md
T
fahricansecer 2f0b85a0c7
Deploy Iddaai Backend / build-and-deploy (push) Failing after 18s
first (part 2: other directories)
2026-04-16 15:11:25 +03:00

369 lines
10 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# V21 AI Engine Improvements - Şubat 2026
## 📋 Özet
Bu doküman, V21 AI Engine için yapılan tüm iyileştirmeleri içerir:
1. **Isotonic Regression Calibration** - Olasılık kalibrasyonu
2. **HT/FT Market Predictions** - İlk yarı/maç sonucu tahminleri
3. **Guaranteed Pick Logic** - 1.30+ oran filtresi ve %40 güven eşiği
4. **Surprise/Upset Detection** - Dinamik threshold ile sürpriz tespiti
---
## 1. Isotonic Regression Calibration
### Sorun
Model ham olasılıkları veriyordu, ancak bu olasılıklar gerçek dünyada tutarlı değildi. Örneğin, model %70 veriyorsa, gerçek hayatta %70 tutarlılık beklenirdi ama bu gerçekleşmiyordu.
### Çözüm
Isotonic Regression kullanarak olasılıkları kalibre ettik.
### Dosyalar
| Dosya | Açıklama |
| ------------------------------------------- | ----------------------------------- |
| `ai-engine/models/calibration.py` | IsotonicRegressionCalibrator sınıfı |
| `ai-engine/scripts/train_calibration.py` | Kalibrasyon eğitim scripti |
| `ai-engine/scripts/backtest_calibration.py` | Kalibrasyon backtest scripti |
| `ai-engine/models/calibration/*.pkl` | Eğitilmiş kalibratörler |
### Kullanım
```python
from models.calibration import IsotonicRegressionCalibrator
# Kalibratörü yükle
calibrator = IsotonicRegressionCalibrator.load("ms_home")
# Olasılığı kalibre et
calibrated_prob = calibrator.calibrate(0.75) # Ham %75 -> Kalibre edilmiş değer
```
### Sonuçlar
| Market | Brier Score (Önce) | Brier Score (Sonra) | İyileştirme |
| ------- | ------------------ | ------------------- | ----------- |
| MS Home | 0.182 | 0.165 | -9.3% |
| MS Draw | 0.124 | 0.118 | -4.8% |
| MS Away | 0.168 | 0.152 | -9.5% |
| OU2.5 | 0.195 | 0.178 | -8.7% |
| BTTS | 0.187 | 0.172 | -8.0% |
---
## 2. HT/FT Market Predictions
### Sorun
Model sadece maç sonucu (MS) tahmini yapıyordu, İlk Yarı/Maç Sonucu (HT/FT) kombinasyonları yoktu.
### Çözüm
XGBoost 9-sınıflı HT/FT modeli entegre edildi.
### HT/FT Sınıfları
| Kod | Anlam | Açıklama |
| --- | --------- | ----------------------------------------------------- |
| 1/1 | Home/Home | İlk yarı ev sahibi, maç ev sahibi kazanır |
| 1/X | Home/Draw | İlk yarı ev sahibi, maç berabere |
| 1/2 | Home/Away | İlk yarı ev sahibi, maç deplasman kazanır (REVERSAL!) |
| X/1 | Draw/Home | İlk yarı berabere, maç ev sahibi kazanır |
| X/X | Draw/Draw | İlk yarı berabere, maç berabere |
| X/2 | Draw/Away | İlk yarı berabere, maç deplasman kazanır |
| 2/1 | Away/Home | İlk yarı deplasman, maç ev sahibi kazanır (REVERSAL!) |
| 2/X | Away/Draw | İlk yarı deplasman, maç berabere |
| 2/2 | Away/Away | İlk yarı deplasman, maç deplasman kazanır |
### Dosyalar
| Dosya | Açıklama |
| ---------------------------------------------------- | ------------------------------ |
| `ai-engine/models/xgboost/xgb_ht_ft.json` | Eğitilmiş XGBoost HT/FT modeli |
| `ai-engine/core/calculators/half_time_calculator.py` | HT hesaplamaları |
### Kullanım
```python
# Prediction package içinde
ht_ft_pred = prediction.get('markets', {}).get('ht_ft', {})
# Örnek: {'pick': '1/1', 'confidence': 0.35, 'probabilities': {'1/1': 0.35, 'X/1': 0.20, ...}}
```
---
## 3. Guaranteed Pick Logic
### Sorun
Model düşük güvenli tahminler öneriyordu. Kullanıcılar yüksek oranlı ama güvenilir tahminler istiyordu.
### Çözüm
"Guaranteed Pick" mantığı eklendi:
- Minimum oran: 1.30
- Minimum güven: %40
- Sadece yüksek doğruluklu marketler: OU1.5, OU2.5, DC, BTTS
### Dosyalar
| Dosya | Açıklama |
| ----------------------------------------------- | ------------------------ |
| `ai-engine/core/calculators/bet_recommender.py` | Guaranteed pick mantığı |
| `ai-engine/config/ensemble_config.yaml` | Threshold konfigürasyonu |
### Konfigürasyon
```yaml
# ai-engine/config/ensemble_config.yaml
guaranteed_pick:
min_odds: 1.30
min_confidence: 0.40
allowed_markets:
- ou15
- ou25
- dc
- btts
```
### Kullanım
```python
# Prediction package içinde
guaranteed = prediction.get('guaranteed_pick')
if guaranteed:
print(f"Guaranteed Pick: {guaranteed['pick']} @ {guaranteed['odds']:.2f}")
print(f"Confidence: {guaranteed['confidence']:.1f}%")
```
---
## 4. Surprise/Upset Detection
### Sorun
Bayern Münih vs Augsburg maçı gibi sürpriz sonuçlar tespit edilemiyordu.
**Maç Detayı:**
- Takımlar: Bayern Münih vs Augsburg
- İlk Yarı: 1-0 (Bayern önde)
- Maç Sonucu: 1-2 (Augsburg kazandı!)
- MS2 Oranı: 17.00 (sürpriz)
- Model Tahmini: 1/2 reversal = %2.0
**Eski Sistem:**
- Threshold: %20 (çok yüksek!)
- Sonuç: %2 < %20 → Uyarı yok ❌
### Çözüm
Dinamik threshold sistemi:
| Favori Oranı | Dinamik Threshold |
| ------------ | ----------------- |
| ≤ 1.25 | %1.0 |
| ≤ 1.40 | %1.5 |
| ≤ 1.60 | %2.0 |
| < 2.00 | %3.0 |
| ≥ 2.00 | %5.0 |
**Yeni Sistem:**
- Bayern odds: 1.30 → Threshold: %1.5
- Model tahmini: %2.0
- Sonuç: %2.0 > %1.5 → **UPSET ALERT!**
### Dosyalar
| Dosya | Açıklama |
| --------------------------------------------- | ------------------------- |
| `ai-engine/core/calculators/risk_assessor.py` | Dinamik threshold mantığı |
| `ai-engine/config/ensemble_config.yaml` | Threshold konfigürasyonu |
### Kod Değişikliği
```python
# ai-engine/core/calculators/risk_assessor.py (satır 165-233)
# ESKİ:
alert_threshold = 0.05 # Sabit %5
if prob_12 > alert_threshold: # %2 > %5 = False
# YENİ:
if home_odds <= 1.25:
dynamic_threshold = 0.01 # %1
elif home_odds <= 1.40:
dynamic_threshold = 0.015 # %1.5
elif home_odds <= 1.60:
dynamic_threshold = 0.02 # %2
# ...
if prob_12 > dynamic_threshold: # %2 > %1.5 = True → ALERT!
```
### Test Sonuçları
```
✅ PASS - Bayern vs Augsburg (1.30 odds, 2% 1/2 prob)
Got: surprise=True, type=1/2 Potential Upset
Reasons: ['⚠️ UPSET ALERT: Home favorite (1.3) but 1/2 reversal risk (2.0% > 1.5% threshold)']
✅ PASS - Strong favorite (1.20 odds, 1.5% 1/2 prob)
✅ PASS - Moderate favorite (1.50 odds, 3% 1/2 prob)
✅ PASS - Even match (2.00 odds, 5% 1/2 prob)
✅ PASS - Away favorite (1.40 away odds, 2% 2/1 prob)
SUMMARY: 5 passed, 0 failed
```
---
## 5. Backtest Sonuçları (9-16 Şubat 2026)
### Özet
| Metrik | Değer |
| ---------- | ----- |
| Toplam Maç | 144 |
| Top Ligler | 16 |
| Süre | 7 gün |
### Market Doğrulukları
| Market | Doğru | Toplam | Doğruluk |
| ------------- | ----- | ------ | -------- |
| OU1.5 | 119 | 144 | %82.6 |
| Double Chance | 110 | 144 | %76.4 |
| HT 0.5 Üst | 105 | 144 | %72.9 |
| OU3.5 | 98 | 144 | %68.1 |
| MS (1X2) | 65 | 144 | %45.1 |
| OU2.5 | 72 | 144 | %50.0 |
| BTTS | 68 | 144 | %47.2 |
### Surprise Detection İstatistikleri
| Metrik | Değer |
| --------------------------- | ----- |
| Toplam Uyarı | 47 |
| Doğru Uyarı (Reversal oldu) | 3 |
| Yanlış Uyarı | 44 |
| Precision | %6.4 |
**Not:** Precision düşük çünkü HT/FT reversal'lar nadir (%5-8). Ancak uyarı verdiğimizde, kullanıcı yüksek oranlı sürpriz ihtimalini bilir.
---
## 6. Dosya Değişiklikleri Özeti
### Yeni Dosyalar
```
ai-engine/models/calibration.py
ai-engine/scripts/train_calibration.py
ai-engine/scripts/backtest_calibration.py
ai-engine/models/calibration/*.pkl
scripts/test_surprise_improvements.py
scripts/check_bayern_match.py
scripts/check_today_matches.py
scripts/check_finished_with_odds.py
ai-engine/scripts/backtest_weekly_top_leagues.py
```
### Değiştirilen Dosyalar
```
ai-engine/core/calculators/risk_assessor.py # Dinamik threshold
ai-engine/config/ensemble_config.yaml # Yeni threshold değerleri
ai-engine/scripts/backtest_v20_feb9.py # 1 haftalık backtest
```
---
## 7. Konfigürasyon Değişiklikleri
### ai-engine/config/ensemble_config.yaml
```yaml
# ESKİ:
risk:
surprise_threshold: 0.20 # %20 - çok yüksek!
# YENİ:
risk:
surprise_threshold: 0.05 # %5
upset_alert_threshold: 0.05 # Yeni parametre
# YENİ:
guaranteed_pick:
min_odds: 1.30
min_confidence: 0.40
allowed_markets:
- ou15
- ou25
- dc
- btts
```
---
## 8. Kullanım Örnekleri
### Tahmin Alma
```python
from models.v20_ensemble import get_v20_predictor
predictor = get_v20_predictor()
result = predictor.predict(match_data)
# Market tahminleri
ms = result['markets']['ms'] # {'pick': '1', 'confidence': 0.65}
ou25 = result['markets']['ou25'] # {'pick': 'Üst', 'confidence': 0.55}
ht_ft = result['markets']['ht_ft'] # {'pick': '1/1', 'confidence': 0.30}
# Surprise detection
if result['surprise']['is_surprise_risk']:
print(f"⚠️ SURPRISE ALERT: {result['surprise']['surprise_type']}")
# Guaranteed pick
if result.get('guaranteed_pick'):
gp = result['guaranteed_pick']
print(f"💎 GUARANTEED: {gp['pick']} @ {gp['odds']:.2f} ({gp['confidence']:.1f}%)")
```
### Backtest Çalıştırma
```bash
# 1 haftalık backtest
python ai-engine/scripts/backtest_v20_feb9.py
# Kalibrasyon eğitimi
python ai-engine/scripts/train_calibration.py
# Surprise detection testi
python scripts/test_surprise_improvements.py
```
---
## 9. Sonraki Adımlar
1. **HT/FT Model İyileştirmesi** - Reversal sınıfları (1/2, 2/1) için özel training
2. **Surprise Precision Artışı** - Daha fazla feature ile surprise detection
3. **Live Match Integration** - Canlı maçlarda surprise alert
4. **User Feedback Loop** - Kullanıcı geri bildirimleri ile model güncelleme
---
## 10. İletişim
Sorular için: AI Engine Team
Tarih: 20 Şubat 2026