Skip to content

Multiclass classification

For a multiclass model, mli fans out one-vs-rest: it builds a full profile (archetypes and rules) per class, plus a comparative view. You don't pass a target_mask; mli detects the classes and profiles each one.

In short

  • Fit with more than two classes and fit_profiler profiles every class against the rest.
  • result.class_keys lists the classes; result[key] (or result.profile_for(key)) is one class's ClassProfile.
  • Each class has its own archetypes and rules; the all-class rule engine is binary only.
  • Trust and the model card roll up the per-class results.

In practice the model comes from ml4

This page uses a plain classifier to keep the focus on the multiclass surface. For a model built by ml4, see Explain an ml4 model.

1. Train & profile

import pandas as pd
from lightgbm import LGBMClassifier
from parleml_mli import ProfilingConfig, RulesConfig, fit_profiler

df = pd.read_parquet("tickets.parquet")
y = df.pop("priority")                        # {low, medium, high, urgent}

clf = LGBMClassifier(n_estimators=300).fit(df, y)

result = fit_profiler(
    model=clf,
    X=df,
    y=y,                                      # no target_mask — fan-out is automatic
    config=ProfilingConfig(rules=RulesConfig()),
)

assert result.is_multiclass
print(result.task_type)                       # TaskType.MULTICLASS
print(result.class_keys)                      # one entry per class

2. Read each class's archetypes & rules

for key in result.class_keys:
    profile = result.profile_for(key)         # a ClassProfile (also: result[key])
    print(f"\n=== class {profile.class_label} ===")
    print(profile.summary_df[["cluster_id", "n_target_cases", "lift"]])
    if profile.has_rules:
        for engine, ruleset in profile.rules.items():
            for rule in ruleset.rules[:5]:
                print(rule.text)

3. Trust & model card

Trust grading and model cards work the same as binary — they roll up the per-class results:

from parleml_mli import compute_trust_summary
from parleml_mli.autodoc import build_model_card

trust = compute_trust_summary(result)
card = build_model_card(result, trust_summary=trust)

See the Profiling guide for the artifact surface and Rules for the one-vs-rest rule contract.

Next