Skip to content

Instantly share code, notes, and snippets.

@mmerce
Last active November 2, 2018 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmerce/df209e7d69d2122cfd9e5900adb349d8 to your computer and use it in GitHub Desktop.
Save mmerce/df209e7d69d2122cfd9e5900adb349d8 to your computer and use it in GitHub Desktop.
Creating dataset with top-n features of a model
{
"name": "Top n features dataset from model",
"description": "It creates a dataset that includes the top n features as detected by a model",
"inputs": [
{
"name": "model-id",
"type": "model-id",
"description": "Model that selects the features"
},
{
"name": "n",
"type": "number",
"default": 5,
"description": "Number of features to be selected"
},
{
"name": "dataset-id",
"type": "string",
"description": "Dataset to select the features from"
}
],
"outputs": [
{
"name": "top-n-dataset",
"type": "dataset-id",
"description": "Dataset with the top-n best features according to the model"
}
]
}
(define (top-n-features-dataset model-id n dataset-id)
(let (model (fetch model-id)
important-fields (map head (model ["model" "importance"]))
important-fields (cons (model "objective_field") important-fields)
fields (model ["model" "fields"])
important-fields (map (lambda (x) ((find-field fields x) "name"))
important-fields)
dataset-fields (take (+ n 1) important-fields)
dataset-id (if (empty? dataset-id)
(model "dataset")
dataset-id))
(create-and-wait-dataset dataset-id {"input_fields" dataset-fields})))
(define top-n-dataset (top-n-features-dataset model-id n dataset-id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment