|
import pandas as pd |
|
|
|
output_file_path = 'outputs/experiment_1_gpt-4-turbo_100iters.csv' |
|
outputs_df = pd.read_csv(output_file_path) |
|
|
|
print(outputs_df.head()) |
|
|
|
|
|
|
|
def calculate_precision_recall(df): |
|
|
|
true_positives = df['Correct'].sum() |
|
total_predicted = len(df) |
|
total_actual = df['Misconception ID'].nunique() |
|
|
|
precision = true_positives / total_predicted if total_predicted else 0 |
|
recall = true_positives / total_actual if total_actual else 0 |
|
|
|
return precision, recall |
|
|
|
|
|
overall_precision, overall_recall = calculate_precision_recall(outputs_df) |
|
|
|
|
|
topic_precision_recall = outputs_df.groupby('Topic').apply(calculate_precision_recall).apply(pd.Series) |
|
topic_precision_recall.columns = ['Precision', 'Recall'] |
|
|
|
|
|
print(f"Overall Precision: {overall_precision:.3f}") |
|
print(f"Overall Recall: {overall_recall:.3f}") |
|
print("\nPrecision and Recall per Topic:") |
|
print(topic_precision_recall) |