×
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!
Forward stepwise regression | 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
Forward stepwise regression
Details:
Created
Thu, 8 Oct 2026 15:00:30 +0000
Published
Thu, 8 Oct 2026 17:26:19 +0000
Description:
Find the best features for building a logistic regression using a greedy algorithm
Tags:
BigMLer
BigMLer_ThuOct0826_170030
URL:
https://bigml.com/user/whizzml/gallery/script/6ac7b00e5ada585217a2f279
Script
FREE
Source code
;; Get feature names given ids (define (feature-names dataset-id ids) (let (fields ((fetch dataset-id) "fields")) (map (lambda (id) (fields [id "name"])) ids))) ;; Get the default set of input fields for this dataset (all preferred ;; fields minus the objective field). (define (default-inputs dataset-id obj-id) (let (fields ((fetch dataset-id) "fields") fids (keys fields)) (filter (lambda (k) (and (fields [k "preferred"] true) (not (= obj-id k)))) fids))) ;; Make a list of logistic regressions using the given dataset, ;; objective field and selected features. For each lr, add one of the ;; potential features in potentials to the input feature list. (define (make-lr dataset-id obj-field selected potentials) (let (all-reqs (for (fid potentials) {"dataset" dataset-id "objective_field" obj-field "input_fields" (cons fid selected)})) (create-and-wait* "logisticregression" all-reqs))) ;; Given a test dataset, a list of potential features, and a list of ;; model ids corresponding to those features, select the best ;; potential feature by performing an evaluation on each model and ;; returning the feature with the best performance. (define (select-feature test-dataset-id potentials model-ids) (let (eval-req {"dataset" test-dataset-id} make-req (lambda (mid) (assoc eval-req "model" mid)) all-reqs (map make-req model-ids) evs (map fetch (create-and-wait* "evaluation" all-reqs)) vs (map (lambda (ev) (ev ["result" "model" "average_f_measure"] 0)) evs) value-map (make-map potentials vs) max-val (apply max vs) choose-best (lambda (id) (and (= max-val (value-map id)) id))) (delete* (map (lambda (x) (x "resource")) evs)) [(some choose-best potentials) max-val])) ;; Retrieves and checks whether the objective field of the given ;; dataset is categorical, raising an error otherwise. (define (get-objective ds-id obj-id) (let (obj-id (if (empty? obj-id) (dataset-get-objective-id ds-id) obj-id) otype ((fetch ds-id) ["fields" obj-id "optype"] "missing")) (when (not (= "categorical" otype)) (raise (str "The dataset's objective field must be categorical, " "but is " otype))) obj-id)) ;; Do forward stepwise regression. Given a dataset and a target ;; number of features iteratively construct logistic regressions for ;; each feature, evaluate them, and add the feature corresponding to ;; the best evaluation to the running set of features. To avoid ;; overfitting, a different training and test split is used when ;; choosing each feature. Stop when you reach the target number, or ;; you run out of features. (define (select-features dataset-id threshold objective-id) (let (obj-id (get-objective dataset-id objective-id) input-ids (default-inputs dataset-id obj-id)) (loop (selected [] potentials input-ids f-measure 0) (let (_ (log-info "Splitting dataset...") [train-id test-id] (create-dataset-split dataset-id 0.5 "bigml") _ (log-info "Making logistic regressions...") model-ids (make-lr train-id obj-id selected potentials) _ (log-info "Selecting feature...") next-feat (select-feature test-id potentials model-ids) _ (log-info "Selected feature is " (next-feat 0)) diff (- (next-feat 1) (+ f-measure threshold))) (log-info "Best f-measure is " (next-feat 1)) (delete* (concat [train-id test-id] model-ids)) (if (or (>= 0 diff) (empty? potentials)) (feature-names dataset-id selected) (recur (cons (next-feat 0) selected) (filter (lambda (id) (not (= id (next-feat 0)))) potentials) (next-feat 1))))))) (define output-features (select-features dataset-id threshold objective-id))
Description
Find the best features for building a logistic regression using a greedy algorithm
Find the best features for building a logistic regression using a greedy algorithm
Show more
Inputs
Outputs
License:
Creative Commons Zero V1.0
Script
FREE
Forward stepwise regression | BigML.com
Sending Request...
Sending Request...