Clustering module#
- class libadalina_analytics.clustering.ClusteringDistance(*, name: str, weight: float | None = 1.0, function: str | None = None)[source]#
- function: str | None#
- Distance function to use. Must be one of the following:
euclidean
manhattan
chebyshev
haversine
hamming
canberra
braycurtis
jaccard
matching
dice
kulsinski
rogerstanimoto
russellrao
sokalmichener
sokalsneath
- If None, the default function depends on the type of the values in the column:
geometric values default to scipy distance_matrix
float and int values default to euclidean
string values default to hamming
boolean values default to jaccard
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- libadalina_analytics.clustering.clustering_algorithm(data: DataFrame | GeoDataFrame | DataFrame, epsg: EPSGFormats, geometry_column: str = 'geometry', geometry_format: GeometryFormats = GeometryFormats.WKT, weight_column: str | None = None, k_min: int | None = None, k_max: int | None = None, f_min: float | None = None, distances: list[ClusteringDistance] | None = None, timelimit: int = 60) AdalinaZoningSolution | None[source]#
Create clusters of similar areas minimizing their internal distance.
Distances are given as a list of ClusteringDistance objects, each containing: - name: the name of the column in the input data - weight: the weight of the distance in the overall distance calculation - function: the distance function to use
- Parameters:
data (pandas.DataFrame or geopandas.GeoDataFrame or pyspark.sql.DataFrame) – The input data containing the geometries and attributes to be clustered.
epsg (EPSGFormats) – The EPSG format of the input geometries.
geometry_column (str) – The name of the column containing the geometries. Default is ‘geometry’.
geometry_format (GeometryFormats) – The format of the geometries in the geometry column. Default is GeometryFormats.WKT.
weight_column (str | None) – The name of the column to use as the optional weight of an area. Default is None.
k_min (int | None) – The minimum number of clusters to create. If None, defaults to 1.
k_max (int | None) – The maximum number of clusters to create. Default is None.
f_min (float | None) – The minimum total weight of a cluster. If None, defaults to 1.
distances (list[ClusteringDistance] | None) – List of distances to use for clustering. If None, no only distance between area centroids will be used. Each distance is represented as a ClusteringDistance object that includes the name of the column, the weight of the distance, and the distance function to use.
timelimit (int) – The maximum time (in seconds) to run the algorithm. Default is 60 seconds.
- Return type:
AdalinaZoningSolution