Last active
November 2, 2018 08:41
-
-
Save mmerce/df209e7d69d2122cfd9e5900adb349d8 to your computer and use it in GitHub Desktop.
Creating dataset with top-n features of a model
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
{ | |
"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" | |
} | |
] | |
} |
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
(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