Skip to content

Commit

Permalink
[ML] Fix callout message for total feature importance (#80881)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
qn895 and kibanamachine committed Oct 19, 2020
1 parent 1e242b5 commit 1a1e905
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,19 @@ export const ExplorationPageWrapper: FC<Props> = ({
<ExpandableSectionAnalytics jobId={jobConfig.id} />
)}

{isLoadingJobConfig === true && totalFeatureImportance === undefined && <LoadingPanel />}
{isLoadingJobConfig === false && totalFeatureImportance !== undefined && (
<>
<FeatureImportanceSummaryPanel totalFeatureImportance={totalFeatureImportance} />
</>
)}
{isLoadingJobConfig === true &&
jobConfig !== undefined &&
totalFeatureImportance === undefined && <LoadingPanel />}
{isLoadingJobConfig === false &&
jobConfig !== undefined &&
totalFeatureImportance !== undefined && (
<>
<FeatureImportanceSummaryPanel
totalFeatureImportance={totalFeatureImportance}
jobConfig={jobConfig}
/>
</>
)}

{isLoadingJobConfig === true && jobConfig === undefined && <LoadingPanel />}
{isLoadingJobConfig === false && jobConfig !== undefined && isInitialized === true && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,6 +72,7 @@ const theme: PartialTheme = {

export interface FeatureImportanceSummaryPanelProps {
totalFeatureImportance: TotalFeatureImportance[];
jobConfig: DataFrameAnalyticsConfig;
}

const tooltipContent = i18n.translate(
Expand All @@ -88,6 +92,7 @@ const calculateTotalMeanImportance = (featureClass: ClassificationTotalFeatureIm

export const FeatureImportanceSummaryPanel: FC<FeatureImportanceSummaryPanelProps> = ({
totalFeatureImportance,
jobConfig,
}) => {
const {
services: { docLinks },
Expand Down Expand Up @@ -189,13 +194,52 @@ export const FeatureImportanceSummaryPanel: FC<FeatureImportanceSummaryPanelProp
const tickFormatter = useCallback((d) => 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 (
<EuiCallOut
size="s"
title={
<FormattedMessage
id="xpack.ml.dataframe.analytics.exploration.totalFeatureImportanceNotCalculatedCalloutMessage"
defaultMessage="Feature importance was not calculated because num_top_feature_importance values is set to 0."
/>
}
/>
);
} else {
// or is it because the data is uniform
return (
<EuiCallOut
size="s"
title={
<FormattedMessage
id="xpack.ml.dataframe.analytics.exploration.noTotalFeatureImportanceCalloutMessage"
defaultMessage="Total feature importance data is not available; the data set is uniform and the features have no significant impact on the prediction."
/>
}
/>
);
}
}
}
return undefined;
}, [totalFeatureImportance, jobConfig]);
return (
<>
<ExpandableSection
isExpanded={hasTotalFeatureImportance}
isExpanded={noDataCallOut === undefined}
dataTestId="FeatureImportanceSummary"
title={
<FormattedMessage
Expand Down Expand Up @@ -224,16 +268,8 @@ export const FeatureImportanceSummaryPanel: FC<FeatureImportanceSummaryPanelProp
},
]}
content={
!hasTotalFeatureImportance ? (
<EuiCallOut
size="s"
title={
<FormattedMessage
id="xpack.ml.dataframe.analytics.exploration.noTotalFeatureImportanceCalloutMessage"
defaultMessage="Total feature importance data is not available; the data set is uniform and the features have no significant impact on the prediction."
/>
}
/>
noDataCallOut ? (
noDataCallOut
) : (
<Chart
size={{
Expand Down

0 comments on commit 1a1e905

Please sign in to comment.