scicloj.metamorph.ml.classification

Classification models and evaluation metrics for metamorph.ml.

This namespace provides tools for classification tasks including:

  • Confusion matrix generation and analysis
  • Baseline classifier implementations
  • Classification evaluation utilities

Key features:

  • confusion-map: Creates confusion matrices from predictions and true labels
  • confusion-map->ds: Converts confusion matrices to tabular dataset format
  • :metamorph.ml/dummy-classifier: A baseline classifier for sanity checks

Dummy Classifier Strategies:

  • :majority-class (default): Always predicts the most frequent class
  • :fixed-class: Predicts a specified class
  • :random-class: Predicts randomly from the observed classes

Confusion Matrix Normalization:

  • :all (default): Row-wise normalization (recall perspective)
  • :none: Raw counts

See also: scicloj.metamorph.ml.viz/confusion-matrix

Categories

    Other vars: confusion-map confusion-map->ds

    confusion-map

    (confusion-map predicted-labels labels normalize)(confusion-map predicted-labels labels)

    Creates a confusion matrix in nested map form for classification evaluation.

    predicted-labels - Sequence of predicted class labels labels - Sequence of actual class labels normalize - Normalization mode (default: :all)

    • :all - Normalize by row (proportion of actual class)
    • :none - Raw counts

    Returns a nested sorted map where {actual-class {predicted-class value}}. When normalized, values represent proportions; otherwise, they are counts.

    Example: {:setosa {:setosa 0.95 :versicolor 0.05} :versicolor {:versicolor 1.0}}

    Use confusion-map->ds to convert to dataset format for display.

    See also: confusion-map->ds, scicloj.metamorph.ml.viz/confusion-matrix

    Examples

    Usage

    (let [pred [0 1 0 1 1]
          truth [0 0 1 1 1]]
      (confusion-map pred truth :none))
    ;;=> {0 {0 1, 1 1}, 1 {0 1, 1 2}}

    confusion-map->ds

    (confusion-map->ds conf-matrix-map)

    Converts a confusion matrix map to dataset representation for display.

    conf-matrix-map - Confusion matrix map from confusion-map

    Returns a dataset with actual classes as rows (:column-name) and predicted classes as columns. Cell values show counts or proportions depending on how the confusion map was generated.

    The dataset format is suitable for printing, analysis, or visualization.

    See also: confusion-map, scicloj.metamorph.ml.viz/confusion-matrix

    Examples

    Usage

    (let [pred [0 1 0 1 1 2]
          truth [2 0 1 1 1 2]
          conf-map (confusion-map pred truth :none)]
      (str (confusion-map->ds conf-map)))
    ;;=> _unnamed [3 4]:
    ;;=> 
    ;;=> | :column-name | 0 | 1 | 2 |
    ;;=> |-------------:|---|---|---|
    ;;=> |            0 | 0 | 1 | 0 |
    ;;=> |            1 | 1 | 2 | 0 |
    ;;=> |            2 | 1 | 0 | 1 |