🔮Predictions

These methods are necessary in order to use some of the endpoints in this section.

  • to obtain a valid token use the following method: Authentication

  • To get the id of your projects you must go to the following method: List projects.

  • To get the models of your project you must go to the following method: Project information.


List Inputs for prediction:

GET https://api.arkangel.ai/api/experiments/io/project/{{PROJECT_ID}}/model/{{MODEL_ID}}

Path Parameters

NameTypeDescription

{{MODEL_ID}}*

UUID

Model ID

{{PROJECT_ID}}*

UUID

Project ID

Headers

NameTypeDescription

TOKEN*

JWT

Bearer TOKEN

{
    "status": 200,
    "result": {
        "id": "45a129d6-f421-44c2-8950-cde9fe82bffg",
        "status": "done",
        "createdAt": "2023-04-19T16:15:00.216Z",
        "updatedAt": "2023-04-19T16:15:00.216Z",
        "experimentsIO": [
            {
                "id": "5b255639-d3a8-418f-824d-92cc4627e690",
                "io": true,
                "alias": null,
                "description": null,
                "name": "id",
                "dataType": "number_int",
                "range": [
                    "3",
                    "399"
                ],
                "createdAt": "2023-04-19T17:12:24.992Z",
                "updatedAt": "2023-04-19T17:12:24.992Z"
            },
            {
                "id": "bc4bc70a-a558-47d5-bcfb-9c3e46322e24",
                "io": true,
                "alias": null,
                "description": null,
                "name": "rc",
                "dataType": "number_float",
                "range": [
                    "2.1",
                    "8"
                ],
                "createdAt": "2023-04-19T17:12:25.003Z",
                "updatedAt": "2023-04-19T17:12:25.003Z"
            },
            {
                "id": "ddc1868a-2c0c-44fb-abb2-47b1c75dbd92",
                "io": true,
                "alias": null,
                "description": null,
                "name": "rbc",
                "dataType": "categorical",
                "range": [
                    "normal",
                    "abnormal"
                ],
                "createdAt": "2023-04-19T17:12:25.003Z",
                "updatedAt": "2023-04-19T17:12:25.003Z"
            }
        ]
    }
}

Example request

import requests

url = "https://apidev.arkangel.ai/api/experiments/io/project/{{PROJECT_ID}}/model/{{MODEL_ID}}"

