File size: 1,762 Bytes
8bbb872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import csv
from clearml import Task

print("Fetching tasks from ClearML...")
tasks = Task.get_tasks(
    project_name='FocusGuards Large Group Project',
    tags=['optuna_manual'],
    task_filter={'status': ['completed', 'failed']}
)

results = []
for t in tasks:
    if t.get_status() != 'completed': continue
    params = t.get_parameters()
    
    # We reported logloss as Loss/Val, and F1 as Summary/val_f1
    metrics = t.get_last_scalar_metrics()
    val_loss = metrics.get('Loss', {}).get('Val', {}).get('last', float('inf'))
    val_f1 = metrics.get('Summary', {}).get('val_f1', {}).get('last', 0.0)
    val_acc = metrics.get('Summary', {}).get('val_accuracy', {}).get('last', 0.0)
    
    row = {
        'task_id': t.id,
        'val_loss': round(val_loss, 4) if val_loss != float('inf') else val_loss,
        'val_f1': round(val_f1, 4),
        'val_acc': round(val_acc, 4),
    }
    
    # Default Optuna parameter names parsed back from ClearML storage format
    for k in ['n_estimators', 'max_depth', 'learning_rate', 'subsample', 'colsample_bytree', 'reg_alpha', 'reg_lambda']:
        val = params.get(f"General/{k}") or params.get(k)
        row[k] = val
        
    results.append(row)

# Sort by lowest validation loss
results.sort(key=lambda x: x['val_loss'])

filepath = 'models/xgboost/sweep_results_all_40.csv'
with open(filepath, 'w', newline='') as f:
    fieldnames = ['task_id', 'val_loss', 'val_f1', 'val_acc', 'n_estimators', 'max_depth', 'learning_rate', 'subsample', 'colsample_bytree', 'reg_alpha', 'reg_lambda']
    writer = csv.DictWriter(f, fieldnames=fieldnames, extrasaction='ignore')
    writer.writeheader()
    writer.writerows(results)

print(f"Successfully grabbed {len(results)} trials and saved to {filepath}")