-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
312 lines (246 loc) · 8.41 KB
/
config.py
File metadata and controls
312 lines (246 loc) · 8.41 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# Output directory for all artifacts
OUTPUT_DIR = "outputs"
# Maximum number of improvement iterations
MAX_ITERATIONS = 3
# Stop if metric exceeds this threshold
TARGET_METRIC_THRESHOLD = 0.95
# Stop if improvement is below this threshold
IMPROVEMENT_THRESHOLD = 0.01
# Random seed for reproducibility
RANDOM_SEED = 42
# Number of parallel jobs (-1 = use all cores)
N_JOBS = -1
# ==============================================================================
# DATA PROCESSING
# ==============================================================================
# Train/test split ratio
TEST_SIZE = 0.2
# Imputation strategies
NUMERICAL_IMPUTATION_STRATEGY = 'median' # Options: 'mean', 'median', 'most_frequent'
CATEGORICAL_IMPUTATION_STRATEGY = 'most_frequent'
# Feature engineering
APPLY_SCALING = False # Set True if using distance-based models (SVM, KNN)
SCALING_METHOD = 'standard' # Options: 'standard', 'minmax', 'robust'
# ==============================================================================
# MODEL SETTINGS
# ==============================================================================
# Classification models to try
CLASSIFICATION_MODELS = {
'Logistic Regression': {
'enabled': True,
'params': {
'max_iter': 1000,
'random_state': RANDOM_SEED
}
},
'Random Forest': {
'enabled': True,
'params': {
'n_estimators': 100,
'random_state': RANDOM_SEED,
'n_jobs': N_JOBS
}
},
'Extra Trees': {
'enabled': True,
'params': {
'n_estimators': 100,
'random_state': RANDOM_SEED,
'n_jobs': N_JOBS
}
},
'Gradient Boosting': {
'enabled': True,
'params': {
'n_estimators': 100,
'random_state': RANDOM_SEED
}
},
'SVM': {
'enabled': False, # Disabled by default (slow on large datasets)
'params': {
'kernel': 'rbf',
'random_state': RANDOM_SEED
}
}
}
# Regression models to try
REGRESSION_MODELS = {
'Linear Regression': {
'enabled': True,
'params': {}
},
'Ridge Regression': {
'enabled': True,
'params': {
'random_state': RANDOM_SEED
}
},
'Lasso Regression': {
'enabled': True,
'params': {
'random_state': RANDOM_SEED
}
},
'Random Forest': {
'enabled': True,
'params': {
'n_estimators': 100,
'random_state': RANDOM_SEED,
'n_jobs': N_JOBS
}
},
'Extra Trees': {
'enabled': True,
'params': {
'n_estimators': 100,
'random_state': RANDOM_SEED,
'n_jobs': N_JOBS
}
},
'Gradient Boosting': {
'enabled': True,
'params': {
'n_estimators': 100,
'random_state': RANDOM_SEED
}
}
}
# ==============================================================================
# HYPERPARAMETER OPTIMIZATION
# ==============================================================================
# Enable hyperparameter optimization (requires Optuna)
ENABLE_HYPERPARAMETER_OPTIMIZATION = True
# Number of optimization trials
OPTUNA_N_TRIALS = 30
# Cross-validation folds for optimization
OPTUNA_CV_FOLDS = 3
# Hyperparameter search spaces
HYPERPARAMETER_SEARCH_SPACES = {
'RandomForest': {
'n_estimators': (50, 200),
'max_depth': (3, 20),
'min_samples_split': (2, 10),
'min_samples_leaf': (1, 4)
},
'ExtraTrees': {
'n_estimators': (50, 200),
'max_depth': (3, 20),
'min_samples_split': (2, 10)
},
'GradientBoosting': {
'n_estimators': (50, 200),
'learning_rate': (0.01, 0.3),
'max_depth': (3, 10)
}
}
# ==============================================================================
# METRICS
# ==============================================================================
# Primary metric for model selection
# Classification: 'accuracy', 'f1', 'roc_auc', 'precision', 'recall'
# Regression: 'r2', 'rmse', 'mae'
PRIMARY_METRIC_CLASSIFICATION = 'accuracy'
PRIMARY_METRIC_REGRESSION = 'r2'
# Additional metrics to compute and report
ADDITIONAL_METRICS_CLASSIFICATION = ['precision', 'recall', 'f1']
ADDITIONAL_METRICS_REGRESSION = ['rmse', 'mae']
# ==============================================================================
# VISUALIZATION
# ==============================================================================
# Figure size for plots
FIGURE_SIZE = (10, 6)
# DPI for saved plots
PLOT_DPI = 150
# Color scheme
PLOT_COLOR = 'steelblue'
# Number of top features to show in importance plot
TOP_N_FEATURES = 15
# ==============================================================================
# REPORTING
# ==============================================================================
# Include code examples in reports
INCLUDE_CODE_EXAMPLES = True
# Include improvement suggestions
INCLUDE_IMPROVEMENT_SUGGESTIONS = True
# Report verbosity (1=minimal, 2=normal, 3=detailed)
REPORT_VERBOSITY = 2
# ==============================================================================
# MEMORY & STRATEGY
# ==============================================================================
# Enable strategy memory (reuse successful strategies)
ENABLE_STRATEGY_MEMORY = True
# Strategy file format
STRATEGY_FILE_FORMAT = 'json' # Options: 'json', 'yaml'
# ==============================================================================
# ADVANCED SETTINGS
# ==============================================================================
# Show progress bars (requires tqdm)
SHOW_PROGRESS_BARS = False
# Verbose output during training
VERBOSE_TRAINING = True
# Save intermediate models (not just final)
SAVE_INTERMEDIATE_MODELS = False
# Enable feature selection
ENABLE_FEATURE_SELECTION = False
FEATURE_SELECTION_METHOD = 'mutual_info' # Options: 'mutual_info', 'chi2', 'f_test'
# Handle class imbalance (classification only)
HANDLE_CLASS_IMBALANCE = False
CLASS_IMBALANCE_METHOD = 'oversample' # Options: 'oversample', 'undersample', 'smote'
# ==============================================================================
# RESOURCE CONSTRAINTS
# ==============================================================================
# Maximum dataset size (rows) for full processing
MAX_DATASET_SIZE = 1_000_000
# Maximum number of features before feature selection is recommended
MAX_FEATURES_WITHOUT_SELECTION = 100
# Maximum training time per model (seconds, 0=unlimited)
MAX_TRAINING_TIME_PER_MODEL = 0
# Memory limit (GB, 0=unlimited)
MEMORY_LIMIT_GB = 0
# ==============================================================================
# VALIDATION
# ==============================================================================
def validate_config():
"""Validate configuration settings"""
errors = []
# Check test size
if not 0 < TEST_SIZE < 1:
errors.append("TEST_SIZE must be between 0 and 1")
# Check thresholds
if not 0 <= TARGET_METRIC_THRESHOLD <= 1:
errors.append("TARGET_METRIC_THRESHOLD must be between 0 and 1")
if not 0 < IMPROVEMENT_THRESHOLD < 1:
errors.append("IMPROVEMENT_THRESHOLD must be between 0 and 1")
# Check enabled models
classification_enabled = any(
m['enabled'] for m in CLASSIFICATION_MODELS.values()
)
regression_enabled = any(
m['enabled'] for m in REGRESSION_MODELS.values()
)
if not classification_enabled:
errors.append("At least one classification model must be enabled")
if not regression_enabled:
errors.append("At least one regression model must be enabled")
# Report errors
if errors:
print("⚠️ Configuration Errors:")
for error in errors:
print(f" - {error}")
return False
print("✅ Configuration validated successfully")
return True
if __name__ == "__main__":
# Test configuration
print("ML Agent Configuration")
print("=" * 60)
print(f"Output Directory: {OUTPUT_DIR}")
print(f"Random Seed: {RANDOM_SEED}")
print(f"Test Size: {TEST_SIZE}")
print(f"Hyperparameter Optimization: {'Enabled' if ENABLE_HYPERPARAMETER_OPTIMIZATION else 'Disabled'}")
print(f"Optuna Trials: {OPTUNA_N_TRIALS}")
print(f"Strategy Memory: {'Enabled' if ENABLE_STRATEGY_MEMORY else 'Disabled'}")
print("=" * 60)
# Validate
validate_config()