Spaces:
Paused
Paused
Update ml_engine/sniper_engine.py
Browse files- ml_engine/sniper_engine.py +14 -8
ml_engine/sniper_engine.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# ============================================================
|
| 2 |
-
# 🎯 ml_engine/sniper_engine.py (V1.
|
| 3 |
-
#
|
| 4 |
# ============================================================
|
| 5 |
|
| 6 |
import os
|
|
@@ -15,7 +15,7 @@ import traceback
|
|
| 15 |
from typing import List, Dict, Any
|
| 16 |
|
| 17 |
# --- [ 💡 💡 💡 ] ---
|
| 18 |
-
# [ 🚀 🚀 🚀 ] العتبة الافتراضية (بناءً على طلبك
|
| 19 |
DEFAULT_SNIPER_THRESHOLD = 0.60
|
| 20 |
# [ 🚀 🚀 🚀 ]
|
| 21 |
# --- [ 💡 💡 💡 ] ---
|
|
@@ -113,14 +113,18 @@ def _add_standard_features(df):
|
|
| 113 |
# ============================================================
|
| 114 |
|
| 115 |
class SniperEngine:
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
| 117 |
"""
|
| 118 |
تهيئة محرك قناص الدخول V1 (L2 Sniper).
|
| 119 |
Args:
|
| 120 |
-
|
| 121 |
"""
|
| 122 |
-
|
| 123 |
-
|
|
|
|
| 124 |
self.models: List[lgb.Booster] = []
|
| 125 |
self.feature_names: List[str] = []
|
| 126 |
|
|
@@ -138,9 +142,11 @@ class SniperEngine:
|
|
| 138 |
"""
|
| 139 |
print(f"🎯 [SniperEngine V1] جاري التهيئة من {self.models_dir}...")
|
| 140 |
try:
|
|
|
|
| 141 |
model_files = [f for f in os.listdir(self.models_dir) if f.startswith('lgbm_guard_v3_fold_')]
|
| 142 |
if len(model_files) < N_SPLITS:
|
| 143 |
print(f"❌ [SniperEngine V1] خطأ فادح: تم العثور على {len(model_files)} نماذج فقط، مطلوب {N_SPLITS}.")
|
|
|
|
| 144 |
return
|
| 145 |
|
| 146 |
for f in sorted(model_files):
|
|
@@ -162,7 +168,7 @@ class SniperEngine:
|
|
| 162 |
"""
|
| 163 |
السماح بتغيير العتبة أثناء التشغيل.
|
| 164 |
"""
|
| 165 |
-
if 0.30 <= new_threshold <= 0.
|
| 166 |
print(f"🎯 [SniperEngine V1] تم تحديث العتبة من {self.threshold} إلى {new_threshold}")
|
| 167 |
self.threshold = new_threshold
|
| 168 |
else:
|
|
|
|
| 1 |
# ============================================================
|
| 2 |
+
# 🎯 ml_engine/sniper_engine.py (V1.1 - L2 Entry Sniper)
|
| 3 |
+
# (معدل ليقرأ النماذج من نفس مجلد Guard V2)
|
| 4 |
# ============================================================
|
| 5 |
|
| 6 |
import os
|
|
|
|
| 15 |
from typing import List, Dict, Any
|
| 16 |
|
| 17 |
# --- [ 💡 💡 💡 ] ---
|
| 18 |
+
# [ 🚀 🚀 🚀 ] العتبة الافتراضية (بناءً على طلبك 0.60)
|
| 19 |
DEFAULT_SNIPER_THRESHOLD = 0.60
|
| 20 |
# [ 🚀 🚀 🚀 ]
|
| 21 |
# --- [ 💡 💡 💡 ] ---
|
|
|
|
| 113 |
# ============================================================
|
| 114 |
|
| 115 |
class SniperEngine:
|
| 116 |
+
|
| 117 |
+
# [ 🚀 🚀 🚀 ]
|
| 118 |
+
# [ 💡 💡 💡 ] التعديل: تغيير __init__ ليطابق GuardEngine
|
| 119 |
+
def __init__(self, models_dir: str):
|
| 120 |
"""
|
| 121 |
تهيئة محرك قناص الدخول V1 (L2 Sniper).
|
| 122 |
Args:
|
| 123 |
+
models_dir: المسار المباشر للمجلد (e.g., "ml_models/guard_v2")
|
| 124 |
"""
|
| 125 |
+
self.models_dir = models_dir
|
| 126 |
+
# [ 🚀 🚀 🚀 ]
|
| 127 |
+
|
| 128 |
self.models: List[lgb.Booster] = []
|
| 129 |
self.feature_names: List[str] = []
|
| 130 |
|
|
|
|
| 142 |
"""
|
| 143 |
print(f"🎯 [SniperEngine V1] جاري التهيئة من {self.models_dir}...")
|
| 144 |
try:
|
| 145 |
+
# (سيبحث الآن داخل 'ml_models/guard_v2/' عن هذه الملفات)
|
| 146 |
model_files = [f for f in os.listdir(self.models_dir) if f.startswith('lgbm_guard_v3_fold_')]
|
| 147 |
if len(model_files) < N_SPLITS:
|
| 148 |
print(f"❌ [SniperEngine V1] خطأ فادح: تم العثور على {len(model_files)} نماذج فقط، مطلوب {N_SPLITS}.")
|
| 149 |
+
print(f" -> (تأكد من وجود ملفات 'lgbm_guard_v3...' داخل {self.models_dir})")
|
| 150 |
return
|
| 151 |
|
| 152 |
for f in sorted(model_files):
|
|
|
|
| 168 |
"""
|
| 169 |
السماح بتغيير العتبة أثناء التشغيل.
|
| 170 |
"""
|
| 171 |
+
if 0.30 <= new_threshold <= 0.90: # (توسيع النطاق)
|
| 172 |
print(f"🎯 [SniperEngine V1] تم تحديث العتبة من {self.threshold} إلى {new_threshold}")
|
| 173 |
self.threshold = new_threshold
|
| 174 |
else:
|