momepy.mean_deviation#
- momepy.mean_deviation(y, graph)[source]#
Calculate the mean deviation of each
y
value and its graph neighbours.\[\frac{1}{n}\sum_{i=1}^n dev_i=\frac{dev_1+dev_2+\cdots+dev_n}{n}\]- Parameters:
- ySeries
A Series containing the values to be analysed.
- graphlibpysal.graph.Graph
Graph representing spatial relationships between elements.
- Returns:
- Series
Examples
>>> from libpysal import graph >>> path = momepy.datasets.get_path("bubenec") >>> buildings = geopandas.read_file(path, layer="buildings") >>> buildings.head() uID geometry 0 1 POLYGON ((1603599.221 6464369.816, 1603602.984... 1 2 POLYGON ((1603042.88 6464261.498, 1603038.961 ... 2 3 POLYGON ((1603044.65 6464178.035, 1603049.192 ... 3 4 POLYGON ((1603036.557 6464141.467, 1603036.969... 4 5 POLYGON ((1603082.387 6464142.022, 1603081.574...
Define spatial graph:
>>> knn5 = graph.Graph.build_knn(buildings.centroid, k=5) >>> knn5 <Graph of 144 nodes and 720 nonzero edges indexed by [0, 1, 2, 3, 4, ...]>
Mean deviation of building area and area of 5 nearest neighbors:
>>> momepy.mean_deviation(buildings.area, knn5) 0 281.179149 1 10515.948995 2 2240.706061 3 230.360732 4 68.719810 ... 139 259.180720 140 517.496703 141 331.849751 142 25.297225 143 654.691897 Length: 144, dtype: float64