job-fair / util /plot.py
Zekun Wu
update
3f8a515
raw
history blame
2.91 kB
import pandas as pd
import plotly.graph_objs as go
import plotly.express as px
def create_score_plot(df):
fig = go.Figure()
fig.add_trace(go.Scatter(
x=df.index, y=df['Privilege_Avg_Score'],
mode='lines+markers', name='Privilege',
text=df['Role'], hoverinfo='text+y'
))
fig.add_trace(go.Scatter(
x=df.index, y=df['Protect_Avg_Score'],
mode='lines+markers', name='Protection',
text=df['Role'], hoverinfo='text+y'
))
fig.add_trace(go.Scatter(
x=df.index, y=df['Neutral_Avg_Score'],
mode='lines+markers', name='Neutral',
text=df['Role'], hoverinfo='text+y'
))
fig.update_layout(
title=f'Scores of Resumes',
xaxis_title='Resume Index',
yaxis_title='Score',
legend_title='Score Type',
hovermode='closest'
)
return fig
def create_rank_plots(df):
fig = go.Figure()
# Add traces for ranks
fig.add_trace(go.Scatter(
x=df.index, y=df['Privilege_Rank'],
mode='lines+markers', name='Privilege',
text=df['Role'], hoverinfo='text+y'
))
fig.add_trace(go.Scatter(
x=df.index, y=df['Protect_Rank'],
mode='lines+markers', name='Protection',
text=df['Role'], hoverinfo='text+y'
))
fig.add_trace(go.Scatter(
x=df.index, y=df['Neutral_Rank'],
mode='lines+markers', name='Neutral',
text=df['Role'], hoverinfo='text+y'
))
# Update layout
fig.update_layout(
title='Ranks of Scores',
xaxis_title='Resume Index',
yaxis_title='Rank',
legend_title='Rank Type',
hovermode='closest'
)
return fig
def create_correlation_heatmaps(df):
scores_df = df[['Privilege_Avg_Score', 'Protect_Avg_Score', 'Neutral_Avg_Score']]
ranks_df = df[['Privilege_Rank', 'Protect_Rank', 'Neutral_Rank']]
# Pearson correlation
scores_corr_pearson = scores_df.corr(method='pearson')
ranks_corr_pearson = ranks_df.corr(method='pearson')
# Spearman correlation
scores_corr_spearman = scores_df.corr(method='spearman')
ranks_corr_spearman = ranks_df.corr(method='spearman')
# Kendall Tau correlation
scores_corr_kendall = scores_df.corr(method='kendall')
ranks_corr_kendall = ranks_df.corr(method='kendall')
# Plotting the heatmaps separately
heatmaps = {
'Scores Pearson Correlation': scores_corr_pearson,
'Ranks Pearson Correlation': ranks_corr_pearson,
'Scores Spearman Correlation': scores_corr_spearman,
'Ranks Spearman Correlation': ranks_corr_spearman,
'Scores Kendall Correlation': scores_corr_kendall,
'Ranks Kendall Correlation': ranks_corr_kendall
}
figs = {}
for title, corr_matrix in heatmaps.items():
fig = px.imshow(corr_matrix, text_auto=True, title=title)
figs[title] = fig
return figs