Repository navigation
[ML] Categorization wizard #53009
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
Merged
jgowdyelastic
merged 29 commits into
elastic:master
from
jgowdyelastic:categorization-wizard
Jan 9, 2020
Merged
[ML] Categorization wizard #53009
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
f1ba674
[ML] Categorization wizard
jgowdyelastic a058464
fixing js prettier issues
jgowdyelastic caadec2
adding basic category field validation
jgowdyelastic 4b77ad7
adding rare or count selection
jgowdyelastic 8d0795f
fixing types
jgowdyelastic bf3dafc
category examples changes
jgowdyelastic f2b4712
improving results search
jgowdyelastic 3c04614
adding analyzer editing
jgowdyelastic b92b087
improving callout
jgowdyelastic d38050f
updating callout text
jgowdyelastic 868da11
fixing import path
jgowdyelastic 6f0f363
resetting cat analyser json on flyout open
jgowdyelastic 84acf3c
disabling model plot by default
jgowdyelastic 1955044
minor refactoring
jgowdyelastic 03235c3
fixing types
jgowdyelastic 42cc293
hide estimate bucket span
jgowdyelastic 9b5cce9
setting default bucket span
jgowdyelastic f982bea
removing ml_classic workaround
jgowdyelastic 8130a34
changing style of detector selection
jgowdyelastic 7593215
fixing convert to advanced issue
jgowdyelastic 529f109
removing sparse data checkbox
jgowdyelastic 2b4f3b8
changes based on review
jgowdyelastic 74d31c8
use default mml
jgowdyelastic 48c1857
fixing job cloning
jgowdyelastic 2141d04
changes based on review
jgowdyelastic b5d4fca
removing categorization_analyzer from job if it is same as default
jgowdyelastic 81ca64c
fixing translations
jgowdyelastic e869c4b
disabling model plot for rare jobs
jgowdyelastic 80b802f
removing console.error in useResolver
jgowdyelastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * 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 type CategoryId = number; | ||
|
|
||
| export interface Category { | ||
| job_id: string; | ||
| category_id: CategoryId; | ||
| terms: string; | ||
| regex: string; | ||
| max_matching_length: number; | ||
| examples: string[]; | ||
| grok_pattern: string; | ||
| } | ||
|
|
||
| export interface Token { | ||
| token: string; | ||
| start_offset: number; | ||
| end_offset: number; | ||
| type: string; | ||
| position: number; | ||
| } | ||
159 changes: 159 additions & 0 deletions
159
...ugins/ml/public/application/jobs/new_job/common/job_creator/categorization_job_creator.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* | ||
| * 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 { isEqual } from 'lodash'; | ||
| import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public'; | ||
| import { SavedSearchSavedObject } from '../../../../../../common/types/kibana'; | ||
| import { JobCreator } from './job_creator'; | ||
| import { Field, Aggregation, mlCategory } from '../../../../../../common/types/fields'; | ||
| import { Job, Datafeed, Detector } from './configs'; | ||
| import { createBasicDetector } from './util/default_configs'; | ||
| import { | ||
| JOB_TYPE, | ||
| CREATED_BY_LABEL, | ||
| DEFAULT_BUCKET_SPAN, | ||
| DEFAULT_RARE_BUCKET_SPAN, | ||
| } from '../../../../../../common/constants/new_job'; | ||
| import { ML_JOB_AGGREGATION } from '../../../../../../common/constants/aggregation_types'; | ||
| import { getRichDetectors } from './util/general'; | ||
| import { CategorizationExamplesLoader, CategoryExample } from '../results_loader'; | ||
| import { CategorizationAnalyzer, getNewJobDefaults } from '../../../../services/ml_server_info'; | ||
|
|
||
| type CategorizationAnalyzerType = CategorizationAnalyzer | null; | ||
|
|
||
| export class CategorizationJobCreator extends JobCreator { | ||
| protected _type: JOB_TYPE = JOB_TYPE.CATEGORIZATION; | ||
| private _createCountDetector: () => void = () => {}; | ||
| private _createRareDetector: () => void = () => {}; | ||
| private _examplesLoader: CategorizationExamplesLoader; | ||
| private _categoryFieldExamples: CategoryExample[] = []; | ||
| private _categoryFieldValid: number = 0; | ||
| private _detectorType: ML_JOB_AGGREGATION.COUNT | ML_JOB_AGGREGATION.RARE = | ||
| ML_JOB_AGGREGATION.COUNT; | ||
| private _categorizationAnalyzer: CategorizationAnalyzerType = null; | ||
| private _defaultCategorizationAnalyzer: CategorizationAnalyzerType; | ||
|
|
||
| constructor( | ||
| indexPattern: IndexPattern, | ||
| savedSearch: SavedSearchSavedObject | null, | ||
| query: object | ||
| ) { | ||
| super(indexPattern, savedSearch, query); | ||
| this.createdBy = CREATED_BY_LABEL.CATEGORIZATION; | ||
| this._examplesLoader = new CategorizationExamplesLoader(this, indexPattern, query); | ||
|
|
||
| const { anomaly_detectors: anomalyDetectors } = getNewJobDefaults(); | ||
| this._defaultCategorizationAnalyzer = anomalyDetectors.categorization_analyzer || null; | ||
| } | ||
|
|
||
| public setDefaultDetectorProperties( | ||
| count: Aggregation | null, | ||
| rare: Aggregation | null, | ||
| eventRate: Field | null | ||
| ) { | ||
| if (count === null || rare === null || eventRate === null) { | ||
| return; | ||
| } | ||
|
|
||
| this._createCountDetector = () => { | ||
| this._createDetector(count, eventRate); | ||
| }; | ||
| this._createRareDetector = () => { | ||
| this._createDetector(rare, eventRate); | ||
| }; | ||
| } | ||
|
|
||
| private _createDetector(agg: Aggregation, field: Field) { | ||
| const dtr: Detector = createBasicDetector(agg, field); | ||
| dtr.by_field_name = mlCategory.id; | ||
| this._addDetector(dtr, agg, mlCategory); | ||
| } | ||
|
|
||
| public setDetectorType(type: ML_JOB_AGGREGATION.COUNT | ML_JOB_AGGREGATION.RARE) { | ||
| this._detectorType = type; | ||
| this.removeAllDetectors(); | ||
| if (type === ML_JOB_AGGREGATION.COUNT) { | ||
| this._createCountDetector(); | ||
| this.bucketSpan = DEFAULT_BUCKET_SPAN; | ||
| } else { | ||
| this._createRareDetector(); | ||
| this.bucketSpan = DEFAULT_RARE_BUCKET_SPAN; | ||
| this.modelPlot = false; | ||
| } | ||
| } | ||
|
|
||
| public set categorizationFieldName(fieldName: string | null) { | ||
| if (fieldName !== null) { | ||
| this._job_config.analysis_config.categorization_field_name = fieldName; | ||
| this.setDetectorType(this._detectorType); | ||
| this.addInfluencer(mlCategory.id); | ||
| } else { | ||
| delete this._job_config.analysis_config.categorization_field_name; | ||
| this._categoryFieldExamples = []; | ||
| this._categoryFieldValid = 0; | ||
| } | ||
| } | ||
|
|
||
| public get categorizationFieldName(): string | null { | ||
| return this._job_config.analysis_config.categorization_field_name || null; | ||
| } | ||
|
|
||
| public async loadCategorizationFieldExamples() { | ||
| const { valid, examples } = await this._examplesLoader.loadExamples(); | ||
| this._categoryFieldExamples = examples; | ||
| this._categoryFieldValid = valid; | ||
| return { valid, examples }; | ||
| } | ||
|
|
||
| public get categoryFieldExamples() { | ||
| return this._categoryFieldExamples; | ||
| } | ||
|
|
||
| public get categoryFieldValid() { | ||
| return this._categoryFieldValid; | ||
| } | ||
|
|
||
| public get selectedDetectorType() { | ||
| return this._detectorType; | ||
| } | ||
|
|
||
| public set categorizationAnalyzer(analyzer: CategorizationAnalyzerType) { | ||
| this._categorizationAnalyzer = analyzer; | ||
|
|
||
| if ( | ||
| analyzer === null || | ||
| isEqual(this._categorizationAnalyzer, this._defaultCategorizationAnalyzer) | ||
| ) { | ||
| delete this._job_config.analysis_config.categorization_analyzer; | ||
| } else { | ||
| this._job_config.analysis_config.categorization_analyzer = analyzer; | ||
| } | ||
| } | ||
|
|
||
| public get categorizationAnalyzer() { | ||
| return this._categorizationAnalyzer; | ||
| } | ||
|
|
||
| public cloneFromExistingJob(job: Job, datafeed: Datafeed) { | ||
| this._overrideConfigs(job, datafeed); | ||
| this.createdBy = CREATED_BY_LABEL.CATEGORIZATION; | ||
| const detectors = getRichDetectors(job, datafeed, this.scriptFields, false); | ||
|
|
||
| const dtr = detectors[0]; | ||
| if (detectors.length && dtr.agg !== null && dtr.field !== null) { | ||
| this._detectorType = | ||
| dtr.agg.id === ML_JOB_AGGREGATION.COUNT | ||
| ? ML_JOB_AGGREGATION.COUNT | ||
| : ML_JOB_AGGREGATION.RARE; | ||
|
|
||
| const bs = job.analysis_config.bucket_span; | ||
| this.setDetectorType(this._detectorType); | ||
| // set the bucketspan back to the original value | ||
| // as setDetectorType applies a default | ||
| this.bucketSpan = bs; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.