ContextualCountEmbedder
srai.embedders.ContextualCountEmbedder(
neighbourhood,
neighbourhood_distance,
concatenate_vectors=False,
expected_output_features=None,
count_subcategories=False,
)
¶
srai.embedders.ContextualCountEmbedder(
neighbourhood,
neighbourhood_distance,
concatenate_vectors=False,
expected_output_features=None,
count_subcategories=False,
)
Bases: CountEmbedder
ContextualCountEmbedder.
PARAMETER | DESCRIPTION |
---|---|
neighbourhood |
Neighbourhood object used to get neighbours for the contextualization.
TYPE:
|
neighbourhood_distance |
How many neighbours levels should be included in the embedding.
TYPE:
|
concatenate_vectors |
Whether to sum all neighbours into a single vector
with the same width as
TYPE:
|
count_subcategories |
Whether to count all subcategories individually or count features only on the highest level based on features column name. Defaults to False.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If |
Source code in srai/embedders/contextual_count_embedder.py
¶
Embed a given GeoDataFrame.
Creates region embeddings by counting the frequencies of each feature value and applying a contextualization based on neighbours of regions. For each region, features will be altered based on the neighbours either by adding averaged values dimished based on distance, or by adding new separate columns with neighbour distance postfix. Expects features_gdf to be in wide format with each column being a separate type of feature (e.g. amenity, leisure) and rows to hold values of these features for each object. The rows will hold numbers of this type of feature in each region. Numbers can be fractional because neighbourhoods are averaged to represent a single value from all neighbours on a given level.
PARAMETER | DESCRIPTION |
---|---|
regions_gdf |
Region indexes and geometries.
TYPE:
|
features_gdf |
Feature indexes, geometries and feature values.
TYPE:
|
joint_gdf |
Joiner result with region-feature multi-index.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
pd.DataFrame
|
pd.DataFrame: Embedding for each region in regions_gdf. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If features_gdf is empty and self.expected_output_features is not set. |
ValueError
|
If any of the gdfs index names is None. |
ValueError
|
If joint_gdf.index is not of type pd.MultiIndex or doesn't have 2 levels. |
ValueError
|
If index levels in gdfs don't overlap correctly. |