Skip to content

Commit

Permalink
Added demo_results.csv file; changed PCI to be the abs value of the d…
Browse files Browse the repository at this point in the history
…iff; updated plots
  • Loading branch information
qinip committed Sep 23, 2024
1 parent a55fe04 commit 0fefa92
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 14 deletions.
24 changes: 24 additions & 0 deletions results/demo_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Train Start,Train End,Pred Start,Pred End,Test F1,Pred F1
2018-01-01,2022-01-01,2022-01-02,2022-04-01,0.615953947368421,0.4787234042553192
2018-02-01,2022-02-01,2022-02-02,2022-05-01,0.6178199909543193,0.5253623188405797
2018-03-01,2022-03-01,2022-03-02,2022-06-01,0.5974754558204769,0.5703422053231939
2018-04-01,2022-04-01,2022-04-02,2022-07-01,0.6084257206208425,0.5390625
2018-05-01,2022-05-01,2022-05-02,2022-08-01,0.6137767220902612,0.5656192236598891
2018-06-01,2022-06-01,2022-06-02,2022-09-01,0.5934065934065934,0.5559655596555966
2018-07-01,2022-07-01,2022-07-02,2022-10-01,0.5897542690545606,0.5067064083457526
2018-08-01,2022-08-01,2022-08-02,2022-11-01,0.5713083718973496,0.5566714490674318
2018-09-01,2022-09-01,2022-09-02,2022-12-01,0.6029055690072639,0.5910290237467019
2018-10-01,2022-10-01,2022-10-02,2023-01-01,0.5700301204819277,0.5462962962962963
2018-11-01,2022-11-01,2022-11-02,2023-02-01,0.590539894887721,0.5226130653266332
2018-12-01,2022-12-01,2022-12-02,2023-03-01,0.5750337990085624,0.4334705075445816
2019-01-01,2023-01-01,2023-01-02,2023-04-01,0.591604938271605,0.4949832775919732
2019-02-01,2023-02-01,2023-02-02,2023-05-01,0.5755248335893497,0.4581939799331103
2019-03-01,2023-03-01,2023-03-02,2023-06-01,0.5484913793103449,0.5085995085995086
2019-04-01,2023-04-01,2023-04-02,2023-07-01,0.5816692268305171,0.5619596541786743
2019-05-01,2023-05-01,2023-05-02,2023-08-01,0.5583153347732182,0.5398773006134969
2019-06-01,2023-06-01,2023-06-02,2023-09-01,0.5728531855955679,0.513595166163142
2019-07-01,2023-07-01,2023-07-02,2023-10-01,0.5687361419068736,0.5167464114832536
2019-08-01,2023-08-01,2023-08-02,2023-11-01,0.5659369994660972,0.5530085959885387
2019-09-01,2023-09-01,2023-09-02,2023-12-01,0.5542168674698795,0.5
2019-10-01,2023-10-01,2023-10-02,2024-01-01,0.5565978736710444,0.5073313782991202
2019-11-01,2023-11-01,2023-11-02,2024-02-01,0.5650557620817844,0.4870848708487085
Binary file modified results/figures/f1_diff_over_time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified results/figures/f1_scores_over_time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 51 additions & 13 deletions src/analysis_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def plot_results(df, event_dates, output_dir='../results/figures'):

# Plot the results
plt.figure(figsize=(12, 6), facecolor='white')
sns.set_style("white") # 使用白色背景,不包含网格线
sns.set_style("white")

ax = sns.lineplot(data=plot_df, x='Pred End', y='Test F1', label='Test F1', color='navy')
sns.lineplot(data=plot_df, x='Pred End', y='Pred F1', label='Pred F1', color='crimson')

# 移除网格线
# Remove grids
ax.grid(False)

# Add vertical lines for important events and event descriptions
Expand All @@ -105,30 +105,48 @@ def plot_results(df, event_dates, output_dir='../results/figures'):
ax.text(event_date, event_position, event_desc, rotation=0, ha='left', va='center', fontsize=8)

