* Draw confusion matrix.
(model, xTest, yTest)
| 117 | * Draw confusion matrix. |
| 118 | */ |
| 119 | async 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. |
no test coverage detected