<jupyter_start><jupyter_text>Comparison<jupyter_code>palette= sns.color_palette("tab10")


sns.set_style("whitegrid")
sns.set_context("talk")


fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(20, 6))


sns.lineplot(
    data=majority_df[majority_df['type']=='false_alarm_rate'],
    x="C", y="val", hue="model", style='model', 
    ax=axs[0],
    markers=True, dashes=False
)
axs[0].set_ylabel('(%)')
axs[0].set_title('False Alarm Rate')

sns.lineplot(
    data=majority_df[majority_df['type']=='anom_miss_rate'],
    x="C", y="val", hue="model", style='model', 
    ax=axs[1],
    markers=True, dashes=False
)
axs[1].set_ylabel('(%)')
axs[1].set_title('Anomaly Miss Rate')
handles, labels = axs[0].get_legend_handles_labels()
fig.legend(handles[1:], ['lgbm','rf','xgboost'], loc='lower left', bbox_to_anchor=(0.32, 1, 0.3, 0.4), ncol=3, frameon=True, mode='None',)
axs[0].get_legend().remove()
axs[1].get_legend().remove()

plt.suptitle('Majority Filtering')


palette= sns.color_palette("tab10")


sns.set_style("whitegrid")
sns.set_context("talk")


fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(20, 6))


sns.lineplot(
    data=consecutive_df[consecutive_df['type']=='false_alarm_rate'],
    x="C", y="val", hue="model", style='model', 
    ax=axs[0],
    markers=True, dashes=False
)
axs[0].set_ylabel('(%)')
axs[0].set_title('False Alarm Rate')

sns.lineplot(
    data=consecutive_df[consecutive_df['type']=='anom_miss_rate'],
    x="C", y="val", hue="model", style='model', 
    ax=axs[1],
    markers=True, dashes=False
)
axs[1].set_ylabel('(%)')
axs[1].set_title('Anomaly Miss Rate')

handles, labels = axs[0].get_legend_handles_labels()
fig.legend(handles[1:], ['lgbm','rf','xgboost'], loc='lower left', bbox_to_anchor=(0.32, 1, 0.3, 0.4), ncol=3, frameon=True, mode='None',)
axs[0].get_legend().remove()
axs[1].get_legend().remove()
plt.suptitle('Consecutive Filtering')<jupyter_output><empty_output><jupyter_text>Timing Comparison<jupyter_code>#TODO: sorting? 
MODELS = ['lgbm','rf','xgboost']
time_dict = {}
for MODEL in MODELS:
    if FS:
        MODEL = MODEL + '-fs'
    try:
        with open(model_config['results_dir'] / '{}_time_dict.json'.format(MODEL)) as f:
            temp_dict = json.load(f)
        time_dict[MODEL] = temp_dict[MODEL]
    except:
        print("{} does not exist".format(MODEL))
time_dict
dataframe = pd.DataFrame.from_dict(time_dict).transpose()#,orient='index',columns=['a','b','c','d','e'])
dataframe.round(2)
dataframe.index.name = 'model'
dataframe.reset_index(inplace=True)
dataframe.rename(columns={'training_time':'Training Time','inference_time':'Inference Time'},inplace=True)
dataframe
dataframe = pd.melt(dataframe, id_vars=['model'],value_vars=['Training Time','Inference Time'],value_name='time')

dataframe.loc[dataframe['variable'] == 'Training Time','scaled_time'] = dataframe.loc[dataframe['variable'] == 'Training Time']['time'] / min(dataframe.loc[dataframe['variable'] == 'Training Time']['time'])
dataframe.loc[dataframe['variable'] == 'Inference Time','scaled_time'] = dataframe.loc[dataframe['variable'] == 'Inference Time']['time'] / min(dataframe.loc[dataframe['variable'] == 'Inference Time']['time'])
dataframe.sort_values('scaled_time',inplace=True)
palette= sns.color_palette("tab10")

sns.set_style("whitegrid")
sns.set_context("talk")

g = sns.catplot(x='variable',y='scaled_time',                
                 palette = palette[3:6],
                 kind = 'bar',
                 #ax = axs[1],
                 height=6, aspect=2.7,
                 hue = 'model',
                 order =['Training Time','Inference Time'],
                 data=dataframe)
plt.title('Training and Inference Time Comparison',pad=30,fontdict={'fontsize': 20,'fontweight':'bold'})
plt.ylabel('Relative Time')
plt.xlabel('')
plt.yticks([])
#plt.xtickslabels(['Training Time','Inference Time'])

