Skip to content

Instantly share code, notes, and snippets.

@davidkyle
Created February 7, 2020 16:37
Show Gist options
  • Save davidkyle/c8ad2c36ecc98c7bb84079622cbf7e6d to your computer and use it in GitHub Desktop.
Save davidkyle/c8ad2c36ecc98c7bb84079622cbf7e6d to your computer and use it in GitHub Desktop.
Create a trivial model and rescore with it
#!/bin/sh
curl -XPUT -u 'elastic:password' -H 'Content-Type: application/json' 'http://localhost:9200/_ml/inference/density_model?pretty' -d '
{
"input": {
"field_names": [
"key_metric"]
},
"description": "test model for regression",
"definition": {
"trained_model": {
"ensemble": {
"feature_names": [
"key_metric"
],
"target_type": "regression",
"trained_models": [
{
"tree": {
"feature_names": [
"key_metric"
],
"tree_structure": [
{
"node_index": 0,
"split_feature": 0,
"split_gain": 12,
"threshold": 38,
"decision_type": "lte",
"default_left": true,
"left_child": 1,
"right_child": 2
},
{
"node_index": 1,
"leaf_value": 1.0
},
{
"node_index": 2,
"leaf_value": 0.2
}
],
"target_type": "regression"
}
}
]
}
}
}
}'
curl -XPUT -u 'elastic:password' -H 'Content-Type: application/json' 'http://localhost:9200/goods?pretty' -d '
{
"mappings": {
"properties": {
"goods": {
"type": "text"
},
"size": {
"type": "double"
}
}
}
}'
curl -XPOST -u 'elastic:password' -H 'Content-Type: application/json' http://localhost:9200/goods/_doc -d '
{
"goods" : "television",
"size" : "32.0"
}'
curl -XPOST -u 'elastic:password' -H 'Content-Type: application/json' http://localhost:9200/goods/_doc -d '
{
"goods" : "VCR",
"size" : "0.0"
}'
curl -XPOST -u 'elastic:password' -H 'Content-Type: application/json' 'http://localhost:9200/goods/_doc?refresh' -d '
{
"goods" : "widescreen television",
"size" : "40.0"
}'
curl -XGET -u 'elastic:password' -H 'Content-Type: application/json' 'http://localhost:9200/goods/_search?pretty' -d '
{
"query": {
"term": {
"goods": {
"value": "television"
}
}
}
}'
curl -XGET -u 'elastic:password' -H 'Content-Type: application/json' 'http://localhost:9200/goods/_search?pretty' -d '
{
"query": {
"term": {
"goods": {
"value": "television"
}
}
},
"rescore": {
"ml_rescore": {
"model_id": "density_model",
"field_mappings": {"size": "key_metric"},
"inference_config": { "regression": {} }
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment