---
title: Machine Learning on LE via Jupyter
slug: solutions/machine-learning-on-le-via-jupyter
docTags: 
createdAt: 2023-08-01T12:19:10.237Z
---

## Overview

This solution describes how to run a machine learning application using Jupyter on Litmus Edge. After deploying the container, you will be able to log in to a Jupyter
notebook environment running on your LitmusEdge device and use the bundled example notebooks for classification, anomaly detection, and prediction.

![](https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/hmUO88KAvsdUVNw5OLHBU_functiondiagramsolutions-ml-jypiterdrawio.png)

## Prerequisites

- A running Litmus Edge instance with administrative access.
- The Jupyter ML toolkit image (`.tar.gz`) provided by Litmus.
- Network access to the Litmus Edge IP from the machine you will browse from.
- SSH access to the Litmus Edge host (used once to retrieve the Jupyter login token).

## Step 1: Download and prepare the image

Obtain the Jupyter ML toolkit `.tar.gz` file from the Litmus repository or release artifact provided to you.

## Step 2: Upload the image to Litmus Edge

1. Log in to your Litmus Edge instance.
2. Navigate to **Applications > Images**.
3. Upload the `.tar.gz` file downloaded in Step 1.

Wait for the upload to complete and confirm that the image appears in the list of available images.

## Step 3: Configure and run the container

1. Navigate to **Applications > Containers**.
2. Create a new container using the image uploaded in Step 2.
3. Use the following `docker run` command:

```bash
docker run -p 8888:8888 \
  -v /var/lib/loopedge/analytics2/models/:/home/loopedge/work/notes/savedmodels \                                                                                          
  <imgname>:<tagname>   
```

This command:

- Exposes the Jupyter application on port `8888`.
- Mounts the LitmusEdge analytics `models` folder into the container at `/home/loopedge/work/notes/savedmodels`, so any models saved from a notebook are immediately available to the Analytics engine.

:::BlockQuote
**Tip:** If you want to skip the token lookup in Step 5, you can pre-set a token now by adding `-e JUPYTER_TOKEN=<your-chosen-token>` to the command above.
:::

## Step 4: Open the Jupyter application in a browser

In a new browser tab, navigate to your Litmus Edge IP address followed by port `8888`:

`http://<le-ip>:8888`

For example, if your Litmus Edge instance is at `10.17.10.27`, open:

`http://10.17.10.27:8888`

You will be redirected to the Jupyter login page, which prompts for a **Password or token**.

## Step 5: Log in to Jupyter

### 5.1 Retrieve the access token

The Jupyter container generates a one-time token at startup. To retrieve it:

1. SSH into the Litmus Edge host.
2. Find the running Jupyter container:

```bash
docker ps | grep jupyter
```

3. Read the token from the container logs:

```bash
docker logs <container-name> 2>&1 | grep -oE 'token=[a-f0-9]+' | head -1
```

You will see output similar to:

```javascript
token=8968cc8cf0480ed3b2b52c25fed0eb527f7ea2fc888b4ea
```

4. Copy the value after `token=`.

:::BlockQuote
If you set `JUPYTER_TOKEN` in the `docker run` command in Step 3, skip the lookup above and use the value you set.
:::

### 5.2 Log in using one of two options

**Option A: Log in with the token (one-time)**

Paste the token into the **Password or token** field at the top of the login page and click **Log in**.

**Option B: Set a permanent password (recommended)**

On the same login page, scroll down to the **Setup a Password** section:

1. Paste the token into the **Token** field.
2. Enter your chosen password in the **New Password** field.
3. Click **Log in and set new password**.

You will be logged in and the password will be saved for future sessions, so you no longer need to look up the token.

:::BlockQuote
**Note:** The login page contains links labeled *"enable a password"* and *"the documentation on how to enable a password"*. These links point to legacy Jupyter documentation that has been removed and will return a 404. Use the **Setup a Password** form on the same page (Option B above) instead.
:::

## Step 6: Use the bundled notebooks

Once logged in, you will see the Jupyter file browser. The following example notebooks are included under `/home/loopedge/work/notes/`:

- `natsConnection.ipynb` - Example of connecting to the LitmusEdge NATS broker.
- `influxConnection.ipynb` - Example of querying InfluxDB on LitmusEdge.
- `classification.ipynb` - Example classification model.
- `anomaly.ipynb` - Example anomaly detection model.
- `prediction.ipynb` - Example prediction model.
- `template_prediction.ipynb` - Template you can copy as a starting point for new prediction models.

Models saved into `/home/loopedge/work/notes/savedmodels` from any notebook will appear automatically in the LitmusEdge analytics engine, thanks to the volume mount
configured in Step 3.

## Troubleshooting

**The "enable a password" or "the documentation on how to enable a password" links on the Jupyter login page return a 404.**
This is a known issue with the upstream Jupyter login template, which references documentation URLs that have since moved. Use the **Setup a Password** form on the same
login page (see Step 5.2, Option B) to set a password without needing the linked documentation.

`docker logs`**&#x20;does not show a token.**
The container may have been started with `JUPYTER_TOKEN` set to an empty value, or with token authentication disabled. Restart the container without overriding
`JUPYTER_TOKEN`, or set it explicitly using `-e JUPYTER_TOKEN=<your-chosen-token>` in the `docker run` command from Step 3.

**Browser cannot reach&#x20;**`<le-ip>:8888`**.**
Verify that port `8888` is published in the container configuration in Step 3, that the LitmusEdge firewall allows inbound traffic on `8888`, and that your browser machine
has network access to the LitmusEdge IP.

