×
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!
K-means minus two | 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
K-means minus two
Details:
Created
Thu, 8 Oct 2026 15:03:41 +0000
Published
Thu, 8 Oct 2026 17:25:38 +0000
Description:
Implementation of the k-means-minus-two algorithm
Tags:
BigMLer
BigMLer_ThuOct0826_170340
means minus two
URL:
https://bigml.com/user/whizzml/gallery/script/6ac7b0cdc31cdddafbef9048
Script
FREE
Source code
;; An implementation of the k-means-- ;; algorithm. http://pmg.it.usyd.edu.au/outliers.pdf ;; ;; Given a dataset of points to be clustered, a number of clusters k, a ;; number of anomalies l, a Jaccard index threshold, and a maximum ;; number of iterations, returns a list containing the final cluster ;; id, the original dataset appended with cluster membership and ;; centroid distance, the list of l anomalous points, and a list of the ;; similarity between sets of anomalies at each step of the algorithm. (define (headers fields) (let (sorted-fields (sort-by-key "column_number" (values fields))) (map (lambda (f) (f "name")) sorted-fields))) (define (make-anomalies-ds clustering) (let (a-sample-id (clustering 3) anomalies (clustering 2) a-headers (cons "Row" (headers (resource-fields (clustering 1)))) anomalies-data (join "\n" (map (lambda (r) (join "," r)) (cons a-headers anomalies))) anomalies-ds (create-and-wait-dataset {"source" (create-source {"data" anomalies-data}) "name" (str ((fetch a-sample-id) "name") " - anomalies")})) (delete a-sample-id) (append (butlast clustering) anomalies-ds))) (define (get-anomalies ds-id filtered-ds k l) (let (cluster-params (merge (if (> k 0) {"k" k} {}) {"dataset" filtered-ds}) cluster-id (create-cluster cluster-params) batchcentroid-id (create-and-wait-batchcentroid {"cluster" cluster-id "dataset" ds-id "all_fields" true "distance" true "output_dataset" true}) batchcentroid (fetch batchcentroid-id) centroid-ds (batchcentroid "output_dataset_resource") sample-id (create-and-wait-sample centroid-ds) field-id ((fetch centroid-ds) ["objective_field" "id"]) anomalies (fetch sample-id {"row_order_by" (str "-" field-id) "mode" "linear" "rows" l "index" true})) (delete batchcentroid-id) [cluster-id centroid-ds (anomalies ["sample" "rows"]) sample-id])) (define (k-minus-two ds-id k l threshold max-iter) (let (dataset (fetch ds-id) fields (dataset "input_fields") l (if (> l 1) l (max (round (* l (dataset "rows")))))) (loop (dataset ds-id cnt 1 old-ids [] old-list []) (log-info "Iteration number " cnt) (let (clustering (get-anomalies ds-id dataset k l) distance (last (last (nth clustering 2))) point-ids (map head (nth clustering 2)) intersect-count (reduce (lambda (n k) (if (member? k point-ids) (+ 1 n) n)) 0 old-ids) union-count (reduce (lambda (n k) (if (member? k old-ids) n (+ 1 n))) (count old-ids) point-ids) similarity-list (append old-list (/ intersect-count union-count)) new-dataset (create-and-wait-dataset (nth clustering 1) {"input_fields" fields "lisp_filter" (flatline "(< (field " " \"distance\")" " {distance})")})) (cond (or (= cnt max-iter) (> (last similarity-list) threshold)) (prog (delete new-dataset) (let (clustering (make-anomalies-ds clustering)) (append clustering similarity-list))) (prog (delete* [(nth clustering 0) (nth clustering 1)]) (recur new-dataset (+ cnt 1) point-ids similarity-list))))))) (define [cluster dataset-id anomalies anomalies-ds similarities] (k-minus-two dataset k l threshold maximum))
Description
Implementation of the k-means-minus-two algorithm
Implementation of the k-means-minus-two algorithm
Show more
Inputs
Outputs
License:
Creative Commons Zero V1.0
Script
FREE
K-means minus two | BigML.com
Sending Request...
Sending Request...