[text] geo Ia

Viewer

  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. clusters = {
  5.     "A": {"Temperature": 16.588, "PM 10": 18.2, "PM 2.5": 16.5, "CO2": 723.76, "Cars/min": 25.08, "Sound Level": 51.8, "Trees": 25, "Value": 427714},
  6.     "B": {"Temperature": 17.7, "PM 10": 8.2, "PM 2.5": 6.08421052631579, "CO2": 666.789473684211, "Cars/min": 44.4210526315789, "Sound Level": 58.4736842105263, "Trees": 13, "Value": 314438},
  7.     "C": {"Temperature": 14.58, "PM 10": 11.316, "PM 2.5": 8.0, "CO2": 662.84, "Cars/min": 19.28, "Sound Level": 69.0, "Trees": 16, "Value": 374867},
  8.     "D": {"Temperature": 16.0631578947368, "PM 10": 11.73, "PM 2.5": 6.4, "CO2": 479.65, "Cars/min": 40.2, "Sound Level": 65.45, "Trees": 15, "Value": 442588},
  9.     "E": {"Temperature": 14.2, "PM 10": 7.6, "PM 2.5": 5.14, "CO2": 459.6, "Cars/min": 12.6, "Sound Level": 67.2, "Trees": 22, "Value": 218267},
  10. }
  11.  
  12. categories = ["Temperature", "PM 10", "PM 2.5", "CO2", "Cars/min", "Sound Level", "Trees"]
  13.  
  14. for category in categories:
  15.     x = [cluster[category] for cluster in clusters.values()]
  16.     y = [cluster["Value"] for cluster in clusters.values()]
  17.     labels = list(clusters.keys())
  18.  
  19.     plt.scatter(x, y)
  20.     
  21.     # Add the average line
  22.     average = np.mean(x)
  23.     plt.axvline(x=average, color="r", linestyle="--", label=f"Average {category}")
  24.  
  25.     for i, label in enumerate(labels):
  26.         plt.annotate(label, (x[i], y[i]))
  27.  
  28.     plt.xlabel(category)
  29.     plt.ylabel("Land Value")
  30.     plt.legend()
  31.     plt.title(f"Scatter plot of Land Value vs {category}")
  32.     
  33.     # Calculate the correlation coefficient
  34.     correlation = np.corrcoef(x, y)[0, 1]
  35.     print(f"Correlation coefficient (r) for {category}: {correlation:.2f}")
  36.  
  37.     plt.show()
  38.  

Editor

You can edit this paste and save as new: