-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreemodel_performance.py
43 lines (37 loc) · 1.73 KB
/
Treemodel_performance.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
import os
import pandas as pd
import numpy as np
from regression_function import get_model
from tqdm import tqdm # show progress bar
os.chdir('your path')
dt_combine_fs = pd.read_csv('your data')
#FOR SELECTED VARIABLES
var_feature = ['t1_PSES2',
't1_SOLI_total',
't1_EASQ_locus','t1_EASQ_stability', 't1_EASQ_globality',
't1_BIS', 't1_BAS_drive','t1_BAS_reward_responsiveness', 't1_BAS_fun_seeking',
't1_RRS_brooding','t1_UCLALS_total', 't1_SSS_total',
't1_CTQ_total', 't1_CDRISC_total', 't1_PSS_total']
Symptoms = ['t1_PSQI_total','t1_DARS_total','t1_RSES_total',
't1_BHS_total',
't1_MDMQ_vigilance', 't1_MDMQ_procrastination','t1_MDMQ_hypervigilance', 't1_MDMQ_buckpassing',
't1_SBQ_total','t1_SCL_total']
#read the X
X = dt_combine_fs[var_feature]
#inner and outer cv R square
inner_results_ls = []
outer_results_ls = []
for symptom in tqdm(['t1_PHQ_total']+Symptoms):
Y = dt_combine_fs[symptom]
print(symptom)
inner_results, outer_results, importances, best_estimators, best_params, selected_features = get_model(X, Y)
inner_results_ls.append(inner_results)
outer_results_ls.append(outer_results)
if symptom == 't1_PHQ_total':
importances_df = pd.DataFrame(importances, index = X.columns, columns = ['importance']).sort_values('importance', ascending = False)
prediction_dict = {"Symptoms":['t1_PHQ_total']+Symptoms,"inner_results": np.mean(inner_results_ls,axis=1), "outer_results": np.mean(outer_results_ls,axis=1)}
all_y_results = pd.DataFrame(prediction_dict)
os.chdir('your path')
all_y_results.to_excel('give a name',index=False)
importances_df.to_csv('give a name',index=False)
print(all_y_results)