ax = g.facet_axis(0,0)
for p in ax.patches:
    ax.text(p.get_x() + 0.05, 
            p.get_height() * 1.05, 
           '{0:.1f}x'.format(p.get_height()),   #Used to format it K representation
            color='black', 
            rotation='horizontal', 
            size='large')<jupyter_output><empty_output><jupyter_text>OLD TIMING COMPARISON<jupyter_code>with open(model_config['results_dir'] / 'time_dict_fs.json') as f:
    time_dict = json.load(f)
    
dataframe = pd.DataFrame.from_dict(time_dict).transpose()#,orient='index',columns=['a','b','c','d','e'])
dataframe.round(2)
dataframe.index.name = 'model'
dataframe.reset_index(inplace=True)
dataframe.rename(columns={'training_time':'Training Time','inference_time':'Inference Time'},inplace=True)
dataframe
#added this due to thread thingy
dataframe.loc[dataframe['model'] == 'rf-fs','Training Time']= dataframe[dataframe['model'] == 'rf-fs']['Training Time'].values[0]*5
dataframe.loc[dataframe['model'] == 'rf-fs','Inference Time']= dataframe[dataframe['model'] == 'rf-fs']['Inference Time'].values[0]*3
dataframe = pd.melt(dataframe, id_vars=['model'],value_vars=['Training Time','Inference Time'],value_name='time')

dataframe.loc[dataframe['variable'] == 'Training Time','scaled_time'] = dataframe.loc[dataframe['variable'] == 'Training Time']['time'] / min(dataframe.loc[dataframe['variable'] == 'Training Time']['time'])
dataframe.loc[dataframe['variable'] == 'Inference Time','scaled_time'] = dataframe.loc[dataframe['variable'] == 'Inference Time']['time'] / min(dataframe.loc[dataframe['variable'] == 'Inference Time']['time'])
dataframe.sort_values('scaled_time',inplace=True)
palette= sns.color_palette("tab10")

sns.set_style("whitegrid")
sns.set_context("talk")

g = sns.catplot(x='variable',y='scaled_time',                
                 palette = palette[3:6],
                 kind = 'bar',
                 #ax = axs[1],
                 height=6, aspect=2.7,
                 hue = 'model',
                 order =['Training Time','Inference Time'],
                 data=dataframe)
plt.title('Training and Inference Time Comparison',pad=30,fontdict={'fontsize': 20,'fontweight':'bold'})
plt.ylabel('Relative Time')
plt.xlabel('')
plt.yticks([])
#plt.xtickslabels(['Training Time','Inference Time'])

ax = g.facet_axis(0,0)
for p in ax.patches:
    ax.text(p.get_x() + 0.05, 
            p.get_height() * 1.05, 
           '{0:.1f}x'.format(p.get_height()),   #Used to format it K representation
            color='black', 
            rotation='horizontal', 
            size='large')
#comingfrom when we run random forest with out nthread 
palette= sns.color_palette("tab10")

sns.set_style("whitegrid")
sns.set_context("talk")

g = sns.catplot(x='variable',y='time',                
                 palette = palette[4:7],
                 kind = 'bar',
                 #ax = axs[1],
                height=6, aspect=2.7,
                hue = 'model',
                 data=dataframe)
plt.title('Training and Inference Time Comparison')
plt.ylabel('Relative Time')
plt.xlabel('')
plt.yticks([])

ax = g.facet_axis(0,0)
for p in ax.patches:
    ax.text(p.get_x() + 0.05, 
            p.get_height() * 1.05, 
           '{0:.1f}x'.format(p.get_height()),   #Used to format it K representation
            color='black', 
            rotation='horizontal', 
            size='large')<jupyter_output><empty_output><jupyter_text>Single Plot for Paper<jupyter_code>sns.barplot(x='anomaly',y='f1-score',                
                 palette = palette,
                 dodge=False,                                  
                 data=f1_score_df[f1_score_df['model'] == 'rf'])

plt.title('F1-Scores for Window Size '+str(model_config['window_size']))
sns.barplot(y='false_alarm_rate',x='model',hue='model',
            #style='model',
            palette = palette,   
            dodge=False,
            data=alarm_score_df,ax=axs[1],capsize=.1)

axs[1].set_title('False Alarm Rate',
              pad=20)
axs[1].set_xlabel("")
axs[1].set_ylabel('')<jupyter_output><empty_output>