---
title: "Double Moons - Machine Learning Example"
url: "https://help.dectris.cloud/en/article/double-moons-machine-learning-example"
language: "en"
last_updated: "2026-07-15T08:54:29.719Z"
---

# Double Moons - Machine Learning Example

Moons Machine Learning Demo on DECTRIS D.LAB

[Embedded content](https://www.youtube.com/embed/869CEKlcr0g)

## Overview

This demo lets you **train a machine learning model** on the *“two moons”* dataset and then **evaluate four points of your choice** against the model.

It runs in two stages:

`**train_moons.py**`

-   Generates the two-moons dataset.
-   Trains an SVM (support vector machine) classifier.
-   Prints accuracy, saves the trained model and metadata.

`**interactive_moons.py**`

-   Loads the trained model.
-   Classifies four points (A, B, C, D) that you choose.
-   Prints predictions and probabilities.
-   Saves a TXT report and a PNG plot with the decision regions and your chosen points.

Both scripts are already packaged in the DECTRIS D.LAB job template. You don’t have to run them manually.

* * *

## How to Use in DECTRIS CLOUD

**Start the Job Template**

Select the *“Moons Machine Learning Demo”* template in DECTRIS D.LAB.

This template automatically runs `train_moons.py` with reasonable defaults.

**Choose Your 4 Points**

The template will prompt you for four coordinates:

**Point A** (`--point-a`)

**Point B** (`--point-b`)

**Point C** (`--point-c`)

**Point D** (`--point-d`)

Enter each point as `x,y` (for example: `0.5,0.0` or `-0.2,0.8`).

Parentheses are not required. Negative values and zeros are valid (e.g. `-1.0,0` or `0,0`).

**Run the Job**

Submit the job; DECTRIS D.LAB takes care of training and evaluation.

When it finishes, check the **outputs**.

* * *

## Outputs

The job produces:

`**moons_model.joblib**`  
The trained model + metadata.

`**0results.txt**`  
A text file listing your points, predicted classes, and probabilities.

`**0results.png**`  
A plot of the decision regions, training data, and your four points (shown as big red stars with bold labels).

* * *

## Example

Suppose you choose these four points:

`Point A: 0.5,0.0 Point B: 1.0,-0.5 Point C: -0.2,0.8 Point D: 0,0` 

Your output will contain lines like:

`Point A (0.500, 0.000) → class 1 (p0=0.123, p1=0.877) Point B (1.000,-0.500) → class 0 (p0=0.654, p1=0.346) ...`

And the plot will show:

The **two moons** background (colored decision regions).

Your **4 points** marked in **red stars** with **bold labels**.

* * *

## Tips

If you leave a point blank, the script falls back to a default.

Negative values (like `-0.5,0.2`) and zeros (`0,0`) are fully supported.

For reproducibility, the training step always uses the same random seed unless you change it.
