×
BigML is working hard to support a wide range of browsers. Your experience will be better with:
English
Sign up / in
Sign up
Sign in
or Sign in with...
Amazon
Github
GitLab
Google
Toggle navigation
PRODUCT
Features
Releases
What's New
GETTING STARTED
PRICING
Subscriptions
Private Deployments
Training
Certifications
BigML for Education
SUPPORT
Toggle navigation
PRODUCT
Features
Releases
What's New
GETTING STARTED
PRICING
Subscriptions
Private Deployments
Training
Certifications
BigML for Education
SUPPORT
License
Oops!
We could not process your request!
Create category models | BigML.com
×
Embed this Script in your web site
Copy & Paste this code into your HTML code:
whizzml
Public
whizzml's
Scripts
77
Models
0
Datasets
0
0
FREE
BUY
Create category models
Details:
Created
Thu, 8 Oct 2026 14:59:55 +0000
Published
Thu, 8 Oct 2026 17:26:28 +0000
Description:
Generate models for a dataset, simulating a root split on a given field
Tags:
BigMLer
BigMLer_ThuOct0826_165955
URL:
https://bigml.com/user/whizzml/gallery/script/6ac7afeb5ada585217a2f276
Script
FREE
Source code
;; Given a dataset, a field and a model kind, splits the dataset per ;; category and uses the results to create models of the given kind. ;; Find field by either name or id (define (find-field* fields field) (or (when (contains? fields field) [(fields field) field]) (loop (ids (keys fields)) (cond (empty? ids) (raise (str "Field not found: " field)) (= field (fields [(head ids) "name"] "")) [(fields (head ids)) (head ids)] (recur (tail ids)))))) ;; Given a dataset and a categorical field id or name, find ;; the associated list of categories and the missing count. (define (categories dataset-id field-id) (let ([f id] (find-field* ((fetch dataset-id) "fields") field-id)) (when (not (= "categorical" (f "optype"))) (raise (str "Field '" field-id "' is not categorical"))) (let (cs (map head (f ["summary" "categories"] []))) (when (empty? cs) (raise (str "Field '" field-id "' does not contain any category"))) [cs (f ["summary" "missing_count"] 0) id (f "name")]))) ;; Given a parent dataset, a field and one of its categories, ;; create a new dataset containing only the instances of the parent ;; that have the given category. (define (category-dataset origin-id field category ds-name) (let (fltr (flatline "(= (f {{field}}) {{category}})")) (create-dataset origin-id {"lisp_filter" fltr "name" (str ds-name " > " category)}))) ;; Create a dataset and a model for missing values of field (define (missings-resources dataset missings field kind params) (if (positive? missings) (let (fl (flatline "(missing? {{field}})") ds (create-dataset dataset {"lisp_filter" fl})) [ds (wait (create kind ds params))]) [false false])) ;; Final workflow for multiway first split (define (multiway-model dataset field objective kind parameters) (let ([cs missings id name] (categories dataset field) ds-name ((fetch dataset) "name") ds (for (c cs) (category-dataset dataset field c ds-name)) ps (if (empty? objective) parameters (assoc parameters "objective_field" objective)) ms (for (d ds) (create kind d ps)) [md mm] (missings-resources dataset missings field kind ps)) (wait* ms) (delete* ds) (when md (delete md)) {"categories" cs "field-id" id "field-name" name "models" ms "binary" false "kind" kind "missings-model" mm})) ;; Find the category for a binary split (define (find-category dataset id params) (let (m-id (wait (create-model dataset (assoc params "input_fields" [id]))) m (fetch m-id {"exclude" "fields"}) c (m ["model" "root" "children" 0 "predicate" "value"] false)) (delete m-id) (or c (raise "Unable to find a category for first split")))) ;; Split a dataset extracting a given category (define (split-on-category dataset id cat) (let (fl (flatline "(= (f {{id}}) {{cat}})") nfl (flatline "(!= (f {{id}}) {{cat}})")) (for (f [fl nfl]) (create-dataset dataset {"lisp_filter" f})))) ;; Final workflow for binary first split (define (binary-model dataset field objective kind parameters) (let ([cs missings id name] (categories dataset field) ps (if (empty? objective) parameters (assoc parameters "objective_field" objective)) c (find-category dataset id ps) ds (split-on-category dataset id c) ms (wait* (for (d ds) (create kind d ps)))) (delete* ds) {"category" c "field-id" id "field-name" name "models" ms "binary" true "kind" kind})) (define result (let (f (if binary-split binary-model multiway-model)) (f dataset split-field objective model-kind model-parameters)))
Description
Generate models for a dataset, simulating a root split on a given field
Generate models for a dataset, simulating a root split on a given field
Show more
Inputs
Outputs
License:
Creative Commons Zero V1.0
Script
FREE
Create category models | BigML.com
Sending Request...
Sending Request...