Charts

Machine learning

Evaluate classifiers and models: confusion matrix, ROC, calibration, training curves and embeddings.

Each chart below is drawn live from the data of its example. All kinds: Chart types.

Confusion Matrix

Actual against predicted classes of a classifier: which classes it confuses with which.

Data. Two columns with the actual and the predicted class (text or numbers), one row per case.

Example

TypeScript
// Classifier.csv, 400 rows:
//   actual,predicted
//   Wear,Misalign
//   Misalign,Misalign
//   Normal,Normal
//   …
await engine.datasets.addText(await file.text(), 'Classifier.csv')

const chart = engine.charts.add('confusion', {
  title: 'Fault classifier',
  settings: { cfActualCol: 'actual', cfPredictedCol: 'predicted', cfNormalize: true },
})
engine.charts.mount(chart, document.getElementById('chart')!)

Settings

NameTypeDescription
cfActualColstring
Default: ''
The true class.
cfPredictedColstring
Default: ''
The predicted class.
cfNormalizeboolean
Default: false
Show each row as fractions of its actual class.

ROC Curve

How well a score separates two classes at every threshold: the ROC curve (with its AUC) or precision against recall.

Data. A score column and a 0/1 label column.

Example

TypeScript
// score, label: arrays of numbers, all the same length
engine.datasets.addColumns({
  name: 'Detector',
  columns: { score, label },
})

const chart = engine.charts.add('roc', {
  title: 'Anomaly detector',
  settings: { rocScoreCol: 'score', rocLabelCol: 'label', rocMode: 'roc', rocColor: '#f472b6' },
})
engine.charts.mount(chart, document.getElementById('chart')!)

Settings

NameTypeDescription
rocScoreColstring
Default: ''
Classifier score (higher = more likely positive).
rocLabelColstring
Default: ''
True label, 0 or 1.
rocMode'roc' | 'pr'
Default: 'roc'
ROC curve or precision-recall.
rocColorstring
Default: #f472b6
Colour of the marks (hex).

Calibration Curve

Whether predicted probabilities mean what they say: predicted probability against the observed frequency per bin. On the diagonal is well calibrated.

Data. A probability column (0 to 1) and a 0/1 label column.

Example

TypeScript
// score, label: arrays of numbers, all the same length
engine.datasets.addColumns({
  name: 'Detector',
  columns: { score, label },
})

const chart = engine.charts.add('calibration', {
  title: 'Detector calibration',
  settings: { cbScoreCol: 'score', cbLabelCol: 'label', cbBins: 10, cbColor: '#38bdf8' },
})
engine.charts.mount(chart, document.getElementById('chart')!)

Settings

NameTypeDescription
cbScoreColstring
Default: ''
Predicted probability.
cbLabelColstring
Default: ''
True label, 0 or 1.
cbBinsnumber
Default: 10
Number of probability bins.
cbColorstring
Default: #38bdf8
Colour of the marks (hex).

Loss Curves

Training curves on two Y axes: losses on the left, accuracy or learning rate on the right, against epochs or steps.

Data. An X column (epoch, step) and the columns of each axis.

Example

TypeScript
// epoch, train_loss, val_loss, accuracy: arrays of numbers, all the same length
engine.datasets.addColumns({
  name: 'Training',
  columns: { epoch, train_loss, val_loss, accuracy },
})

const chart = engine.charts.add('losscurve', {
  title: 'Training run',
  settings: {
    lcXCol: 'epoch',
    lcLeftCols: [{ column: 'train_loss', color: '#38bdf8' }, { column: 'val_loss', color: '#f5a524' }],
    lcRightCols: [{ column: 'accuracy', color: '#22c55e' }],
  },
})
engine.charts.mount(chart, document.getElementById('chart')!)

Settings

NameTypeDescription
lcXColstring
Default: ''
Column along X.
lcLeftCols{ column, color }[]
Default: []
Curves on the left axis.
lcRightCols{ column, color }[]
Default: []
Curves on the right axis.
lcAlarmAlarmLine | null
Default: null
Horizontal line on the left axis.

Embedding

A 2-D embedding (t-SNE, UMAP, PCA output) coloured by class or by value: clusters of similar cycles, states or parts.

Data. X and Y columns of the embedding; optionally a colour and a label column.

Example

TypeScript
// x, y, state: arrays of numbers, all the same length
engine.datasets.addColumns({
  name: 'States',
  columns: { x, y, state },
})

const chart = engine.charts.add('embedding', {
  title: 'Operating states',
  settings: { emXCol: 'x', emYCol: 'y', emColorCol: 'state', emColorMode: 'categorical', emPointSize: 3 },
})
engine.charts.mount(chart, document.getElementById('chart')!)

Settings

NameTypeDescription
emXColstring
Default: ''
First embedding coordinate.
emYColstring
Default: ''
Second embedding coordinate.
emColorColstring
Default: ''
Colour points by this column; '' uses emColor.
emColorMode'numeric' | 'categorical'
Default: 'categorical'
A colour map or one colour per value.
emLabelColstring
Default: ''
Label shown for each point; '' for none.
emPointSizenumber
Default: 3
Point radius in px.
emColorstring
Default: #a78bfa
Colour of the marks (hex).