← Train a Classifier
Your token

Train a Classifier API

Reading the CSV, training and checking the four kinds of model, the mistakes table, the column importance, the rules and every export run free in the browser and need no API. The API is for the one metered step: send a summary of what was measured (class sizes, scores, the commonest mix-ups, how much each column matters and the cautions found), get back a short explanation in plain words.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

This app has one task. Always send "task": "explain_model".

taskWhat it doesReply
explain_modelSays how good the classifier is against always guessing, which columns it relies on (only columns whose shuffling lowers accuracy), why the commonest mix-ups happen, one piece of advice per caution, and up to three next steps. Never repeats your numbers and never claims a column causes the outcome.One JSON object

Input fields

FieldTypeMeaning
taskstring"explain_model"
factsstringJSON text: target; classes (name, rows, share_pct); rows_labelled, rows_checked, rows_unlabelled, folds; chosen (model, setting); scores (accuracy_pct, macro_f1, balanced_accuracy_pct, roc_auc for two classes); baseline (always_guess, accuracy_pct); models; per_class (class, precision_pct, recall_pct, rows); mix_ups (actual, predicted, rows, at most 5); columns (column, kind, accuracy_drop_pts, most important first, at most 15); columns_total; flags (id, detail).

Flag ids: near_baseline, imbalance, rare_class, small_data, weak_class, possible_leak, dropped_columns, no_signal.

The reply

The job's output is one JSON object: {"task": "explain_model", "summary", "drivers": [{"column", "note"}], "mix_ups": [{"actual", "predicted", "note"}], "cautions": [{"flag", "advice"}], "next_steps": [...]}. summary is at most 45 words; each note and step at most 20, each advice at most 25; there are no digits in any text. The page keeps a driver only when its column was sent, a mix-up only when that pair was sent, and a caution only when its flag was sent, and it checks that every flag got advice. If the balance ran low, truncated is true and the object may stop early; the page keeps the fields that arrived complete.

Worked example

Input (input.json), for the page's Machine status example:

{
  "task": "explain_model",
  "facts": "{\"target\":\"status\",\"classes\":[{\"name\":\"ok\",\"rows\":354,\"share_pct\":73.8},{\"name\":\"warning\",\"rows\":105,\"share_pct\":21.9},{\"name\":\"fault\",\"rows\":21,\"share_pct\":4.4}],\"rows_labelled\":480,\"rows_checked\":480,\"rows_unlabelled\":0,\"folds\":5,\"chosen\":{\"model\":\"Logistic regression\",\"setting\":\"regularisation C = 1\"},\"scores\":{\"accuracy_pct\":89.2,\"macro_f1\":0.789,\"balanced_accuracy_pct\":74.8},\"baseline\":{\"always_guess\":\"ok\",\"accuracy_pct\":73.8},\"models\":[{\"model\":\"Logistic regression\",\"accuracy_pct\":89.2,\"macro_f1\":0.789},{\"model\":\"Decision tree\",\"accuracy_pct\":83.5,\"macro_f1\":0.738},{\"model\":\"Nearest neighbours\",\"accuracy_pct\":86.7,\"macro_f1\":0.708},{\"model\":\"Naive Bayes\",\"accuracy_pct\":86.5,\"macro_f1\":0.713}],\"per_class\":[{\"class\":\"ok\",\"precision_pct\":94,\"recall_pct\":95,\"rows\":354},{\"class\":\"warning\",\"precision_pct\":74,\"recall_pct\":77,\"rows\":105},{\"class\":\"fault\",\"precision_pct\":92,\"recall_pct\":52,\"rows\":21}],\"mix_ups\":[{\"actual\":\"warning\",\"predicted\":\"ok\",\"rows\":23},{\"actual\":\"ok\",\"predicted\":\"warning\",\"rows\":18},{\"actual\":\"fault\",\"predicted\":\"warning\",\"rows\":10},{\"actual\":\"warning\",\"predicted\":\"fault\",\"rows\":1}],\"columns\":[{\"column\":\"temperature_c\",\"kind\":\"number\",\"accuracy_drop_pts\":18.8},{\"column\":\"vibration_mm_s\",\"kind\":\"number\",\"accuracy_drop_pts\":15.4},{\"column\":\"hours_since_service\",\"kind\":\"number\",\"accuracy_drop_pts\":0.4},{\"column\":\"rpm\",\"kind\":\"number\",\"accuracy_drop_pts\":0}],\"columns_total\":4,\"flags\":[{\"id\":\"imbalance\",\"detail\":\"“fault” is only 4.4% of the labelled rows, so accuracy can look good while it is missed.\"},{\"id\":\"dropped_columns\",\"detail\":\"Left out as free text (too many different values to learn from): “machine”.\"}]}"
}

Reply:

{
  "task": "explain_model",
  "summary": "The model is good at telling healthy machines from those needing attention, clearly better than always guessing ok. It relies mainly on temperature_c and vibration_mm_s, but it misses about half of the faults.",
  "drivers": [
    {
      "column": "temperature_c",
      "note": "Machines running hotter than usual tend to be a sign of warning or fault rather than ok."
    },
    {
      "column": "vibration_mm_s",
      "note": "Stronger vibration goes with machines that are not ok, helping tell them apart from healthy ones."
    },
    {
      "column": "hours_since_service",
      "note": "Time since the last service adds only a little help in predicting status."
    }
  ],
  "mix_ups": [
    {
      "actual": "warning",
      "predicted": "ok",
      "note": "Some machines in warning state look normal on temperature and vibration, so the model treats them as healthy."
    },
    {
      "actual": "ok",
      "predicted": "warning",
      "note": "Some healthy machines run warm or shake a bit, which looks like an early warning."
    }
  ],
  "cautions": [
    {
      "flag": "imbalance",
      "advice": "Faults are rare, so judge the model by how many faults it finds, not by overall accuracy alone."
    },
    {
      "flag": "dropped_columns",
      "advice": "The machine column was left out as free text. If it holds a useful group such as model or site, add a simpler version."
    }
  ],
  "next_steps": [
    "Add a column such as load, age or recent repairs, if you have one.",
    "Treat predicted faults as machines to inspect, not as final verdicts.",
    "Collect more fault examples so the model can learn them better."
  ]
}

On the page, each statement is shown next to the number it refers to.

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://train-classifier.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs your personal token: sign in on the token page and copy it.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"train-classifier"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "explain_model", "facts": "{...}"}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="train-classifier:explain_model:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.json   # one JSON object: summary, drivers, mix_ups, cautions, next_steps
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: train-classifier:explain_model:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json