Skip to main content

Client interface for twinLab machine-learning in the cloud.

Project description

twinLab Client

digiLab slack

Headless interface to the twinLab library.

Installation for macOS

Requirements.

  • Python 3.9 to 3.11.9 version installed and running for your current environment.

We recommend managing your Python packages with Python virtual environments. See more here.

Installation

1. Open a terminal.

2. Define the folder/directory where you want to install twinlab. Then, set that folder/directory as your current one.

mkdir my_project
cd my_project

3. In your newly created directory, install twinlab on the terminal using pip3 install twinlab.

pip3 install twinlab

4. In order to import and use twinlab. There are two environment variables that must be set:

  • TWINLAB_API_KEY: This is a unique key that you need to authenticate with our servers.
  • TWINLAB_URL: This is the link to our server that you are authenticating with.

Currently, the way to set these variables is to create a .env file containing these variables. To do this, in the folder/directory that you have selected, create an .env file with your given API key. To do this use the following command on the terminal.

echo -e "TWINLAB_URL=https://twinlab.digilab.co.uk\nTWINLAB_API_KEY=[your_api_key]"> .env

Replace [your_api_key] with the API key given as a part of the license acquisition. (For information on licensing, please contact us here.). Be aware of any blank spaces in the words between the quotation marks!

To make sure you have created the document in your directory you can use the ls -a command on your terminal.

ls -a

As an output, you should see the .env file among your files.

. .env

Import and use

Now you are ready to import and start using twinlab. Open your favourite notebook or code editor, and select the folder/directory where you have installed twinlab and created the .env file.

Option A: using jupyter notebook through anaconda. Launch jupyter notebook inside the file/directory where you have installed twinlab and created the .env file.

Import twinlab and run the following example.

# Import pandas as well
import twinlab as tl
import pandas as pd

# Create a dataset and upload to twinLab cloud
df = pd.DataFrame({"X": [1, 2, 3, 4], "y": [1, 4, 9, 16]})
tl.upload_dataset(df, "test-data")

# Train a machine-learning model for the data
params = {
    "dataset_id": "test-data",
    "inputs": ["X"],
    "outputs": ["y"],
}
tl.train_campaign(params, campaign_id="test-model")

# Evaluate the model on some unseen data
df = pd.DataFrame({"X": [1.5, 2.5, 3.5]})
df_mean, df_std = tl.predict_campaign(df, campaign_id="test-model")

# Explore the results
print(df_mean)
print(df_std)

You should see the following results

>>> print(df_mean)
           y
0   2.173827
1   6.284010
2  12.788779
>>> print(df_std)
          y
0  2.483727
1  2.460696
2  2.483727

Option B: Using python through the terminal. Using the folder where we have installed twinlab and created the .env file, open python and import twinlab.

python
>>> import twinlab as tl

You should get a similar output with your credentials. For example:

{'username': 'yourname', 'credits': 0}

         === TwinLab Client Initialisation ===
         Version  : 1.4.0
         User     : yourname
         Server   : https://twinlab.digilab.co.uk
         Key      : your_api_key

Just to test twinlab, run the following example:

# Import pandas as well
import pandas as pd

# Create a dataset and upload to twinLab cloud
df = pd.DataFrame({"X": [1, 2, 3, 4], "y": [1, 4, 9, 16]})
tl.upload_dataset(df, "test-data")

# Train a machine-learning model for the data
params = {
    "dataset_id": "test-data",
    "inputs": ["X"],
    "outputs": ["y"],
}
tl.train_campaign(params, campaign_id="test-model")

# Evaluate the model on some unseen data
df = pd.DataFrame({"X": [1.5, 2.5, 3.5]})
df_mean, df_std = tl.predict_campaign(df, campaign_id="test-model")

# Explore the results
print(df_mean)
print(df_std)

You should see the following results:

>>> print(df_mean)
           y
0   2.173827
1   6.284010
2  12.788779
>>> print(df_std)
          y
0  2.483727
1  2.460696
2  2.483727

Installation for Windows

