Services collocation

[1]:
import pandas as pd

blocks_gdf = pd.read_pickle('./../../data/saint_petersburg/blocks.pickle')
[3]:
from blocksnet.analysis.services import services_collocation

collocation_mx = services_collocation(blocks_gdf)
[4]:
collocation_mx
[4]:
school kindergarten hospital polyclinic pitch swimming_pool theatre museum cinema mall ... train_station bus_station bus_stop pier animal_shelter prison landfill plant_nursery greenhouse_complex warehouse
school 0.218841 0.411341 0.016645 0.119048 0.423715 0.033602 0.035248 0.036385 0.018767 0.093637 ... 0.001366 0.000000 0.176186 0.018496 0.000000 0.001433 0.002778 0.001427 0.002786 0.021135
kindergarten 0.411341 0.424829 0.018672 0.119048 0.355828 0.029032 0.044728 0.033784 0.019355 0.087043 ... 0.002176 0.000000 0.213359 0.019095 0.000000 0.000000 0.001100 0.000000 0.003315 0.025974
hospital 0.016645 0.018672 0.163462 0.047782 0.024452 0.022346 0.004854 0.027682 0.000000 0.003086 ... 0.000000 0.000000 0.022393 0.016949 0.000000 0.000000 0.000000 0.008696 0.015152 0.012195
polyclinic 0.119048 0.119048 0.047782 0.206897 0.102349 0.029197 0.044369 0.028571 0.014870 0.081633 ... 0.000000 0.000000 0.057602 0.011940 0.000000 0.000000 0.000000 0.000000 0.000000 0.031100
pitch 0.423715 0.355828 0.024452 0.102349 0.522052 0.038394 0.027942 0.033281 0.019862 0.081169 ... 0.001736 0.002691 0.241527 0.021294 0.000896 0.003584 0.003512 0.002679 0.007061 0.029208
swimming_pool 0.033602 0.029032 0.022346 0.029197 0.038394 0.050633 0.022472 0.030303 0.020548 0.030928 ... 0.000000 0.000000 0.016075 0.014151 0.000000 0.000000 0.009091 0.000000 0.000000 0.006557
theatre 0.035248 0.044728 0.004854 0.044369 0.027942 0.022472 0.067961 0.084249 0.035928 0.031847 ... 0.000000 0.000000 0.020354 0.071749 0.000000 0.000000 0.000000 0.008772 0.007576 0.006079
museum 0.036385 0.033784 0.027682 0.028571 0.033281 0.030303 0.084249 0.207254 0.027344 0.024752 ... 0.000000 0.000000 0.034845 0.082237 0.000000 0.000000 0.008969 0.014851 0.032407 0.016908
cinema 0.018767 0.019355 0.000000 0.014870 0.019862 0.020548 0.035928 0.027344 0.014286 0.168675 ... 0.000000 0.000000 0.018862 0.014778 0.000000 0.000000 0.000000 0.000000 0.000000 0.010169
mall 0.093637 0.087043 0.003086 0.081633 0.081169 0.030928 0.031847 0.024752 0.168675 0.153846 ... 0.003802 0.000000 0.060080 0.014205 0.000000 0.000000 0.000000 0.000000 0.004000 0.018141
convenience 0.286079 0.334545 0.022190 0.099352 0.314085 0.027086 0.040846 0.040466 0.022744 0.084972 ... 0.004409 0.002259 0.290021 0.025281 0.001506 0.003010 0.000738 0.000749 0.000739 0.038127
supermarket 0.302269 0.359848 0.017946 0.124498 0.316883 0.031056 0.050463 0.032558 0.057878 0.148335 ... 0.001043 0.001083 0.231161 0.022330 0.001085 0.000000 0.001055 0.000000 0.002116 0.029676
cemetery 0.001304 0.002096 0.016760 0.003571 0.006774 0.000000 0.005556 0.022642 0.000000 0.003356 ... 0.000000 0.000000 0.012012 0.004695 0.000000 0.000000 0.009174 0.011236 0.018868 0.006579
religion 0.046296 0.040000 0.046053 0.029630 0.044953 0.017361 0.032573 0.054404 0.017921 0.028369 ... 0.003906 0.000000 0.049685 0.032448 0.004566 0.009050 0.000000 0.000000 0.008264 0.023148
market 0.022008 0.023077 0.019481 0.049180 0.020158 0.039370 0.006452 0.008197 0.016529 0.053846 ... 0.000000 0.000000 0.014160 0.010695 0.000000 0.000000 0.000000 0.000000 0.000000 0.018116
university 0.054762 0.045764 0.034483 0.047244 0.062602 0.037736 0.064057 0.077562 0.019157 0.014599 ... 0.000000 0.000000 0.043723 0.053968 0.000000 0.004902 0.004405 0.000000 0.018018 0.021687
playground 0.308555 0.386744 0.022556 0.100445 0.419580 0.024219 0.034898 0.045565 0.022393 0.069071 ... 0.002553 0.001305 0.302062 0.024631 0.000652 0.001303 0.001927 0.001300 0.003220 0.025701
pharmacy 0.322333 0.392857 0.030825 0.117541 0.326733 0.030584 0.043159 0.038983 0.044508 0.135870 ... 0.002796 0.000962 0.263225 0.022747 0.000963 0.000961 0.000940 0.000000 0.001885 0.030229
fuel 0.029795 0.032721 0.007752 0.013093 0.043746 0.016427 0.009728 0.008278 0.008299 0.040850 ... 0.006579 0.009547 0.088121 0.012844 0.004762 0.002358 0.002237 0.002342 0.000000 0.055738
beach 0.001312 0.002107 0.005682 0.000000 0.017182 0.020134 0.005714 0.023077 0.000000 0.000000 ... 0.000000 0.000000 0.008997 0.009662 0.000000 0.000000 0.009615 0.011905 0.019802 0.003333
train_building 0.000000 0.000000 0.008065 0.004484 0.002657 0.000000 0.000000 0.004695 0.000000 0.000000 ... 0.000000 0.000000 0.004387 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.004032
bank 0.225869 0.217028 0.014837 0.123386 0.186667 0.029687 0.067187 0.067680 0.065574 0.129760 ... 0.003221 0.000000 0.144383 0.036179 0.001709 0.003407 0.000000 0.000000 0.000000 0.029299
lawyer 0.045514 0.040923 0.018692 0.046205 0.032013 0.026596 0.095960 0.051370 0.051429 0.046875 ... 0.000000 0.000000 0.028141 0.046025 0.000000 0.000000 0.000000 0.000000 0.000000 0.023952
cafe 0.215331 0.260434 0.024038 0.076506 0.229936 0.024458 0.057488 0.071913 0.040714 0.101370 ... 0.003509 0.002157 0.269220 0.042437 0.001438 0.002874 0.003536 0.000715 0.002122 0.045984
subway_entrance 0.033113 0.029787 0.015707 0.042705 0.033563 0.030488 0.048913 0.032847 0.088435 0.095070 ... 0.007576 0.000000 0.028022 0.018018 0.000000 0.010204 0.000000 0.000000 0.000000 0.012739
multifunctional_center 0.038997 0.041249 0.000000 0.044355 0.035492 0.007463 0.012739 0.004032 0.024390 0.033582 ... 0.000000 0.000000 0.017574 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.003534
hairdresser 0.293249 0.373306 0.023693 0.098294 0.298851 0.025042 0.053872 0.048438 0.035684 0.104839 ... 0.002523 0.000000 0.244391 0.032958 0.000867 0.001730 0.000847 0.000000 0.001699 0.025316
restaurant 0.173736 0.196324 0.015476 0.088000 0.175727 0.027295 0.074401 0.092807 0.055412 0.129220 ... 0.001264 0.002653 0.158586 0.053571 0.000000 0.000000 0.001282 0.003958 0.010376 0.024109
bar 0.168168 0.179286 0.022887 0.079365 0.141625 0.025830 0.076067 0.073718 0.047893 0.102686 ... 0.000000 0.000000 0.106383 0.042517 0.002075 0.002062 0.000000 0.000000 0.001976 0.017316
park 0.172131 0.196698 0.024000 0.055159 0.231699 0.021354 0.024420 0.049525 0.018138 0.053522 ... 0.006039 0.001627 0.349377 0.032669 0.001220 0.001219 0.005253 0.001217 0.003228 0.044358
government 0.091319 0.087488 0.010582 0.066519 0.063553 0.017094 0.070225 0.095349 0.035714 0.061702 ... 0.003125 0.000000 0.056191 0.067010 0.000000 0.003497 0.003236 0.000000 0.006536 0.016064
recruitment 0.017070 0.013468 0.007812 0.022422 0.011576 0.000000 0.000000 0.000000 0.000000 0.008197 ... 0.000000 0.000000 0.007097 0.006250 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
hotel 0.098990 0.103806 0.022403 0.056239 0.085612 0.025806 0.101099 0.082418 0.035398 0.038591 ... 0.002273 0.002475 0.077442 0.072289 0.000000 0.002463 0.000000 0.000000 0.004695 0.026230
zoo 0.008511 0.006719 0.000000 0.009009 0.009813 0.000000 0.008130 0.014218 0.058140 0.016807 ... 0.000000 0.037037 0.005405 0.000000 0.000000 0.000000 0.000000 0.000000 0.020000 0.004032
circus 0.002894 0.001136 0.000000 0.000000 0.000898 0.000000 0.029126 0.005128 0.000000 0.000000 ... 0.000000 0.000000 0.000677 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
post 0.186522 0.179899 0.028278 0.121348 0.145765 0.030220 0.058355 0.029474 0.022346 0.070393 ... 0.000000 0.000000 0.077918 0.021277 0.000000 0.000000 0.000000 0.003257 0.003077 0.025440
police 0.136732 0.140488 0.010230 0.090508 0.112698 0.033520 0.036842 0.031983 0.016901 0.066667 ... 0.000000 0.000000 0.073058 0.023981 0.003378 0.003344 0.003106 0.000000 0.003125 0.019646
dog_park 0.019526 0.012115 0.000000 0.004115 0.014978 0.008403 0.000000 0.004292 0.000000 0.007692 ... 0.000000 0.000000 0.011479 0.000000 0.000000 0.000000 0.013889 0.000000 0.000000 0.007491
hostel 0.039340 0.039216 0.013043 0.031056 0.029900 0.009709 0.089202 0.059211 0.031088 0.026393 ... 0.000000 0.000000 0.026631 0.064257 0.000000 0.007299 0.000000 0.000000 0.006329 0.008475
bakery 0.195144 0.221417 0.013643 0.100654 0.180040 0.028653 0.073806 0.068036 0.067771 0.140584 ... 0.000000 0.000000 0.151923 0.040268 0.001553 0.003096 0.001493 0.003082 0.004505 0.024823
parking 0.188796 0.215150 0.028801 0.067929 0.241093 0.032809 0.024700 0.039003 0.026658 0.084646 ... 0.004084 0.003487 0.269019 0.020833 0.002091 0.002784 0.002740 0.002082 0.003432 0.053968
guest_house 0.035433 0.034958 0.004950 0.030717 0.020236 0.011364 0.086022 0.061818 0.030488 0.015873 ... 0.000000 0.000000 0.018339 0.053812 0.000000 0.000000 0.000000 0.000000 0.007812 0.006154
reserve 0.000000 0.000000 0.000000 0.000000 0.001776 0.000000 0.008403 0.009615 0.000000 0.000000 ... 0.000000 0.000000 0.001685 0.000000 0.000000 0.000000 0.000000 0.035714 0.021739 0.000000
sanatorium 0.005312 0.009615 0.023952 0.011236 0.015517 0.028169 0.011905 0.007752 0.007353 0.006993 ... 0.000000 0.000000 0.010364 0.009950 0.000000 0.000000 0.000000 0.000000 0.000000 0.003401
machine_building_plant 0.004011 0.004278 0.006098 0.011494 0.006009 0.014493 0.000000 0.003953 0.000000 0.007143 ... 0.000000 0.000000 0.015146 0.010256 0.000000 0.000000 0.000000 0.000000 0.000000 0.043321
brewery 0.009859 0.008919 0.007692 0.008772 0.010657 0.000000 0.007752 0.004566 0.010417 0.012245 ... 0.000000 0.000000 0.007092 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.011905
woodworking_plant 0.005236 0.007376 0.000000 0.007168 0.009338 0.019481 0.011173 0.007435 0.013699 0.013559 ... 0.008333 0.000000 0.017444 0.009434 0.000000 0.000000 0.000000 0.000000 0.009346 0.044369
wastewater_plant 0.000000 0.000000 0.008065 0.009009 0.002657 0.010101 0.000000 0.004695 0.000000 0.000000 ... 0.000000 0.000000 0.002358 0.006410 0.000000 0.000000 0.000000 0.000000 0.020000 0.012195
water_works 0.002869 0.002260 0.000000 0.000000 0.001789 0.000000 0.000000 0.004975 0.000000 0.004367 ... 0.000000 0.000000 0.002028 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.004237
substation 0.074971 0.077960 0.008746 0.057007 0.083267 0.015823 0.039157 0.043165 0.033113 0.066820 ... 0.007067 0.000000 0.056510 0.013405 0.000000 0.004000 0.007353 0.000000 0.003690 0.030702
train_station 0.001366 0.002176 0.000000 0.000000 0.001736 0.000000 0.000000 0.000000 0.000000 0.003802 ... 0.023256 0.000000 0.006040 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.003704
bus_station 0.000000 0.000000 0.000000 0.000000 0.002691 0.000000 0.000000 0.000000 0.000000 0.000000 ... 0.000000 0.000000 0.002369 0.000000 0.000000 0.000000 0.000000 0.000000 0.027778 0.000000
bus_stop 0.176186 0.213359 0.022393 0.057602 0.241527 0.016075 0.020354 0.034845 0.018862 0.060080 ... 0.006040 0.002369 0.436548 0.020469 0.001014 0.002367 0.003022 0.001688 0.005051 0.043949
pier 0.018496 0.019095 0.016949 0.011940 0.021294 0.014151 0.071749 0.082237 0.014778 0.014205 ... 0.000000 0.000000 0.020469 0.227941 0.000000 0.000000 0.005988 0.013699 0.012195 0.016760
animal_shelter 0.000000 0.000000 0.000000 0.000000 0.000896 0.000000 0.000000 0.000000 0.000000 0.000000 ... 0.000000 0.000000 0.001014 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
prison 0.001433 0.000000 0.000000 0.000000 0.003584 0.000000 0.000000 0.000000 0.000000 0.000000 ... 0.000000 0.000000 0.002367 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.004237
landfill 0.002778 0.001100 0.000000 0.000000 0.003512 0.009091 0.000000 0.008969 0.000000 0.000000 ... 0.000000 0.000000 0.003022 0.005988 0.000000 0.000000 0.218750 0.023256 0.016393 0.007752
plant_nursery 0.001427 0.000000 0.008696 0.000000 0.002679 0.000000 0.008772 0.014851 0.000000 0.000000 ... 0.000000 0.000000 0.001688 0.013699 0.000000 0.000000 0.023256 0.083333 0.135135 0.004184
greenhouse_complex 0.002786 0.003315 0.015152 0.000000 0.007061 0.000000 0.007576 0.032407 0.000000 0.004000 ... 0.000000 0.027778 0.005051 0.012195 0.000000 0.000000 0.016393 0.135135 0.066667 0.007812
warehouse 0.021135 0.025974 0.012195 0.031100 0.029208 0.006557 0.006079 0.016908 0.010169 0.018141 ... 0.003704 0.000000 0.043949 0.016760 0.000000 0.004237 0.007752 0.004184 0.007812 0.153509

60 rows × 60 columns

[16]:
import matplotlib.pyplot as plt

plt.figure(figsize=(10, 8))
plt.imshow(collocation_mx, cmap='RdYlGn', vmin=0, vmax=1)
plt.colorbar(label='Collocation value')

plt.xticks(range(len(collocation_mx.columns)), collocation_mx.columns, fontsize=8, rotation=90, ha='right')
plt.yticks(range(len(collocation_mx.index)), collocation_mx.index, fontsize=8)

plt.title("Services collocation matrix")
plt.tight_layout()
plt.show()
../../../_images/examples_analysis_services_collocation_4_0.png