Estimator API

class core_sg.CoreSGClusterer(k_max, metric='euclidean', p=2, algorithm='core-sg', no_noise=True, noise_label_strategy='mst_label_propagation', random_state=None, approx_knn_kwargs=None, verbose=0, progress_callback=None, cluster_selection_method='eom', allow_single_cluster=False, match_reference_implementation=False, cluster_selection_epsilon=0.0, cluster_selection_persistence=0.0, max_cluster_size=0, cluster_selection_epsilon_max=inf)

Scikit-learn-style estimator wrapper around the native CoreSG API.

CoreSGClusterer keeps k_max as a constructor parameter so it can be introspected, cloned, and tuned by scikit-learn utilities. The native CoreSG object is built only once, on the first fit(…) call. Later fit(…) calls reuse that object and extract a new hierarchy for the requested k.

Parameters:
  • k_max (int)

  • metric (str)

  • p (int)

  • algorithm (str)

  • no_noise (bool)

  • noise_label_strategy (str)

  • random_state (int | np.random.RandomState | None)

  • approx_knn_kwargs (dict[str, Any] | None)

  • verbose (int)

  • progress_callback (ProgressCallback | None)

  • cluster_selection_method (str)

  • allow_single_cluster (bool)

  • match_reference_implementation (bool)

  • cluster_selection_epsilon (float)

  • cluster_selection_persistence (float)

  • max_cluster_size (int)

  • cluster_selection_epsilon_max (float)

fit(X, y=None, *, k=None)

Build Core-SG once and expose clustering artifacts for k.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Dense feature matrix used only when the internal native CoreSG object does not exist yet. After the first fit, subsequent calls reuse core_sg_ and do not rebuild the support graph.

  • y (ignored, default=None) – Accepted for scikit-learn compatibility.

  • k (int or None, keyword-only, default=None) – Neighborhood size to extract. If None, k_max is used.

Returns:

The fitted estimator itself.

Return type:

CoreSGClusterer

fit_predict(X, y=None, *, k=None)

Fit the estimator and return the labels for the fitted k.

Return type:

ndarray

Parameters:
  • X (Any)

  • y (Any)

  • k (int | None)

get_fitted_core_sg()

Return the fitted native CoreSG object.

Return type:

CoreSG

Required Behavior Notes

CoreSGClusterer does not implement predict(...). Core-SG is currently fit/extract oriented and does not define assignment semantics for unseen samples.

The first fit(...) call creates core_sg_ and builds reusable support for k_max. Later calls reuse core_sg_ and extract the hierarchy for the requested k. The decision is based on whether core_sg_ exists, not on whether k == k_max.

The estimator is compatible with get_params(), set_params(), and sklearn.base.clone(...) through scikit-learn’s BaseEstimator.