Requirements

  • Python 3.9 to 3.11.9 version installed and running for your current environment. (To download python visit https://www.python.org/downloads/)
  • Microsoft Visual C++ 14 or higher versions installed.

We recommend managing your Python packages with Python virtual environments. See more here.

Installation

1. Open a terminal.

2. Define the folder/directory where you want to install twinlab. Then, set that folder/directory as your current one.

mkdir my_project
cd my_project

3. In your newly created directory, install twinlab on the terminal using pip3 install twinlab.

pip3 install twinlab

4. Still in the folder/directory that you have selected, create an .env file with your given API key. To do this use the following command on the terminal.

echo TWINLAB_URL=https://twinlab.digilab.co.uk > .env && echo TWINLAB_API_KEY=[your_api_key]>> .env && echo TWINLAB_SERVER=https://twinlab.digilab.co.uk >> .env && echo TWINLAB_KEY=[your_api_key]>> .env

Replace [your_api_key] with the API key given as a part of the license acquisition. Notice that you have to replace it twice! (For information on licensing, please contact us here.)

Be aware of any blank spaces in the words between the quotation marks!

To make sure you have created the document in your directory you can use the dir /a command on your terminal.

dir /a

As an output, you should see the .env file among your files.

. .env

Import and use

Now you are ready to import and start using twinlab. Open your favourite notebook or code, editor and select the folder/directory where you have installed twinlab and created the .env file.

Option A: using jupyter notebook through anaconda. Launch jupyter notebook inside the file/directory where you have installed twinlab and created the .env file.

Import twinlab and run the following example:

# Import pandas as well
import twinlab as tl
import pandas as pd

# Create a dataset and upload to twinLab cloud
df = pd.DataFrame({"X": [1, 2, 3, 4], "y": [1, 4, 9, 16]})
tl.upload_dataset(df, "test-data")

# Train a machine-learning model for the data
params = {
    "dataset_id": "test-data",
    "inputs": ["X"],
    "outputs": ["y"],
}
tl.train_campaign(params, campaign_id="test-model")

# Evaluate the model on some unseen data
df = pd.DataFrame({"X": [1.5, 2.5, 3.5]})
df_mean, df_std = tl.predict_campaign(df, campaign_id="test-model")

# Explore the results
print(df_mean)
print(df_std)

You should see the following results.

>>> print(df_mean)
           y
0   2.173827
1   6.284010
2  12.788779
>>> print(df_std)
          y
0  2.483727
1  2.460696
2  2.483727

Option B: Using python through the terminal. Using the folder where we have installed twinlab and created the .env file, open python and import twinlab.

python
>>> import twinlab as tl

You should get a similar output with your credentials. For example:

{'username': 'yourname', 'credits': 0}

         === TwinLab Client Initialisation ===
         Version  : 1.4.0
         User     : yourname
         Server   : https://twinlab.digilab.co.uk
         Key      : your_api_key

Just to test twinlab, run the following example:

# Import pandas as well
import pandas as pd

# Create a dataset and upload to twinLab cloud
df = pd.DataFrame({"X": [1, 2, 3, 4], "y": [1, 4, 9, 16]})
tl.upload_dataset(df, "test-data")

# Train a machine-learning model for the data
params = {
    "dataset_id": "test-data",
    "inputs": ["X"],
    "outputs": ["y"],
}
tl.train_campaign(params, campaign_id="test-model")

# Evaluate the model on some unseen data
df = pd.DataFrame({"X": [1.5, 2.5, 3.5]})
df_mean, df_std = tl.predict_campaign(df, campaign_id="test-model")

# Explore the results
print(df_mean)
print(df_std)

You should see the following results:

>>> print(df_mean)
           y
0   2.173827
1   6.284010
2  12.788779
>>> print(df_std)
          y
0  2.483727
1  2.460696
2  2.483727

Having Problems?

If you have any questions or concerns you can email us at twinlab@digilab.co.uk or find out more at digilab.co.uk/products/twinlab.

Documentation

See the live documentation at https://digilab-ai.github.io/twinLab-client/. Or build a copy locally:

cd docs
yarn install && yarn start

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twinlab-1.5.0.tar.gz (14.7 kB view hashes)

Uploaded Source

Built Distribution

twinlab-1.5.0-py3-none-any.whl (14.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page