import os
import pandas as pd
import seaborn as sns
import plotly.express as px
import plotly.io as pio
import plotly.graph_objects as go
import matplotlib.pyplot as plt
from hbn.constants import Defaults
from hbn.visualization import visualize
import warnings
"ignore")
warnings.filterwarnings(
%load_ext autoreload
%autoreload 2
%matplotlib inline
# pio.renderers.default = 'iframe'
import ipywidgets as widgets # interactive display
%config InlineBackend.figure_format = 'svg' # other available formats are: 'retina', 'png', 'jpeg', 'pdf'
# load model output
= pd.read_csv(os.path.join(Defaults.MODEL_DIR, 'classifier-all-phenotypic-models-performance.csv'))
df_classify = pd.read_csv(os.path.join(Defaults.MODEL_DIR, 'regression-all-phenotypic-models-performance.csv'))
df_regress
'data'] = df_classify['data'].map({'model-data': 'data', 'model-null': 'null'})
df_classify[
for idx,col in enumerate(['Assessment', 'Domain', 'Measure']):
= df_classify['features'].str.split('-').str.get(idx) df_classify[col]
= pd.read_csv(os.path.join(Defaults.MODEL_DIR, 'classifier-feature_importance.csv'))
df_feature
= df_feature[df_feature['Measure']!='all'] df_feature
# set plotting style
visualize.plotting_style()
def interactive_plot(df, x='features', y='roc_auc_score'):
= go.Figure()
fig
=df[x][df['data']=='data'],
fig.add_trace(go.Violin(x=df[y][df['data']=='data'],
y='Null', scalegroup='Null', name='Null',
legendgroup='negative',
side='blue')
line_color
)=df[x][df['data']=='null'],
fig.add_trace(go.Violin(x=df[y][df['data']=='null'],
y='Data', scalegroup='Data', name='Data',
legendgroup='positive',
side='orange')
line_color
)=True, box_visible=False)
fig.update_traces(meanline_visible=0, violinmode='overlay')
fig.update_layout(violingap=False)
fig.update_xaxes(showticklabels=y)
fig.update_yaxes(title_text
fig.show()
def stable_plot(df, x='features', y='roc_auc_score', hue='data'):
= sns.violinplot(
ax =x,
x=y,
y=hue,
hue=df,
data=True,
split='width',
scale='quartile'
inner
)='upper center', bbox_to_anchor=(0.5, 1.1),
ax.legend(loc=2, fancybox=True, shadow=True)
ncol=90)
plt.xticks(rotation plt.show()
# Child Measures - Language Tasks
= df_classify[(df_classify['target']=='DX_01_Cat_binarize') &
df1 'Assessment']=='Child_Measures') &
(df_classify['Domain']=='Language_Tasks')]
(df_classify[
=df1) interactive_plot(df
# Parent Measures - Demographics
= df_classify[(df_classify['target']=='DX_01_Cat_binarize') &
df1 'Assessment']=='Parent_Measures') &
(df_classify['Domain']=='Demographic_Questionnaire_Measures')]
(df_classify[
=df1) interactive_plot(df
# Parent Measures - Interview of Emotional and Psychological Function
= df_classify[(df_classify['target']=='DX_01_Cat_binarize') &
df1 'Assessment']=='Parent_Measures') &
(df_classify['Domain']=='Interview_of_Emotional_and_Psychological_Function')]
(df_classify[
=df1) interactive_plot(df
# Child Measures - Cognitive Testing
= df_classify[(df_classify['target']=='DX_01_Cat_binarize') &
df1 'Assessment']=='Child_Measures') &
(df_classify['Domain']=='Cognitive_Testing')]
(df_classify[
=df1) interactive_plot(df
# Child Measures - Questionnaire_Measures_of_Emotional_and_Cognitive_Status
= df_classify[(df_classify['target']=='DX_01_Cat_binarize') &
df1 'Assessment']=='Child_Measures') &
(df_classify['Domain']=='Questionnaire_Measures_of_Emotional_and_Cognitive_Status')]
(df_classify[
=df1) interactive_plot(df
# Child Measures : all other domains
= df_classify[(df_classify['target']=='DX_01_Cat_binarize') &
df1 'Assessment']=='Child_Measures')]
(df_classify[
= ['Physical_Fitness_and_Status', 'Neurologic_Function', 'Physiologic_Function', 'Vision', 'Motor_Skills']
cols
= df1[df1['Domain'].isin(cols)]
df1
=df1) interactive_plot(df
# interactive visualization of features
@widgets.interact(
=df_feature['features'].unique(),
feature
)
def visualize_features(feature):
= df_feature[df_feature['features']==feature]
df = px.line(df, x='feature_names_sum', y='feature_sum', markers=True, title=feature)
fig =False)
fig.update_xaxes(showticklabelstype='category')
fig.update_xaxes(
fig.show()