These are some examples on how to use the API to perform typical workflows within Butterfly AI. See also API overview or full API reference for more details on the API.


Auth and smoke test

  • Login to obtain a token
  • List datasets to test out access

Create a Dataset

  • First, create an empty dataset
  • Then, add CSV data to the created dataset
  • Lastly, poll for progress until COMPLETED

Key values to note for next stages:

  • The datasetKey uniquely identifies the dataset
  • The datasetName is a descriptive name to distinguish it from others or versions of of the same underlying data
  • The numberOfBuckets is key hyperparameter that determines how data is shaped for training

Train a Model

Once the dataset is created and in COMPLETED state, training can be executed with the following commands and endpoints.

  • Target 0.99 performance
  • Pass 19 as the scaling factor

As it can be observed in the output, there are 4 algorithms (wrapped into trainingJobs) and one overall status for whole training process launched.

  • The job/algorithm with the highest achieved performance will be the winner (first getting to COMPLETED status)
  • When a job doesn’t reach the target performance in the timeout time (1h currently), it’s marked with TIMEOUT status
  • When a job doesn’t progress at least 0.02 for a given period (5 minutes) it’s stopped and marked as NOT_COMPLETED (stalled)
  • When a job has an irrecoverable failure is marked as FAILED and stopped
  • The overall process stops only when all jobs are out of PROCESSING (either COMPLETED, NOT_COMPLETED, TIMEOUT or FAILED). As long as 1 job completes successfully, the overall process is COMPLETED
  • A champion model is created from the successful training, marking it as the best performing model so far for the dataset. If training is repeated with different hyperparameters (performance threshold, scaling factor or the dataset recreated with different number of buckets) and better performance is achieved, the champion model is overriden with the best one

The completed process response from progress monitoring endpoint looks like this:

  {
    "status": "COMPLETED",
    "jobs": [
        {
            "trainingJobKey": "23de1e06-a126-4719-90a8-8874d9f63a92",
            "algorithm": "BSEV02",
            "status": "COMPLETED",
            "latestPerformance": 0.9000122,
            "recentPerformances": [
                0.8674287,
                0.89866984,
                0.89997154,
                0.89997154,
                0.9000122
            ]
        },
        {
            "trainingJobKey": "54af946f-1f89-4560-99ef-f4934bfab237",
            "algorithm": "BSEV01",
            "status": "NOT_COMPLETED",
            "latestPerformance": 0.6260017,
            "recentPerformances": [
                0.6260017,
                0.625961,
                0.6260017,
                0.625961,
                0.6260017
            ]
        },
        {
            "trainingJobKey": "c46820a8-f5fc-49ab-aa34-bdf71186eff1",
            "algorithm": "BFIF01",
            "status": "NOT_COMPLETED",
            "latestPerformance": 0.7718656,
            "recentPerformances": [
                0.7715808,
                0.7716215,
                0.77174354,
                0.77178425,
                0.7718656
            ]
        },
        {
            "trainingJobKey": "ea4bd529-e886-4167-b800-8a97a147396b",
            "algorithm": "BSIX01",
            "status": "NOT_COMPLETED",
            "latestPerformance": 0.87388635,
            "recentPerformances": [
                0.87388635,
                0.87388635,
                0.87388635,
                0.87388635,
                0.87388635
            ]
        }
    ]
}
  

The winner is BSEV02, the latest performance is 0.90000, the training detail shows the created model and further training performance details:

The model with modelKey=8a86bd31-ff0c-47c1-bdb8-d08331904508 can then be used to run predictions on unseen data.

Run Predictions

After getting the desired _champion model_trained, it’s time to run predictions with it. Before running a prediction we should check the modelKey returned is there with the desired performance:

Then, create a prediction using this model. Remember that, as of now, the blind CSV file to run prediction on must not be more than 32MB in size:

Poll the url for progress on the prediction result:

Once the status moves to COMPLETED, the result CSV can be downloaded:

Hyperparameter Tuning

Hyperparameter tuning is done by combining the above endpoints in order to incrementally obtain better performance by changing the hyper-parameters:

  • Create new versions of dataset with increased/decreased number of buckets
  • Re-train using the training endpoints and progress monitoring observation with more or less scaling factor until the result is COMPLETED successfully
  • Gradually increase or reduce the performance threshold until no more improvements are visible while obtaining COMPLETED results