MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / calculateAndDrawConfusionMatrix

Function calculateAndDrawConfusionMatrix

iris/index.js:119–135  ·  view source on GitHub ↗

* Draw confusion matrix.

(model, xTest, yTest)

Source from the content-addressed store, hash-verified

117 * Draw confusion matrix.
118 */
119async function calculateAndDrawConfusionMatrix(model, xTest, yTest) {
120 const [preds, labels] = tf.tidy(() => {
121 const preds = model.predict(xTest).argMax(-1);
122 const labels = yTest.argMax(-1);
123 return [preds, labels];
124 });
125
126 const confMatrixData = await tfvis.metrics.confusionMatrix(labels, preds);
127 const container = document.getElementById('confusion-matrix');
128 tfvis.render.confusionMatrix(
129 container,
130 {values: confMatrixData, labels: data.IRIS_CLASSES},
131 {shadeDiagonal: true},
132 );
133
134 tf.dispose([preds, labels]);
135}
136
137/**
138 * Run inference on some test Iris flower data.

Callers 2

trainModelFunction · 0.70
evaluateModelOnTestDataFunction · 0.70

Calls 1

predictMethod · 0.45

Tested by

no test coverage detected