From 96ccaef1be6614f3dce368ea228c63282fdf6327 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Thu, 29 Oct 2020 17:50:41 +0100 Subject: [PATCH] [ML] Fix classification feature importance object. --- .../application/components/data_grid/common.ts | 12 ++++++++---- .../exploration_results_table.tsx | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/ml/public/application/components/data_grid/common.ts b/x-pack/plugins/ml/public/application/components/data_grid/common.ts index c6dbe3f266608..cb5008d628b51 100644 --- a/x-pack/plugins/ml/public/application/components/data_grid/common.ts +++ b/x-pack/plugins/ml/public/application/components/data_grid/common.ts @@ -184,13 +184,17 @@ export const getFeatureImportance = ( // return object structure for classification job if (classNames !== undefined && classImportance !== undefined) { + const overallClassNames = classNames?.slice(0, classNames.length / featureNames.length); + return featureNames.map((fName, index) => { - const offset = featureNames.length * index; - const featureClassNames = classNames.slice(offset, offset + featureNames.length); - const featureClassImportance = classImportance.slice(offset, offset + featureNames.length); + const offset = overallClassNames.length * index; + const featureClassImportance = classImportance.slice( + offset, + offset + overallClassNames.length + ); return { feature_name: fName, - classes: featureClassNames.map((fClassName, fIndex) => { + classes: overallClassNames.map((fClassName, fIndex) => { return { class_name: fClassName, importance: featureClassImportance[fIndex] }; }), }; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_results_table/exploration_results_table.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_results_table/exploration_results_table.tsx index a6e95269b3633..10e2ad5b5eb53 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_results_table/exploration_results_table.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_results_table/exploration_results_table.tsx @@ -29,7 +29,7 @@ interface Props { } export const ExplorationResultsTable: FC = React.memo( - ({ indexPattern, jobConfig, jobStatus, needsDestIndexPattern, searchQuery }) => { + ({ indexPattern, jobConfig, needsDestIndexPattern, searchQuery }) => { const { services: { mlServices: { mlApiServices },