-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Add decision path charts to exploration results table #73561
Changes from 49 commits
62e8918
031415f
40ef5e6
7e47db9
e8d0b41
5ad6690
40f17cf
ea12a63
49a541c
52964e5
efbeffd
8b1e8c8
e029cfc
19a1aae
c718437
d0fa245
a317505
973ddb9
1c22df3
f248722
39e3749
0c57415
6b525b4
c7bd561
c9261a4
38a5e48
c6cf181
175bfd4
c5b68d5
0970f04
0fa835f
669c683
eccdb4d
049ba5a
172a58e
ef815d1
74ef5fd
eaae596
b50daae
9aa5d81
a71e190
9f435f6
a954cc6
09495e3
1345cf2
76488b6
a93e740
004518b
5fd5ff4
b857ffe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export const DEFAULT_RESULTS_FIELD = 'ml'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export interface ClassFeatureImportance { | ||
class_name: string | boolean; | ||
importance: number; | ||
} | ||
export interface FeatureImportance { | ||
feature_name: string; | ||
importance?: number; | ||
classes?: ClassFeatureImportance[]; | ||
} | ||
|
||
export interface TopClass { | ||
class_name: string; | ||
class_probability: number; | ||
class_score: number; | ||
} | ||
|
||
export type TopClasses = TopClass[]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
AnalysisConfig, | ||
ClassificationAnalysis, | ||
OutlierAnalysis, | ||
RegressionAnalysis, | ||
ANALYSIS_CONFIG_TYPE, | ||
} from '../types/data_frame_analytics'; | ||
|
||
export const isOutlierAnalysis = (arg: any): arg is OutlierAnalysis => { | ||
const keys = Object.keys(arg); | ||
return keys.length === 1 && keys[0] === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION; | ||
}; | ||
|
||
export const isRegressionAnalysis = (arg: any): arg is RegressionAnalysis => { | ||
const keys = Object.keys(arg); | ||
return keys.length === 1 && keys[0] === ANALYSIS_CONFIG_TYPE.REGRESSION; | ||
}; | ||
|
||
export const isClassificationAnalysis = (arg: any): arg is ClassificationAnalysis => { | ||
const keys = Object.keys(arg); | ||
return keys.length === 1 && keys[0] === ANALYSIS_CONFIG_TYPE.CLASSIFICATION; | ||
}; | ||
|
||
export const getDependentVar = ( | ||
analysis: AnalysisConfig | ||
): | ||
| RegressionAnalysis['regression']['dependent_variable'] | ||
| ClassificationAnalysis['classification']['dependent_variable'] => { | ||
let depVar = ''; | ||
|
||
if (isRegressionAnalysis(analysis)) { | ||
depVar = analysis.regression.dependent_variable; | ||
} | ||
|
||
if (isClassificationAnalysis(analysis)) { | ||
depVar = analysis.classification.dependent_variable; | ||
} | ||
return depVar; | ||
}; | ||
|
||
export const getPredictionFieldName = ( | ||
analysis: AnalysisConfig | ||
): | ||
| RegressionAnalysis['regression']['prediction_field_name'] | ||
| ClassificationAnalysis['classification']['prediction_field_name'] => { | ||
// If undefined will be defaulted to dependent_variable when config is created | ||
let predictionFieldName; | ||
if (isRegressionAnalysis(analysis) && analysis.regression.prediction_field_name !== undefined) { | ||
predictionFieldName = analysis.regression.prediction_field_name; | ||
} else if ( | ||
isClassificationAnalysis(analysis) && | ||
analysis.classification.prediction_field_name !== undefined | ||
) { | ||
predictionFieldName = analysis.classification.prediction_field_name; | ||
} | ||
return predictionFieldName; | ||
}; | ||
|
||
export const getDefaultPredictionFieldName = (analysis: AnalysisConfig) => { | ||
return `${getDependentVar(analysis)}_prediction`; | ||
}; | ||
export const getPredictedFieldName = ( | ||
resultsField: string, | ||
analysis: AnalysisConfig, | ||
forSort?: boolean | ||
) => { | ||
// default is 'ml' | ||
const predictionFieldName = getPredictionFieldName(analysis); | ||
const predictedField = `${resultsField}.${ | ||
predictionFieldName ? predictionFieldName : getDefaultPredictionFieldName(analysis) | ||
}`; | ||
return predictedField; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,13 +119,14 @@ export const getDataGridSchemasFromFieldTypes = (fieldTypes: FieldTypes, results | |
schema = 'numeric'; | ||
} | ||
|
||
if ( | ||
field.includes(`${resultsField}.${FEATURE_IMPORTANCE}`) || | ||
field.includes(`${resultsField}.${TOP_CLASSES}`) | ||
) { | ||
if (field.includes(`${resultsField}.${TOP_CLASSES}`)) { | ||
schema = 'json'; | ||
} | ||
|
||
if (field.includes(`${resultsField}.${FEATURE_IMPORTANCE}`)) { | ||
schema = 'featureImportance'; | ||
} | ||
|
||
return { id: field, schema, isSortable }; | ||
}); | ||
}; | ||
|
@@ -250,10 +251,6 @@ export const useRenderCellValue = ( | |
return cellValue ? 'true' : 'false'; | ||
} | ||
|
||
if (typeof cellValue === 'object' && cellValue !== null) { | ||
return JSON.stringify(cellValue); | ||
} | ||
|
||
Comment on lines
-253
to
-256
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why this is no longer necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this line is a duplicate of line 228 of this file so I removed it. This change shouldn't cause any issue :) |
||
return cellValue; | ||
}; | ||
}, [indexPattern?.fields, pagination.pageIndex, pagination.pageSize, tableItems]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using const instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just talked to Melissa and since
ANALYSIS_CONFIG_TYPE
is used in a quite a lot of place, I think it's better to do this in a follow-up PR.