geolatent.utils#

Utility sub-package for geolatent.

Submodules#

Functions#

validate_class_names(→ Optional[Dict])

Validate an optional class-name mapping.

validate_classification_labels(→ numpy.ndarray)

Assert that y is suitable for classification.

validate_embeddings(→ Tuple[numpy.ndarray, numpy.ndarray])

Validate an (embeddings, labels) pair for latent-space visualisation.

validate_feature_matrix(→ numpy.ndarray)

Validate and coerce a feature matrix.

validate_label_vector(→ numpy.ndarray)

Validate and coerce a label / target vector.

validate_sklearn_model(→ None)

Validate that model exposes a scikit-learn-compatible interface.

Package Contents#

geolatent.utils.validate_class_names(class_names: Dict | None, unique_classes: numpy.ndarray) Dict | None[source]#

Validate an optional class-name mapping.

Parameters:
  • class_names (dict or None) – Mapping from class label to display string.

  • unique_classes (np.ndarray) – Array of unique class labels detected in the data.

Returns:

class_names – The input unchanged if valid.

Return type:

dict or None

Raises:

TypeError – If class_names is not a dict.

geolatent.utils.validate_classification_labels(y: numpy.ndarray, *, name: str = 'y') numpy.ndarray[source]#

Assert that y is suitable for classification.

Parameters:
Returns:

y – The input unchanged.

Return type:

np.ndarray

Raises:

ValueError – If y contains only one unique class (degenerate problem).

geolatent.utils.validate_embeddings(embeddings: Any, labels: Any) Tuple[numpy.ndarray, numpy.ndarray][source]#

Validate an (embeddings, labels) pair for latent-space visualisation.

Parameters:
  • embeddings (array-like of shape (n_samples, n_dims)) – High-dimensional embedding vectors.

  • labels (array-like of shape (n_samples,)) – Integer or string class labels.

Returns:

  • embeddings (np.ndarray of shape (n_samples, n_dims))

  • labels (np.ndarray of shape (n_samples,))

geolatent.utils.validate_feature_matrix(X: Any, *, min_samples: int = 4, min_features: int = 2, name: str = 'X') numpy.ndarray[source]#

Validate and coerce a feature matrix.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Input feature matrix.

  • min_samples (int) – Minimum acceptable number of samples.

  • min_features (int) – Minimum acceptable number of features.

  • name (str) – Variable name used in error messages.

Returns:

X

Return type:

np.ndarray of shape (n_samples, n_features), dtype float64

Raises:
  • TypeError – If X cannot be converted to a NumPy array.

  • ValueError – If X is not 2-D, contains fewer than min_samples rows, fewer than min_features columns, or contains non-finite values.

geolatent.utils.validate_label_vector(y: Any, *, n_samples: int, name: str = 'y') numpy.ndarray[source]#

Validate and coerce a label / target vector.

Parameters:
  • y (array-like of shape (n_samples,)) – Class labels or regression targets.

  • n_samples (int) – Expected length (must match the corresponding feature matrix).

  • name (str) – Variable name used in error messages.

Returns:

y

Return type:

np.ndarray of shape (n_samples,)

Raises:
  • TypeError – If y cannot be converted to a NumPy array.

  • ValueError – If y is not 1-D or its length does not match n_samples.

geolatent.utils.validate_sklearn_model(model: Any, *, require_predict_proba: bool = False) None[source]#

Validate that model exposes a scikit-learn-compatible interface.

Parameters:
  • model (Any) – The model to validate.

  • require_predict_proba (bool) – If True, also assert that predict_proba is present.

Raises:
  • TypeError – If model does not expose predict.

  • AttributeError – If require_predict_proba is True and predict_proba is absent.