payload = ""
headers = {
  'Authorization': 'Bearer {{TOKEN}}'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

Create public user:

This is important if you want to make inferences on projects that are enabled as public with users not registered in the app. If an already created email is sent, it will return the existing one.

POST https://api.arkangel.ai/api/public-users

The body must be in JSON format

Request Body

NameTypeDescription

email*

String

user email

{
    "status": 201,
    "result": {
        "id": "6cc146ed-ecd5-4ba9-9547-51a453fc826c",
        "email": "example_email@arkangel.ai",
        "createdAt": "2024-05-17T18:43:07.560Z",
        "updatedAt": "2024-05-17T18:43:07.560Z"
    }
}

Example request

import requests
import json

url = "https://apidev.arkangel.ai/api/public-users"

payload = json.dumps({
  "email": "example_email@arkangel.ai"
})
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Create prediction:

Create a prediction

POST https://api.arkangel.ai/api/inference

The body must be in JSON format

Headers

NameTypeDescription

TOKEN*

JWT

Bearer TOKEN (Not necessary if an inference is to be made with a public user)

If the project is public, you can make inferences without sending the token, but you must create a public user and send the id of the created user.

Request Body

NameTypeDescription

projectId*

UUID

PROJECT_ID

modelId*

UUID

MODEL_ID

inputs*

Array<Inputs>

clientId

String

Name of inference (Not necessary if an inference is to be made with a public user)

publicUserId

UUID

PUBLIC_USER_ID

If you want to make an inference without providing the token, the publicUserId property is required.

{
    "id": "8ee23c6a-441e-4d8c-9110-3ab2fefc6b79",
    "comment": null,
    "annotated": null,
    "clientId": null,
    "startInference": "2023-08-31T15:19:46.000Z",
    "endInference": "2023-08-31T15:19:52.000Z",
    "inputs": [
        {
            "name": "rc",
            "value": "4.2",
            "inferenceInputId": "b6c12361-d462-4be9-846f-ca73d8f7ffbf"
        },
        {
            "name": "rbc",
            "value": "normal",
            "inferenceInputId": "463b4eb4-d892-46f3-9c09-aa86d8a2eb20"
        },
        {
            "name": "pc",
            "value": "abnormal",
            "inferenceInputId": "b2100bc0-2e50-4efa-926a-6dc5979098cf"
        }
    ],
    "labels": [
        {
            "id": "fbe86179-c98c-493c-a8ec-b7f21d7f3b3f",
            "name": "classification",
            "classes": [
                {
                    "explainabilities": [
                        {
                            "id": "0c463083-23a1-4748-a30c-f8abea40bffc",
                            "inferenceInputId": "b6c12361-d462-4be9-846f-ca73d8f7ffbf",
                            "value": "0.1166613112549300"
                        },
                        {
                            "id": "96d46890-8d98-41f9-a17a-35162ea91d62",
                            "inferenceInputId": "463b4eb4-d892-46f3-9c09-aa86d8a2eb20",
                            "value": "0.2366151378308200"
                        },
                        {
                            "id": "33a30934-b45c-4fa3-88ed-3469387e8287",
                            "inferenceInputId": "b2100bc0-2e50-4efa-926a-6dc5979098cf",
                            "value": "0.0025483931053800"
                        }
                    ],
                    "result": "0.72316533327103",
                    "labelStr": "ckd"
                },
                {
                    "explainabilities": [
                        {
                            "id": "c4a91a27-5f58-497c-b3be-cdfb531da359",
                            "inferenceInputId": "b6c12361-d462-4be9-846f-ca73d8f7ffbf",
                            "value": "0.0555980612992000"
                        },
                        {
                            "id": "01ee0681-7fb7-45c2-b322-59d1302baa6d",
                            "inferenceInputId": "463b4eb4-d892-46f3-9c09-aa86d8a2eb20",
                            "value": "-0.2253670386386000"
                        },
                        {
                            "id": "148935bc-a4ad-43e0-9bb0-9cd0473f8368",
                            "inferenceInputId": "b2100bc0-2e50-4efa-926a-6dc5979098cf",
                            "value": "-0.1166613119150600"
                        }
                    ],
                    "result": "0.27683460712433",
                    "labelStr": "notckd"
                }
            ]
        }
    ],
    "annotations": []
}

Example request for tabulated classification data:

import requests
import json

url = "https://api.arkangel.ai//api/inference"

predict_dic = {}
predict_dic['projectId'] = "{{PROJECT_ID}}"
predict_dic['modelId'] = "{{MODEL_ID}}"
# The number of inputs are given by the number of columns or variables
# used to train the experiment.
# Value can be any number, or if the column is categorical, variable
# must be a string that the experiment has already seen.
# For example:
# the experiment has been trained with the inputs ['red','green','blue']
# then value must be 'red', 'green', or 'blue' it can not be 'yellow'
predict_dic['inputs'] =[
    {
      "id": "870fc9cb-6c8e-4d7c-9e75-11631a67a137",
      "input": 2015
    },
    {
      "id": "27a9d20a-9c89-42b6-a91c-99ab1c315850",
      "name": "AdultMortality",
      "input": 263
    }
  ]

# Transform dictionary to json response
payload = json.dumps(predict_dic, indent=4)

headers = {
  'Authorization': 'Bearer {{TOKEN}}',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Example request for image data classification

import requests
import json


# For this method it is not necessary to use List Inputs method
# It automatically obtains the image ID since only one is needed.
url = "https://api.arkangel.ai/api/experiments/io/{{MODEL_ID}}"

payload = ""
headers = {
  'Authorization': 'Bearer {{TOKEN}}'
}

img_id = requests.request("GET", url, headers=headers, data=payload)
img_id = json.loads(img_id.text)
img_id["result"]["experimentsIO"][0]["id"]

url = "https://api.arkangel.ai/api/inference"

# The image that is going to be used for the prediction must 
# Be in base 64 format
payload = json.dumps({
  "userId": "{{USER_ID}}",
  "projectId": "{{PROJECT_ID}}",
  "modelId": "{{MODEL_ID}}",
  "inputs": [
    {
      "id": img_index,
      "input": "{{IMAGE_TRANSFORMED_INTO_BASE64}}"
    }
  ]
})
headers = {
  'Authorization': 'Bearer {{TOKEN}}',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Create multiple predictions:

POST https://api.arkangel.ai/api/inference/batch

This method will allow you to make more than one prediction at a time, you will have to send a .csv file, it will respond with an equal file, which contains the errors of the predictions if it found any error, if the file is empty no inferences with typing errors or similar were found. The correct predictions will be made and when they are complete, the file with the results will be sent to the email, and the results can also be obtained through the endpoint of list predictions.

Headers

NameTypeDescription

TOKEN*

JWT

Bearer TOKEN

Request Body

NameTypeDescription

modelIds*

Array

[ MODEL_IDS ]

projectId*

String

PROJECT_ID

batch*

File

This will be the .csv containing the predictions

{
    "status": 201,
    "result": "Multi-inference started"
}

Example of use for example_file.csv

clientId27a9d20a-9c89-42b69c89-42b6-27a9d20a42b6-27a9d20a-9c89

Name

Year

Age

Example 1

Carlos

1999

23

Example 2

Marina

1995

27

The CSV file should have a maximum of 50.000 cells.

Example request

import requests

url = "https://apidev.arkangel.ai/api/inference/batch"

payload = {
  'projectId': '{{PROJECT_ID}}',
  'modelIds': [ '{{MODEL_ID}}' ]
}
files=[
  ('batch',('example_file.csv', open('/home/user/Downloads/example_file.csv','rb'), 'text/csv'))
]
headers = {
  'Authorization': 'Bearer {{TOKEN}}'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

List predictions:

List a predictions

GET https://api.arkangel.ai/api/inference/project/{{PROJECT_ID}}/model/{{MODEL_ID}}

Path Parameters

NameTypeDescription

{{PROJECT_ID}}*

UUID

Project ID

{{MODEL_ID}}*

UUID

Model ID

Query Parameters

NameTypeDescription

limit*

int

{{LIMIT}}

offset*

int

{{OFFSET}}

{
    "total": 3,
    "data": [
        {
            "id": "8ee23c6a-881e-4d8c-9110-3ab2fefc6b88",
            "prediction": "ckd",
            "result": "0.72316533327103",
            "modelId": "c3c7ca91-c3f1-4982-a54c-25253ab36c78",
            "comment": null,
            "clientId": null,
            "createdAt": "2023-08-31T15:19:52.151Z",
            "updatedAt": "2023-08-31T15:19:52.151Z"
        },
        {
            "id": "113d2c1f-79fe-4665-b02e-4313e1b9c896",
            "prediction": "ckd",
            "result": "0.75037169456482",
            "modelId": "c3c7ca91-c3f1-4982-a54c-25253ab36c78",
            "comment": null,
            "clientId": null,
            "createdAt": "2023-08-29T16:12:48.223Z",
            "updatedAt": "2023-08-29T16:12:48.223Z"
        },
        {
            "id": "5bd0dac0-61c3-46a3-b5eb-f1aeb484cb35",
            "prediction": "notckd",
            "result": "0.67639052867889",
            "modelId": "c3c7ca91-c3f1-4982-a54c-25253ab36c78",
            "comment": null,
            "clientId": null,
            "createdAt": "2023-05-17T20:47:57.489Z",
            "updatedAt": "2023-05-17T20:47:57.489Z"
        }
    ]
}

Example request

import requests

# Replace this with the corresponding information
PROJECT_ID = '{{PROJECT_ID}}'
MODEL_ID = '{{MODEL_ID}}'
LIMIT = '{{LIMIT}}'
OFFSET = '{{OFFSET}}'

url = f"https://api.arkangel.ai/api/inference/project/{PROJECT_ID}/model/{MODEL_ID}?limit={LIMIT}&offset={OFFSET}"

payload={}
# Obtain user's web token
headers = {
  'Authorization': 'Bearer {{TOKEN}}'
}

# Configure the information created before of the project and obtain response
response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

List Prediction:

GET https://api.arkangel.ai/api/inference/{{INFERENCE_ID}}

Path Parameters

NameTypeDescription

Inference Id*

UUID

{{INFERENCE_ID}}

{
    "status": 200,
    "result": {
        "id": "{{INFERENCE_ID}}",
        "startInference": "2022-10-12T22:53:02.000Z",
        "endInference": "2022-10-12T22:53:05.000Z",
        "inputs": [
            {
                "name": "BMI",
                "value": "16.6",
                "inferenceInputId": "ca7581c2-5bc0-42de-9ee1-b9550f78cace"
            },
            {
                "name": "Smoking",
                "value": "1",
                "inferenceInputId": "605f426d-dde2-4e40-903c-b1a905ab4d30"
            }
        ],
        "labels": [
            {
                "id": "870fcf8e-07d7-4932-9528-220a144bbe2b",
                "name": "Target",
                "classes": [
                    {
                        "explainabilities": [
                            {
                                "id": "8201cc2a-8f93-4f16-90eb-a1bff5058208",
                                "inferenceInputId": "ca7581c2-5bc0-42de-9ee1-b9550f78cace",
                                "value": "0.0104488377621390"
                            },
                            {
                                "id": "a6c01a95-08c2-4e78-aeeb-54294807a9d6",
                                "inferenceInputId": "605f426d-dde2-4e40-903c-b1a905ab4d30",
                                "value": "0.0052993741086582"
                            }

                           
                        ],
                        "result": "0.00000000001003",
                        "labelStr": "Yes"
                    },
                    {
                        "explainabilities": [
                            {
                                "id": "a7035d95-b7f2-42c9-b659-0d51d340829b",
                                "inferenceInputId": "ca7581c2-5bc0-42de-9ee1-b9550f78cace",
                                "value": "-0.0107978574070894"
                            },
                            {
                                "id": "8032c322-7be6-48d1-a7ba-888db1c0c51f",
                                "inferenceInputId": "605f426d-dde2-4e40-903c-b1a905ab4d30",
                                "value": "-0.0053141740812033"
                            }      
                        ],
                        "result": "1.00000000000000",
                        "labelStr": "No"
                    }
                ]
            }
        ]
    }
}

Example request

import requests

# Replace this with the inference ID
INFERENCE_ID= '{{INFERENCE_ID}}'
url = "https://api.arkangel.ai/api/inference/{{INFERENCE_ID}}"

payload={}
# Obtain user's web token
headers = {
  'Authorization': 'Bearer {{TOKEN}}'
}

# Configure the information created before of the project and obtain response
response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

List Targets of the model:

GET https://api.arkangel.ai/api/models/{{MODEL_ID}}/labels

Path Parameters

NameTypeDescription

MODEL_ID*

UUID

{{MODEL_ID}}

{
    "status": 200,
    "result": [
        {
            "id": "UUID",
            "nameStr": "target name",
            "createdAt": "2023-02-24T17:50:31.614Z",
            "updatedAt": "2023-02-24T17:50:31.614Z",
            "classes": []
        }
    ]
}

Example request

import requests

# Replace this with the model ID
MODEL_ID= '{{MODEL_ID}}'
url = "https://api.arkangel.ai/api/models/{{MODEL_ID}}/labels"

payload={}
# Obtain user's web token
headers = {
  'Authorization': 'Bearer {{TOKEN}}'
}

# Configure the information created before of the project and obtain response
response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

Annotate prediction:

GET https://api.arkangel.ai/api/inference/annotations

Request Body

NameTypeDescription

inferenceId*

UUID

INFERENCE_ID

annotations*

Array<object>

Annotations by Target - Objects for each Target of the project

annotated*

Boolean

Type of annotation - true: valid annotation | false: invalid annotation

{
    "status": 200,
    "result": {
        "annotated": false,
        "annotations" : [
            {
               "labelId": "UUID",
               "labelStr": "Label of the target",
               "annotated": "value of the annotation",
               "createdAt": "2023-03-27T15:29:30.088Z",
               "updatedAt": "2023-03-27T15:29:30.088Z"
            }
        ],
        "clientId": "",
        "comment": "",
        "endInference": "2023-03-27T15:29:24.000Z",
        "id": "INFERENCE_ID",
        "inputs": [],
        "labels": [],
        "startInference": "2023-03-27T15:29:22.000Z"
    }
}

Example request

import requests

# Replace this with the inference ID
INFERENCE_ID= '{{INFERENCE_ID}}'
url = "https://apidev.arkangel.ai/api/inference/annotations"

payload={
  'inferenceId': INFERENCE_ID,
  "annotated" : true | false,
  # Objects for each Target of the project
  # This field is only sent if the property "annotated" is true
  'annotations': [
    # Example if the project is of type Classification
    {
        "labelId": "TARGET_ID",
        "classId": "CLASS_ID"
    },
    # Example if the project is of type Regression
    {
        "labelId": "TARGET_ID",
        "result": "Number value"
    }
  ]
}
# Obtain user's web token
headers = {
  'Authorization': 'Bearer {{TOKEN}}'
}

# Configure the information created before of the project and obtain response
response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Last updated