Last active
November 5, 2020 21:29
-
-
Save jeffvestal/39830dd40dfd907a7296599498b7229e to your computer and use it in GitHub Desktop.
Dev Tools Data from Elastic Classification Churn Demo
This file contains 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
# Preview and create transform | |
# PUT _transform/churn | |
POST _transform/_preview | |
{ | |
"source": { | |
"index": [ | |
"churn_demo-calls", | |
"churn_demo-customers" | |
] | |
}, | |
"dest": { | |
"index": "churn" | |
}, | |
"pivot": { | |
"group_by": { | |
"phone_number": { | |
"terms": { | |
"field": "phone_number" | |
} | |
} | |
}, | |
"aggregations": { | |
"call_charges": { | |
"sum": { | |
"field": "call_charges" | |
} | |
}, | |
"call_duration": { | |
"sum": { | |
"field": "call_duration" | |
} | |
}, | |
"call_count": { | |
"value_count": { | |
"field": "dialled_number" | |
} | |
}, | |
"customer_service_calls": { | |
"sum": { | |
"field": "customer_service_calls" | |
} | |
}, | |
"number_vmail_messages": { | |
"sum": { | |
"field": "number_vmail_messages" | |
} | |
}, | |
"churn": { | |
"scripted_metric": { | |
"init_script": "state.churn = null", | |
"map_script": "state.churn = params._source.churn", | |
"combine_script": "return state.churn", | |
"reduce_script": "for (d in states) if (d != null) return d" | |
} | |
}, | |
"account_length": { | |
"scripted_metric": { | |
"init_script": "state.account_length = null", | |
"map_script": "state.account_length = params._source.account_length", | |
"combine_script": "return state.account_length", | |
"reduce_script": "for (d in states) if (d != null) return d" | |
} | |
}, | |
"international_plan": { | |
"scripted_metric": { | |
"init_script": "state.international_plan = null", | |
"map_script": "state.international_plan = params._source.international_plan", | |
"combine_script": "return state.international_plan", | |
"reduce_script": "for (d in states) if (d != null) return d" | |
} | |
}, | |
"voice_mail_plan": { | |
"scripted_metric": { | |
"init_script": "state.voice_mail_plan = null", | |
"map_script": "state.voice_mail_plan = params._source.voice_mail_plan", | |
"combine_script": "return state.voice_mail_plan", | |
"reduce_script": "for (d in states) if (d != null) return d" | |
} | |
}, | |
"state": { | |
"scripted_metric": { | |
"init_script": "state.state = null", | |
"map_script": "state.state = params._source.state", | |
"combine_script": "return state.state", | |
"reduce_script": "for (d in states) if (d != null) return d" | |
} | |
} | |
} | |
} | |
} | |
## Index Template | |
index template name: churn_template | |
template_config = { | |
"index_patterns": [ | |
"churn*" | |
], | |
"settings": { | |
"number_of_shards": 1 | |
}, | |
"mappings": { | |
"dynamic_templates": [ | |
{ | |
"strings_as_keyword": { | |
"match_mapping_type": "string", | |
"mapping": { | |
"type": "keyword" | |
} | |
} | |
} | |
] | |
} | |
} | |
## Set up Inferernce Processor | |
# need to get model ID | |
GET /_ml/inference/ | |
## Inference Processor Settings | |
{ | |
"model_id": "<GET_MODEL_ID>", | |
"inference_config": { | |
"classification": { | |
"num_top_classes": 2 | |
} | |
}, | |
"description": "churn_analysis-model" | |
} | |
## Inference pipeline test doc | |
[ | |
{ | |
"_source": { | |
"voice_mail_plan": "yes", | |
"call_count": 312, | |
"number_vmail_messages": 15, | |
"account_length": 119, | |
"phone_number": "415-352-5118", | |
"international_plan": "yes", | |
"state": "NM", | |
"call_charges": 48.71000000000003, | |
"customer_service_calls": 5, | |
"call_duration": 451.8000000000003 | |
} | |
} | |
] | |
## Original Eland based Elastic Webinar Github | |
- including calls.csv and customer.csv | |
http://ela.st/supervised-ml-webinar | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment