@@ -63,7 +63,7 @@ def extract_data(lat, lon, file_path):
6363
6464 return total_population if 0 <= px < src.width and 0 <= py < src.height else None
6565
66- from scipy.stats import spearmanr
66+ from scipy.stats import spearmanr, pearsonr
6767
6868
6969#Define Spearman Correlation Function
@@ -72,6 +72,13 @@ def calculate_spearman_correlation(coordinates, predictions, groundtruth_tif):
7272 corr, _ = spearmanr(predictions, groundtruth)
7373 return corr
7474
75+ #Define function to calculate Pearson Correlation via pearsonr module and extract data function
76+ def calculate_pearson_correlation(coordinates, predictions, groundtruth_tif):
77+ groundtruth = [extract_data(lat, lon, groundtruth_tif) for lat, lon in coordinates]
78+ corr1, _ = pearsonr(predictions, groundtruth)
79+ return corr1
80+
81+
7582PROMPT_FILE = "world_prompts.jsonl"
7683TASK = "population density"
7784OUTPUT_FILE = "gemma3_results.csv"
@@ -127,11 +134,20 @@ else:
127134
128135
129136
130- # Lastly lets run the spearman correction
137+ #Run the spearman correction
131138corr = calculate_spearman_correlation(coordinates, predictions, groundtruth_tif)
132139
133140print(f"Spearman correlation: {corr:.2f}")
134141
135142
143+ #Run Pearson correlation function and print results
144+ corr1 = calculate_pearson_correlation(coordinates, predictions, groundtruth_tif)
145+ print(f"Pearson correlation: {corr1:.2f}")
146+
147+ #Calculate r^2 value which is used in the article by Manvi et al and print results
148+ r2 = corr1**2
149+ print(f"r^2 value: {r2:.2f}")
150+
151+
136152
137153
0 commit comments