pypsa.clustering.ClusteringAccessor.busmap_by_hac#
- ClusteringAccessor.busmap_by_hac(n_clusters: int, buses_i: pd.Index | None = None, branch_components: Collection[str] | None = None, feature: pd.DataFrame | None = None, affinity: str | Callable = 'euclidean', linkage: str = 'ward', **kwargs: Any) pd.Series #
Create a busmap according to Hierarchical Agglomerative Clustering.
- Parameters:
n (pypsa.Network)
n_clusters (int) – Final number of clusters desired.
buses_i (None | pandas.Index, default=None) – Subset of buses to cluster. If None, all buses are considered.
branch_components (List, default=None) – Subset of all branch_components in the network. If None, all branch_components are considered.
feature (None | pandas.DataFrame, default=None) – Feature to be considered for the clustering. The DataFrame must be indexed with buses_i. If None, all buses have the same similarity.
affinity (str or Callable, default=’euclidean’) – Metric used to compute the linkage. Can be “euclidean”, “l1”, “l2”, “manhattan”, “cosine”, or “precomputed”. If linkage is “ward”, only “euclidean” is accepted. If “precomputed”, a distance matrix (instead of a similarity matrix) is needed as input for the fit method.
linkage (‘ward’, ‘complete’, ‘average’ or ‘single’, default=’ward’) – Which linkage criterion to use. The linkage criterion determines which distance to use between sets of observation. The algorithm will merge the pairs of cluster that minimize this criterion. - ‘ward’ minimizes the variance of the clusters being merged. - ‘average’ uses the average of the distances of each observation of the two sets. - ‘complete’ or ‘maximum’ linkage uses the maximum distances between all observations of the two sets. - ‘single’ uses the minimum of the distances between all observations of the two sets.
kwargs – Any remaining arguments to be passed to Hierarchical Clustering (e.g. memory, connectivity).
- Returns:
busmap – Mapping of n.buses to clusters (indexed by non-negative integers).
- Return type:
pandas.Series