coordinate_clustering

class CoordinateEuclideanClusterer(clusterer: sensai.clustering.clustering_base.EuclideanClusterer)[source]

Bases: sensai.clustering.clustering_base.EuclideanClusterer, sensai.geoanalytics.geopandas.coordinates.GeoDataFrameWrapper

Wrapper around a clustering model. This class adds additional, geospatial-specific features to the provided clusterer

Parameters

clusterer – an instance of ClusteringModel

__init__(clusterer: sensai.clustering.clustering_base.EuclideanClusterer)
class Cluster(coordinates: numpy.ndarray, identifier: Union[str, int])

Bases: sensai.clustering.clustering_base.EuclideanClusterer.Cluster, sensai.geoanalytics.geopandas.coordinates.GeoDataFrameWrapper, sensai.util.cache.LoadSaveInterface

Wrapper around a coordinates array

Parameters
  • coordinates

  • identifier

__init__(coordinates: numpy.ndarray, identifier: Union[str, int])
to_geodf(crs='epsg:3857')

Export the cluster as a GeoDataFrame of length 1 with the cluster as an instance of MultiPoint and the identifier as index.

Parameters

crs – projection. By default pseudo-mercator

Returns

GeoDataFrame

as_multipoint()
Returns

The cluster’s coordinates as a MultiPoint object

classmethod load(path)

Instantiate from a geopandas readable file containing a single row with an identifier and an instance of MultiPoint

Parameters

path

Returns

instance of CoordinateCluster

save(path, crs='EPSG:3857')

Saves the cluster’s coordinates as shapefile

Parameters
  • crs

  • path

Returns

fit(coordinates: Union[numpy.ndarray, shapely.geometry.MultiPoint, geopandas.GeoDataFrame, sensai.clustering.clustering_base.EuclideanClusterer.Cluster])

Fitting to coordinates from a numpy array, a MultiPoint object or a GeoDataFrame with one Point per row

Parameters

coordinates

Returns

to_geodf(condition: Callable[[sensai.geoanalytics.geopandas.coordinate_clustering.CoordinateEuclideanClusterer.Cluster], bool] = None, crs='epsg:3857', include_noise=False) geopandas.GeoDataFrame

GeoDataFrame containing all clusters found by the model. It is a concatenation of GeoDataFrames of individual clusters

Parameters
  • condition – if provided, only clusters fulfilling the condition will be included

  • crs – projection. By default pseudo-mercator

  • include_noise

Returns

GeoDataFrame with all clusters indexed by their identifier

plot(include_noise=False, condition=None, **kwargs)

Plots the resulting clusters with random coloring

Parameters
  • include_noise – Whether to include the noise cluster

  • condition – If provided, only clusters fulfilling this condition will be included

  • kwargs – passed to GeoDataFrame.plot

Returns

get_cluster(cluster_id: int) sensai.geoanalytics.geopandas.coordinate_clustering.CoordinateEuclideanClusterer.Cluster
noise_cluster() sensai.geoanalytics.geopandas.coordinate_clustering.CoordinateEuclideanClusterer.Cluster
clusters(condition: Optional[Callable[[sensai.geoanalytics.geopandas.coordinate_clustering.CoordinateEuclideanClusterer.Cluster], bool]] = None) Iterable[sensai.geoanalytics.geopandas.coordinate_clustering.CoordinateEuclideanClusterer.Cluster]
Parameters

condition – if provided, only clusters fulfilling the condition will be included

Returns

generator of clusters

class SkLearnCoordinateClustering(clusterer: sensai.clustering.sklearn_clustering.SkLearnClustererProtocol, noise_label=- 1, min_cluster_size: Optional[int] = None, max_cluster_size: Optional[int] = None)[source]

Bases: sensai.geoanalytics.geopandas.coordinate_clustering.CoordinateEuclideanClusterer

Wrapper around a sklearn clusterer. This class adds additional features like relabelling and convenient methods for handling geospatial data

Parameters
  • clusterer – a clusterer object compatible the sklearn API

  • noise_label – label that is associated with the noise cluster or None

  • min_cluster_size – if not None, clusters below this size will be labeled as noise

  • max_cluster_size – if not None, clusters above this size will be labeled as noise

__init__(clusterer: sensai.clustering.sklearn_clustering.SkLearnClustererProtocol, noise_label=- 1, min_cluster_size: Optional[int] = None, max_cluster_size: Optional[int] = None)