-
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 feature importance summary charts #78238
Changes from 11 commits
f2b59b7
f14cae9
c8dd714
255c5c3
6820ab7
2226e92
8f18b98
dc2538b
bf2a837
f263a75
c419c42
fd279e4
5ca3178
6a3c0d8
89f1ee3
25f8f83
58fe66b
e18bc41
da48b1a
3c4251f
b73325b
ab8a750
4c0abf5
17cfd1d
701cbc2
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 |
---|---|---|
|
@@ -15,13 +15,18 @@ import { ml } from '../../services/ml_api_service'; | |
import { newJobCapsService } from '../../services/new_job_capabilities_service'; | ||
import { useMlContext } from '../../contexts/ml'; | ||
|
||
import { DataFrameAnalyticsConfig } from '../common'; | ||
import { ANALYSIS_CONFIG_TYPE, DataFrameAnalyticsConfig, getAnalysisType } from '../common'; | ||
|
||
import { isGetDataFrameAnalyticsStatsResponseOk } from '../pages/analytics_management/services/analytics_service/get_analytics'; | ||
import { DATA_FRAME_TASK_STATE } from '../pages/analytics_management/components/analytics_list/common'; | ||
import { useInferenceApiService } from '../../services/ml_api_service/inference'; | ||
import { TotalFeatureImportance } from '../../../../common/types/inference'; | ||
import { getToastNotificationService } from '../../services/toast_notification_service'; | ||
|
||
export const useResultsViewConfig = (jobId: string) => { | ||
const mlContext = useMlContext(); | ||
const inferenceApiService = useInferenceApiService(); | ||
|
||
const [indexPattern, setIndexPattern] = useState<IndexPattern | undefined>(undefined); | ||
const [isInitialized, setIsInitialized] = useState<boolean>(false); | ||
const [needsDestIndexPattern, setNeedsDestIndexPattern] = useState<boolean>(false); | ||
|
@@ -33,13 +38,18 @@ export const useResultsViewConfig = (jobId: string) => { | |
const [jobConfigErrorMessage, setJobConfigErrorMessage] = useState<undefined | string>(undefined); | ||
const [jobStatus, setJobStatus] = useState<DATA_FRAME_TASK_STATE | undefined>(undefined); | ||
|
||
const [totalFeatureImportance, setTotalFeatureImportance] = useState< | ||
TotalFeatureImportance[] | undefined | ||
>(undefined); | ||
|
||
// get analytics configuration, index pattern and field caps | ||
useEffect(() => { | ||
(async function () { | ||
setIsLoadingJobConfig(false); | ||
|
||
try { | ||
const analyticsConfigs = await ml.dataFrameAnalytics.getDataFrameAnalytics(jobId); | ||
|
||
const analyticsStats = await ml.dataFrameAnalytics.getDataFrameAnalyticsStats(jobId); | ||
const stats = isGetDataFrameAnalyticsStatsResponseOk(analyticsStats) | ||
? analyticsStats.data_frame_analytics[0] | ||
|
@@ -54,6 +64,29 @@ export const useResultsViewConfig = (jobId: string) => { | |
analyticsConfigs.data_frame_analytics.length > 0 | ||
) { | ||
const jobConfigUpdate = analyticsConfigs.data_frame_analytics[0]; | ||
const analysisType = getAnalysisType(jobConfigUpdate.analysis); | ||
// don't fetch the total feature importance if it's outlier_detection | ||
if ( | ||
analysisType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION || | ||
analysisType === ANALYSIS_CONFIG_TYPE.REGRESSION | ||
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. In 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. I have updated it to using the util functions here e18bc41 |
||
) { | ||
try { | ||
const inferenceModels = await inferenceApiService.getInferenceModel(`${jobId}*`, { | ||
include: 'total_feature_importance', | ||
}); | ||
const inferenceModel = inferenceModels.find( | ||
(model) => model.metadata?.analytics_config?.id === jobId | ||
); | ||
if ( | ||
Array.isArray(inferenceModel?.metadata?.total_feature_importance) === true && | ||
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. Nit - I don't think you really need the 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. For some reasons TS needs the explicit check here to make the second part of the if statement valid. Not sure why but I will leave it for now if that's okay. |
||
inferenceModel?.metadata?.total_feature_importance.length > 0 | ||
) { | ||
setTotalFeatureImportance(inferenceModel?.metadata?.total_feature_importance); | ||
} | ||
} catch (e) { | ||
getToastNotificationService().displayErrorToast(e); | ||
} | ||
} | ||
|
||
try { | ||
const destIndex = Array.isArray(jobConfigUpdate.dest.index) | ||
|
@@ -103,5 +136,6 @@ export const useResultsViewConfig = (jobId: string) => { | |
jobConfigErrorMessage, | ||
jobStatus, | ||
needsDestIndexPattern, | ||
totalFeatureImportance, | ||
}; | ||
}; |
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.
We also have
feature_importance.ts
in the same directory, can we move all additions to this file tofeature_importances.ts
?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.
Updated here e18bc41