From 4e02adfbb4811c458d0e03d74ae93ba3576ac7b6 Mon Sep 17 00:00:00 2001 From: Ziyuan Lin Date: Tue, 6 Aug 2024 03:22:09 -0400 Subject: [PATCH] reorder metadata legend before results (#181) * sort legend by onehot array * add comment --- src/NeuralNetwork/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/NeuralNetwork/index.js b/src/NeuralNetwork/index.js index 6dc63416..4e041f0a 100644 --- a/src/NeuralNetwork/index.js +++ b/src/NeuralNetwork/index.js @@ -1102,6 +1102,13 @@ class DiyNeuralNetwork { if (meta !== null) { const label = Object.keys(meta.outputs)[0]; const vals = Object.entries(meta.outputs[label].legend); + // sort the legend array results by each item's one-hot encoding + vals.sort((a, b) => { + return ( + b[1].reduce((acc, curr) => acc * 2 + curr, 0) - + a[1].reduce((acc, curr) => acc * 2 + curr, 0) + ); + }); const formattedResults = unformattedResults.map((unformattedResult) => { return vals