From 1a1e905ed5d42a1d7f9b7bea37f2916129379f87 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen <43350163+qn895@users.noreply.github.com> Date: Mon, 19 Oct 2020 10:08:24 -0500 Subject: [PATCH] [ML] Fix callout message for total feature importance (#80881) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../exploration_page_wrapper.tsx | 19 ++++-- .../feature_importance_summary.tsx | 64 +++++++++++++++---- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_page_wrapper/exploration_page_wrapper.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_page_wrapper/exploration_page_wrapper.tsx index b03777fef6bd4..de4d1a97f248f 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_page_wrapper/exploration_page_wrapper.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/exploration_page_wrapper/exploration_page_wrapper.tsx @@ -144,12 +144,19 @@ export const ExplorationPageWrapper: FC = ({ )} - {isLoadingJobConfig === true && totalFeatureImportance === undefined && } - {isLoadingJobConfig === false && totalFeatureImportance !== undefined && ( - <> - - - )} + {isLoadingJobConfig === true && + jobConfig !== undefined && + totalFeatureImportance === undefined && } + {isLoadingJobConfig === false && + jobConfig !== undefined && + totalFeatureImportance !== undefined && ( + <> + + + )} {isLoadingJobConfig === true && jobConfig === undefined && } {isLoadingJobConfig === false && jobConfig !== undefined && isInitialized === true && ( diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/total_feature_importance_summary/feature_importance_summary.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/total_feature_importance_summary/feature_importance_summary.tsx index b754e2eeba349..4da96c595bdf7 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/total_feature_importance_summary/feature_importance_summary.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/total_feature_importance_summary/feature_importance_summary.tsx @@ -32,6 +32,9 @@ import { import { useMlKibana } from '../../../../../contexts/kibana'; import { ExpandableSection } from '../expandable_section'; +import { DataFrameAnalyticsConfig } from '../../../../../../../common/types/data_frame_analytics'; +import { getAnalysisType } from '../../../../common'; +import { isClassificationAnalysis, isRegressionAnalysis } from '../../../../common/analytics'; const { euiColorMediumShade } = euiVars; const axisColor = euiColorMediumShade; @@ -69,6 +72,7 @@ const theme: PartialTheme = { export interface FeatureImportanceSummaryPanelProps { totalFeatureImportance: TotalFeatureImportance[]; + jobConfig: DataFrameAnalyticsConfig; } const tooltipContent = i18n.translate( @@ -88,6 +92,7 @@ const calculateTotalMeanImportance = (featureClass: ClassificationTotalFeatureIm export const FeatureImportanceSummaryPanel: FC = ({ totalFeatureImportance, + jobConfig, }) => { const { services: { docLinks }, @@ -189,13 +194,52 @@ export const FeatureImportanceSummaryPanel: FC Number(d.toPrecision(3)).toString(), []); // do not expand by default if no feature importance data - const hasTotalFeatureImportance = useMemo(() => totalFeatureImportance.length > 1, [ - totalFeatureImportance, - ]); + const noDataCallOut = useMemo(() => { + // if no total feature importance data + if (totalFeatureImportance.length === 0) { + // check if it's because num_top_feature_importance_values is set to 0 + if ( + (jobConfig?.analysis && isRegressionAnalysis(jobConfig?.analysis)) || + isClassificationAnalysis(jobConfig?.analysis) + ) { + const analysisType = getAnalysisType(jobConfig.analysis); + if ( + analysisType !== 'unknown' && + jobConfig.analysis[analysisType].num_top_feature_importance_values === 0 + ) { + return ( + + } + /> + ); + } else { + // or is it because the data is uniform + return ( + + } + /> + ); + } + } + } + return undefined; + }, [totalFeatureImportance, jobConfig]); return ( <> - } - /> + noDataCallOut ? ( + noDataCallOut ) : (