Skip to content

A browser ML project: a rule, a model, and a recorded mistake

A useful ML project compares a trained model with a simple baseline, inspects mistakes, and runs the saved result in an application. Deep Orbit's independent project asks you to do that with recorded room measurements and JavaScript. Try the supplied training example below to see how a model compares with a light-threshold rule on later readings.

By , a group of JavaScript engineers. Updated .

The task and its data

A facilities team wants a review-only display of whether one office is occupied. The inputs are temperature, relative humidity, light, CO₂, and humidity ratio. You choose features, chronological training/validation/test periods, error costs, a model, and a decision threshold.

The starter includes 2,056 recorded measurements derived from the UCI Occupancy Detection dataset. These are real room recordings. They are a separate source from Deep Orbit's fictional ship data.

Tensorcraft sorted the source's 20,560 readings by timestamp and kept every tenth row. The subset preserves values and labels. This sampling reduces download size. It does not make nearby observations independent. The source timestamps have no assigned timezone.

The data attribution and modification record supplies the citation, CC BY 4.0 terms, archive hash, and transformation details. The experiment serves one recorded room. It does not establish performance in another building or suitability for access controls.

Supplied five-epoch reference

We recorded this maintainer run with TensorFlow.js 4.22.0 on the CPU backend. It used the same supplied training code and recorded data as the browser demo. We last verified it on .

The first 1,200 readings fit the scaler and model. Both policies were then checked on the next 400 validation readings. The last 456 readings remain unused. These are supplied reference results. Your browser run appears in its own section below.

Supplied reference on 400 validation readings
OutcomeLight ruleModel, five epochs
Correct occupied6160
Correct empty303319
False alarms3620
Missed occupancy01
Correct predictions91%94.75%
Illustrative error cost3624

The illustrative cost is 1 per false alarm and 4 per missed occupied reading. Those costs are choices for this example. This result describes validation data from one room. It does not establish performance in another room or show what a learner can build independently.

The versioned reference record includes the source and data hashes. The training source records the model, preprocessing and evaluation choices.

Training and validation in your browser

Run this maintainer-supplied example on the room recording. It fits a small model using temperature, light and CO₂, then compares it with the rule that calls a room occupied when its light reaches 100 lux. The code and choices are supplied. This demonstration is separate from your independent project.

First 1,200 readings
Fit the scaler and train the model.
Next 400 readings
Compare both policies on validation data.
Last 456 readings
Reserve for the project’s final test. This demo leaves them unused.

The scaler learns each feature’s mean and standard deviation from the training rows. It subtracts that mean and divides by that standard deviation for both training and validation inputs.

Training choices and source

This example uses one sigmoid unit, which produces a score between 0 and 1. Adam updates its weights with a learning rate of 0.01. Each batch contains up to 32 training rows, kept in their recorded order without shuffling.

Seed 17 fixes the starting weights. Binary cross-entropy measures the training error against the occupied or empty labels. These settings stay fixed while you choose the number of epochs.

Inspect the training and evaluation code and the recorded input data.

An epoch is one pass through the training rows. Choose how many passes to make. Each run starts a fresh model, with the same starting weights and a decision threshold of 0.5. More training does not guarantee a better result on later readings.

TensorFlow.js 4.22.0 and the data load when you run the example. Training uses your browser’s CPU. No installation is needed.

Ready to train the supplied example.

These are readings from one room. Nearby observations remain related, and these results do not establish performance in another building. Repeatedly inspecting validation results helps choose a model. It does not turn those readings into an independent final test. Model scores are not calibrated probabilities.

One validation reading where both policies were wrong

This supplied score comes from our recorded demonstration. Changing the threshold applies a decision rule to that score. It does not retrain the model or evaluate the rest of the data.

Temperature
23.7 °C
Light
271 lux
CO₂
814.3 ppm
Recorded label
Unoccupied
Supplied model score
0.656
Rule: light ≥ 100 lux
Occupied, incorrect on this row

At threshold 0.50, the model policy says occupied. It disagrees with the recorded label. The score stays 0.656.

A matching label here does not establish a useful threshold. Choose a policy using validation data and the costs of missed occupancy and false alarms. Keep the final test period separate. This score is not a calibrated probability.

About the recorded demonstration

The threshold example above comes from a maintainer integration fixture, recorded with TensorFlow.js 4.22.0 on its cpu backend. Five fixed training epochs checked the saved-model workflow. This is supplied demonstration work, separate from a learner's project.

The model and the light-threshold rule both classify this validation reading as occupied at the recorded settings. Its label says unoccupied. Their agreement does not establish correctness. One row also cannot establish either policy's overall quality.

You can inspect the exact reading, score, artifact hashes, fixture hash and reproduction commands in the recorded fixture. The recorded hashes identify the demonstration artifacts. The starter download contains no trained solution.

Read the reproduction runner, the fixture training code, and the preview builder in the versioned reproduction package. Its file manifest records the source hashes. The training file's hash matches the record above.

Download the standalone reproduction package and follow its reproduction instructions. It includes the supplied fixture and the tools to check it, with no main-repository checkout required. The learner starter remains a separate download without a trained solution.

Your work and the supplied tools

Responsibilities in the independent project
You createThe starter supplies
Feature choices, data periods, baseline and training experimentRecorded data, attribution and a training-file skeleton
Saved model, preprocessing parameters and evaluation runsExport/reload helpers and metric arithmetic
Error analysis and a recommendation about which policy to keepA local browser application that loads your result

Deep Orbit's lessons build the foundations for this work. Arrays and tensor shapes establish input meaning. Training and evaluation introduce fitted parameters, data splits and mistakes. The independent project asks you to make and explain your own choices.

Browser lessons need no local installation. The independent project requires Node.js 22 or later and an initial dependency download. After setup, its commands and application use local files. A completed project produces your model artifact, evaluation records, and a browser app that runs the saved result.

An honest evaluation

Fit preprocessing with training rows. Use validation data to choose model settings and thresholds. Freeze those choices before evaluating the final test period. If you change the policy after inspecting that period, it becomes development data and you need new data for an independent test.

Compare the rule and model on the same rows, inspect false positives and missed occupancy, and include your chosen error costs. Keeping the rule is a valid outcome when it serves the task better.

Automated checks can detect overlapping row IDs and recompute scores. They cannot prove that you avoided looking at the final period or that your reasoning is sound. That requires reviewing your code and explanation.

The project files and course entry

Deep Orbit's first five lessons are free, with no account needed. They introduce the data preparation that model work depends on. The full course continues through training, evaluation and deployment.

Start the first free lesson

The course overview and pricing describe the available course and paid continuation.