Skip to content

Commit

Permalink
[ML] DFAnalytics results: ensure ml result fields are shown in data g…
Browse files Browse the repository at this point in the history
…rid (#68305)

* wip: ensure top classes and influencer result col show up correctly

* ensure ml subFields columns are populated
  • Loading branch information
alvarezmelissa87 authored Jun 8, 2020
1 parent bc39186 commit e2f11e9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
FEATURE_IMPORTANCE,
FEATURE_INFLUENCE,
OUTLIER_SCORE,
TOP_CLASSES,
} from '../../data_frame_analytics/common/constants';
import { formatHumanReadableDateTimeSeconds } from '../../util/date_utils';
import { getNestedProperty } from '../../util/object_utils';
Expand Down Expand Up @@ -110,7 +111,10 @@ export const getDataGridSchemasFromFieldTypes = (fieldTypes: FieldTypes, results
schema = 'numeric';
}

if (field.includes(`${resultsField}.${FEATURE_IMPORTANCE}`)) {
if (
field.includes(`${resultsField}.${FEATURE_IMPORTANCE}`) ||
field.includes(`${resultsField}.${TOP_CLASSES}`)
) {
schema = 'json';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ export const getPredictionFieldName = (
return predictionFieldName;
};

export const getNumTopClasses = (
analysis: AnalysisConfig
): ClassificationAnalysis['classification']['num_top_classes'] => {
let numTopClasses;
if (isClassificationAnalysis(analysis) && analysis.classification.num_top_classes !== undefined) {
numTopClasses = analysis.classification.num_top_classes;
}
return numTopClasses;
};

export const getNumTopFeatureImportanceValues = (
analysis: AnalysisConfig
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
export const DEFAULT_RESULTS_FIELD = 'ml';
export const FEATURE_IMPORTANCE = 'feature_importance';
export const FEATURE_INFLUENCE = 'feature_influence';
export const TOP_CLASSES = 'top_classes';
export const OUTLIER_SCORE = 'outlier_score';
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import {
getNumTopClasses,
getNumTopFeatureImportanceValues,
getPredictedFieldName,
getDependentVar,
Expand All @@ -18,7 +19,7 @@ import { Field } from '../../../../common/types/fields';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../../../../../../../src/plugins/data/public';
import { newJobCapsService } from '../../services/new_job_capabilities_service';

import { FEATURE_IMPORTANCE, FEATURE_INFLUENCE, OUTLIER_SCORE } from './constants';
import { FEATURE_IMPORTANCE, FEATURE_INFLUENCE, OUTLIER_SCORE, TOP_CLASSES } from './constants';

export type EsId = string;
export type EsDocSource = Record<string, any>;
Expand Down Expand Up @@ -177,6 +178,7 @@ export const getDefaultFieldsFromJobCaps = (

const featureImportanceFields = [];
const featureInfluenceFields = [];
const topClassesFields = [];
const allFields: any = [];
let type: ES_FIELD_TYPES | undefined;
let predictedField: string | undefined;
Expand Down Expand Up @@ -207,20 +209,29 @@ export const getDefaultFieldsFromJobCaps = (
type = newJobCapsService.getFieldById(dependentVariable)?.type;
const predictionFieldName = getPredictionFieldName(jobConfig.analysis);
const numTopFeatureImportanceValues = getNumTopFeatureImportanceValues(jobConfig.analysis);
const numTopClasses = getNumTopClasses(jobConfig.analysis);

const defaultPredictionField = `${dependentVariable}_prediction`;
predictedField = `${resultsField}.${
predictionFieldName ? predictionFieldName : defaultPredictionField
}`;

if ((numTopFeatureImportanceValues ?? 0) > 0 && needsDestIndexFields === true) {
if ((numTopFeatureImportanceValues ?? 0) > 0) {
featureImportanceFields.push({
id: `${resultsField}.${FEATURE_IMPORTANCE}`,
name: `${resultsField}.${FEATURE_IMPORTANCE}`,
type: KBN_FIELD_TYPES.UNKNOWN,
});
}

if ((numTopClasses ?? 0) > 0) {
topClassesFields.push({
id: `${resultsField}.${TOP_CLASSES}`,
name: `${resultsField}.${TOP_CLASSES}`,
type: KBN_FIELD_TYPES.UNKNOWN,
});
}

// Only need to add these fields if we didn't use dest index pattern to get the fields
if (needsDestIndexFields === true) {
allFields.push(
Expand All @@ -234,7 +245,12 @@ export const getDefaultFieldsFromJobCaps = (
}
}

allFields.push(...fields, ...featureImportanceFields, ...featureInfluenceFields);
allFields.push(
...fields,
...featureImportanceFields,
...featureInfluenceFields,
...topClassesFields
);
allFields.sort(({ name: a }: { name: string }, { name: b }: { name: string }) =>
sortExplorationResultsFields(a, b, jobConfig)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {
import { SavedSearchQuery } from '../../../../../contexts/ml';

import { getIndexData, getIndexFields, DataFrameAnalyticsConfig } from '../../../../common';
import { DEFAULT_RESULTS_FIELD, FEATURE_IMPORTANCE } from '../../../../common/constants';
import {
DEFAULT_RESULTS_FIELD,
FEATURE_IMPORTANCE,
TOP_CLASSES,
} from '../../../../common/constants';
import { sortExplorationResultsFields, ML__ID_COPY } from '../../../../common/fields';

export const useExplorationResults = (
Expand Down Expand Up @@ -47,8 +51,9 @@ export const useExplorationResults = (
25,
// reduce default selected rows from 20 to 8 for performance reasons.
8,
// by default, hide feature-importance columns and the doc id copy
(d) => !d.includes(`.${FEATURE_IMPORTANCE}.`) && d !== ML__ID_COPY
// by default, hide feature-importance and top-classes columns and the doc id copy
(d) =>
!d.includes(`.${FEATURE_IMPORTANCE}.`) && !d.includes(`.${TOP_CLASSES}.`) && d !== ML__ID_COPY
);

useEffect(() => {
Expand Down

0 comments on commit e2f11e9

Please sign in to comment.