×
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!
Pick random row in group | BigML.com
×
Embed this Script in your web site
Copy & Paste this code into your HTML code:
mmartin
Public
mmartin's
Scripts
1
Models
0
Datasets
0
8
FREE
BUY
Pick random row in group
Details:
Created
Fri, 25 Jan 2019 21:22:40 +0000
Published
Sun, 27 Jan 2019 00:26:37 +0000
Description:
Selects one of the rows (at random) from the ones grouped by a list of fields
Tags:
URL:
https://bigml.com/user/mmartin/gallery/script/5c4b7e20eba31d5884000751
Script
FREE
Source code
(define fields (resource-fields dataset-id)) (define find-fields-fn (lambda (x) (find-field fields x))) (define filter-id-fn (lambda (x) (when (map? x) (x "id")))) (define order-by-fields (filter string? (map filter-id-fn (map find-fields-fn fields-list)))) (if (= (count order-by-fields) 0) (raise "Could not find a grouping field list") (log-info order-by-fields)) (define order-strs (append (map (lambda (x) (str "A.`" x "`")) order-by-fields) "RAND()")) (define order-str (join ", " order-strs)) (define filter-str-fn (lambda (x) (flatline "(= (f {{x}}) (f {{x}} -1))"))) (define filter-strs (map filter-str-fn order-by-fields)) (define filter-str (join " " filter-strs)) (define ordered-dataset (create-and-wait-dataset {"origin_datasets" [dataset-id] "sql_query" (flatline "select A.* from A order by {order-str}") "origin_dataset_names" (assoc {} dataset-id "A")})) (define filtered-dataset (try (create-and-wait-dataset {"origin_dataset" ordered-dataset "lisp_filter" (flatline "(not (and {filter-str}))")}) (catch e (log-info "Error: " e)))) (delete ordered-dataset)
Description
Selects one of the rows (at random) from the ones grouped by a list of fields
Selects one of the rows (at random) from the ones grouped by a list of fields
Show more
Inputs
Outputs
License:
Creative Commons Zero V1.0
Script
FREE
Pick random row in group | BigML.com
Sending Request...
Sending Request...