-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.py
51 lines (40 loc) · 1.78 KB
/
run_tests.py
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
import json
from re import L
import numpy as np
import pandas as pd
import ert.ert_aia_peaks as ert_aia_peaks
import os
### Script to run training and testing of ERT model on different feature sets and random seeds]
in_features = 'hmi' # can be either 'hmi','hmiandaia' or 'aia'
seeds = np.arange(1001,11001,1000)
data = {'seed':seeds,'RMSE_train':[],'MAE_train':[],'R2_train':[],'L2err_train':[],'RMSE_test':[],'MAE_test':[],'R2_test':[],'L2err_test':[]}
for seed in seeds:
# first update config file
with open('ert/config_regression.json', 'r') as jsonfile:
config = json.load(jsonfile)
print('Running test with seed ', seed)
config['features'] = in_features
config["seed"] = int(seed)
config["labels_file"] = 'flare_catalogs/aia_flares_catalog_verified.csv'
config["output_dir"] = 'ert_results_'+str(in_features)+'/seed'+str(seed)+'/'
if not os.path.exists(config["output_dir"]):
os.makedirs(config["output_dir"])
with open('ert/config_regression.json', 'w') as outfile:
json.dump(config, outfile)
# then run code
model, features, trainerrs, testerrs = ert_aia_peaks.main()
data['RMSE_train'].append(trainerrs[0])
data['MAE_train'].append(trainerrs[1])
data['R2_train'].append(trainerrs[2])
data['L2err_train'].append(trainerrs[3])
data['RMSE_test'].append(testerrs[0])
data['MAE_test'].append(testerrs[1])
data['R2_test'].append(testerrs[2])
data['L2err_test'].append(testerrs[3])
for feature,importance in zip(features,model.feature_importances_):
if feature in data.keys():
data[feature].append(importance)
else:
data[feature] = [importance]
df = pd.DataFrame(data)
df.to_csv(config["output_dir"]+'ert_results_'+in_features+'_verified.csv',index=False)