-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_simple_ensemble.py
More file actions
158 lines (136 loc) · 5.46 KB
/
test_simple_ensemble.py
File metadata and controls
158 lines (136 loc) · 5.46 KB
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
#!/usr/bin/env python3
"""
Simple test to verify ensemble helper methods
"""
def test_model_type_detection():
"""Test the model type detection logic"""
def _get_model_type_from_path(model_path: str) -> str:
"""Extrait le type de modèle du nom de fichier"""
filename = model_path.lower()
if 'logistic_regression' in filename or 'logistic' in filename:
return 'logistic_regression'
elif 'elasticnet' in filename or 'elastic_net' in filename:
return 'elastic_net'
elif 'random_forest' in filename or 'rf' in filename:
return 'random_forest'
elif 'xgb' in filename or 'xgboost' in filename:
return 'xgboost_classifier'
elif 'quantile' in filename:
return 'quantile_regression'
else:
return 'logistic_regression'
test_cases = [
("models_store/logistic_regression_mvp.joblib", "logistic_regression"),
("models_store/test_elasticnet_model.joblib", "elastic_net"),
("models_store/test_rf_opt_model.joblib", "random_forest"),
("models_store/test_xgb_opt_model.joblib", "xgboost_classifier"),
("models_store/test_quantile_model.joblib", "quantile_regression"),
]
print("🧪 Testing model type detection:")
all_passed = True
for path, expected in test_cases:
result = _get_model_type_from_path(path)
passed = result == expected
status = "✅ PASS" if passed else "❌ FAIL"
print(f" {path} -> {result} (expected: {expected}) {status}")
if not passed:
all_passed = False
return all_passed
def test_model_params():
"""Test the model parameters generation"""
def _get_model_params_for_type(model_type: str):
"""Retourne les paramètres appropriés pour chaque type de modèle"""
params = {
'logistic_regression': {
'solver': 'liblinear',
'max_iter': 1000,
'C': 1.0,
'penalty': 'l2'
},
'elastic_net': {
'loss': 'log_loss',
'penalty': 'elasticnet',
'max_iter': 1000,
'tol': 1e-3,
'alpha': 0.0001,
'l1_ratio': 0.15
},
'random_forest': {
'n_estimators': 100,
'max_depth': 10,
'min_samples_split': 5,
'min_samples_leaf': 2,
'n_jobs': -1,
'ccp_alpha': 0.0
},
'xgboost_classifier': {
'objective': 'binary:logistic',
'eval_metric': 'logloss',
'n_estimators': 100,
'max_depth': 6,
'learning_rate': 0.1,
'subsample': 0.8,
'colsample_bytree': 0.8
},
'quantile_regression': {
'loss': 'quantile',
'alpha': 0.5,
'n_estimators': 100,
'max_depth': 6,
'learning_rate': 0.1
}
}
return params.get(model_type, {})
print("\n🧪 Testing model parameters generation:")
model_types = ['logistic_regression', 'elastic_net', 'random_forest', 'xgboost_classifier', 'quantile_regression']
all_passed = True
for model_type in model_types:
params = _get_model_params_for_type(model_type)
has_params = len(params) > 0
status = "✅ PASS" if has_params else "❌ FAIL"
print(f" {model_type}: {len(params)} parameters {status}")
if has_params:
print(f" Key parameters: {list(params.keys())[:4]}")
if not has_params:
all_passed = False
return all_passed
def check_model_files():
"""Check if model files exist"""
import os
models_dir = "models_store"
expected_models = [
"logistic_regression_mvp.joblib",
"test_elasticnet_model.joblib",
"test_rf_opt_model.joblib",
"test_xgb_opt_model.joblib",
"test_quantile_model.joblib"
]
print("\n📁 Checking model file availability:")
all_exist = True
for model_file in expected_models:
model_path = os.path.join(models_dir, model_file)
exists = os.path.exists(model_path)
status = "✅ AVAILABLE" if exists else "❌ MISSING"
print(f" {model_file}: {status}")
if not exists:
all_exist = False
return all_exist
if __name__ == "__main__":
print("🚀 AlphaBeta808 Ensemble Helper Methods Test")
print("=" * 50)
test1_passed = test_model_type_detection()
test2_passed = test_model_params()
test3_passed = check_model_files()
print("\n" + "=" * 50)
if test1_passed and test2_passed and test3_passed:
print("✅ All tests PASSED! Ensemble functionality is ready.")
print("\n🎯 The continuous trader can now:")
print(" • Detect model types from file paths")
print(" • Generate appropriate parameters for each model type")
print(" • Use multiple models in ensemble predictions")
print(" • Calculate weighted averages of model predictions")
print(" • Handle uncertainty reduction when predictions vary")
else:
print("❌ Some tests FAILED. Check the output above.")
if not test3_passed:
print(" Note: Missing model files can be retrained using the existing training scripts.")