plt.title('Test and Prediction F1 Over Time', fontsize=16)
plt.xlabel('Prediction End Date', fontsize=14)
plt.ylabel('F1 Score', fontsize=14)
plt.xticks(rotation=45)
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))

# Set x-axis ticks to every two months

# Set x-axis ticks to every two months and rotate labels
ax.xaxis.set_major_locator(mdates.MonthLocator(interval=2))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
plt.xticks(rotation=45, ha='right', rotation_mode='anchor')

# Adjust the x-axis limits to show the desired time range
ax.set_xlim([datetime(2022, 2, 1), datetime(2024, 4, 30)])

# Remove x-axis label
ax.set_xlabel('')

# Configure tick lines to protrude downward
ax.tick_params(
axis='x',
which='major',
direction='out', # Tick direction outward (downward)
length=5, # Length of major ticks
width=1, # Width of tick lines
colors='black', # Color of tick lines
pad=2, # Distance between tick labels and tick lines
bottom=True, # Show ticks at the bottom
top=False # Don't show ticks at the top
)

# Ensure the bottom spine is visible and styled
ax.spines['bottom'].set_visible(True)
ax.spines['bottom'].set_linewidth(1)
ax.spines['bottom'].set_color('black')

plt.tight_layout() # Adjust the plot to ensure everything fits without overlapping
plt.savefig(output_file_1, dpi=300, bbox_inches='tight', facecolor='white') # Set facecolor to 'white'
plt.show()

# Second plot to show the difference between the test and prediction F1
plt.figure(figsize=(12, 6), facecolor='white')
sns.set_style("white") # 使用白色背景,不包含网格线
sns.set_style("white")

plot_df['F1 Diff'] = plot_df['Test F1'] - plot_df['Pred F1']
ax = sns.lineplot(data=plot_df, x='Pred End', y='F1 Diff')

# 移除网格线
ax.grid(False)

# Add vertical lines for important events and event descriptions
Expand All @@ -143,20 +161,40 @@ def plot_results(df, event_dates, output_dir='../results/figures'):

plt.ylabel('Policy Change Index for North Korea', fontsize=14)
plt.axhline(0, color='red', linestyle='--') # Add a horizontal line at 0
plt.xticks(rotation=45)

# Set x-axis ticks to every two months

# Set x-axis ticks to every two months and rotate labels
ax.xaxis.set_major_locator(mdates.MonthLocator(interval=2))
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
plt.xticks(rotation=45, ha='right', rotation_mode='anchor')

# Adjust the x-axis limits to show the desired time range
ax.set_xlim([datetime(2022, 2, 1), datetime(2024, 4, 30)])

# Remove x-axis label
ax.set_xlabel('')

# Configure tick lines to protrude downward
ax.tick_params(
axis='x',
which='major',
direction='out', # Tick direction outward (downward)
length=5, # Length of major ticks
width=1, # Width of tick lines
colors='black', # Color of tick lines
pad=2, # Distance between tick labels and tick lines
bottom=True, # Show ticks at the bottom
top=False # Don't show ticks at the top
)

# Ensure the bottom spine is visible and styled
ax.spines['bottom'].set_visible(True)
ax.spines['bottom'].set_linewidth(1)
ax.spines['bottom'].set_color('black')

plt.tight_layout()
plt.savefig(output_file_2, dpi=300, bbox_inches='tight', facecolor='white') # Set facecolor to 'white'
plt.show()


###########################################################
## 2. LLM analysis

Expand Down
2 changes: 1 addition & 1 deletion src/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def main(args):
columns=['Train Start', 'Train End', 'Pred Start', 'Pred End', 'Test F1', 'Pred F1'])

all_res = pd.concat([all_res, res], ignore_index=True)
all_res['PCI'] = (all_res['Test F1'] - all_res['Pred F1'])
all_res['PCI'] = abs((all_res['Test F1'] - all_res['Pred F1']))
all_res.to_csv(all_res_file, index=False)

# Print the full training history
Expand Down

0 comments on commit 0fefa92

Please sign in to comment.