zen_mapper.adapters module¶
Adapters for converting between zen-mapper types and 3rd party types
- sk_learn(base_clusterer, precomputed=None)¶
Wrap a scikit-learn clusterer for use with zen-mapper.
This function acts as an adapter, allowing scikit-learn’s clustering algorithms to be integrated into the zen-mapper pipeline. Note: any datapoints which are considered noise by the base clusterer are ignored.
- Parameters:
base_clusterer (
TypeVar(C)) – An instance of a scikit-learn compatible clustering algorithm. This object should have a fit_predict method and a labels_ attribute after fitting, which is standard for scikit-learn clusterers.precomputed (
bool|None, default:None) – True if the scikit-learn algorithm is expecting a distance matrix. If not specified the adapter attempts to detect this from base_clusterer.
- Returns:
Clusterer[ndarray,TypeVar(C)] – An object conforming to the zen-mapper Clusterer protocol, which wraps the provided clusterer. This allows zen-mapper to use the scikit-learn clusterer’s fit_predict methods within its pipeline. A copy of the fitted base clusterer is also returned as metadata allowing for inspection of the fitted model (e.g., centroids, parameters, dendrograms) after the mapper pipeline.- Return type:
- to_networkx(komplex)¶
Convert a zen-mapper komplex to a networkx graph
This function takes a Komplex object, which represents a simplicial complex, and converts it into a networkx.Graph object. The vertices of the Komplex become the nodes in the networkx graph, and the 1-simplices (edges) of the Komplex become the edges in the networkx graph.
- Parameters:
komplex (
Komplex) – The Komplex object to convert. This object is expected to have a vertices attribute and support indexing for its simplices (e.g., komplex[1] for 1-simplices).- Returns:
Graph– A graph representing the 0 and 1-dimensional structure of the input Komplex.- Raises:
ImportError – If the networkx library is not installed.
- Return type: