pypsa.clustering.ClusteringAccessor.busmap_by_hac#
- ClusteringAccessor.busmap_by_hac(n_clusters, buses_i=None, branch_components=None, feature=None, affinity='euclidean', linkage='ward', **kwargs)#
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 network.buses to clusters (indexed by non-negative integers).
- Return type:
pandas.Series