Skip to content

Commit

Permalink
[ML] Add callout for legacy feature influence data.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Oct 20, 2020
1 parent de33e97 commit 0785fb7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
4 changes: 3 additions & 1 deletion x-pack/plugins/ml/common/types/data_frame_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export type DataFrameAnalyticsId = string;
export interface OutlierAnalysis {
[key: string]: {};

outlier_detection: {};
outlier_detection: {
compute_feature_influence?: boolean;
};
}

interface Regression {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/ml/common/util/analytics_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ import {
import { ANALYSIS_CONFIG_TYPE } from '../../common/constants/data_frame_analytics';

export const isOutlierAnalysis = (arg: any): arg is OutlierAnalysis => {
if (typeof arg !== 'object' || arg === null) return false;
const keys = Object.keys(arg);
return keys.length === 1 && keys[0] === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION;
};

export const isRegressionAnalysis = (arg: any): arg is RegressionAnalysis => {
if (typeof arg !== 'object' || arg === null) return false;
const keys = Object.keys(arg);
return keys.length === 1 && keys[0] === ANALYSIS_CONFIG_TYPE.REGRESSION;
};

export const isClassificationAnalysis = (arg: any): arg is ClassificationAnalysis => {
if (typeof arg !== 'object' || arg === null) return false;
const keys = Object.keys(arg);
return keys.length === 1 && keys[0] === ANALYSIS_CONFIG_TYPE.CLASSIFICATION;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import React, { useState, FC } from 'react';

import { EuiSpacer, EuiText } from '@elastic/eui';
import { EuiCallOut, EuiSpacer, EuiText } from '@elastic/eui';

import { i18n } from '@kbn/i18n';

import {
useColorRange,
Expand All @@ -15,7 +17,8 @@ import {
} from '../../../../../components/color_range_legend';
import { SavedSearchQuery } from '../../../../../contexts/ml';

import { defaultSearchQuery, useResultsViewConfig } from '../../../../common';
import { defaultSearchQuery, isOutlierAnalysis, useResultsViewConfig } from '../../../../common';
import { FEATURE_INFLUENCE } from '../../../../common/constants';

import { ExpandableSectionAnalytics, ExpandableSectionResults } from '../expandable_section';
import { ExplorationQueryBar } from '../exploration_query_bar';
Expand All @@ -39,6 +42,24 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =
const featureCount = getFeatureCount(jobConfig?.dest?.results_field || '', tableItems);
const colorRange = useColorRange(COLOR_RANGE.BLUE, COLOR_RANGE_SCALE.INFLUENCER, featureCount);

// Show the color range only if feature influence is enabled and there's more than 0 features.
const showColorRange =
featureCount > 0 &&
isOutlierAnalysis(jobConfig?.analysis) &&
jobConfig?.analysis.outlier_detection.compute_feature_influence === true;

const resultsField = jobConfig?.dest.results_field ?? '';

// Identify if the results index has a legacy feature influence format.
// If feature influence was enabled for the legacy job we'll show a callout
// with some additional information for a workaround.
const showLegacyFeatureInfluenceFormatCallout =
isOutlierAnalysis(jobConfig?.analysis) &&
jobConfig?.analysis.outlier_detection.compute_feature_influence === true &&
columnsWithCharts.findIndex(
(d) => d.id === `${resultsField}.${FEATURE_INFLUENCE}.feature_name`
) === -1;

return (
<>
{typeof jobConfig?.description !== 'undefined' && (
Expand All @@ -55,8 +76,26 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =
</>
)}
{typeof jobConfig?.id === 'string' && <ExpandableSectionAnalytics jobId={jobConfig?.id} />}
{showLegacyFeatureInfluenceFormatCallout && (
<>
<EuiCallOut
size="s"
title={i18n.translate(
'xpack.ml.dataframe.analytics.outlierExploration.legacyFeatureInfluenceFormatCalloutTitle',
{
defaultMessage:
'Color coded table cells based on feature influence are not available, because this results index uses an unsupported legacy format. Please clone an rerun the job to enable support for color coding.',
}
)}
iconType="pin"
/>
<EuiSpacer size="m" />
</>
)}
<ExpandableSectionResults
colorRange={featureCount > 0 ? colorRange : undefined}
colorRange={
showColorRange && !showLegacyFeatureInfluenceFormatCallout ? colorRange : undefined
}
indexData={outlierData}
indexPattern={indexPattern}
jobConfig={jobConfig}
Expand Down

0 comments on commit 0785fb7

Please sign in to comment.