Client interface for twinLab machine-learning in the cloud.
Project description
twinLab Client
Interface to the twinlab library.
Installation for macOS
Requirements.
- Python 3.8 to 3.11 version installed and running for your current environment.
We recommend managing your Python packages with a virtual environment. See more here.
Installation
1. Enter a <project>
directory where you will be working on a twinlab project:
cd <project>
2. Install twinlab:
pip install twinlab
3. You must create a .env
file that contains your twinlab user credentials, including your API key.
For information on licensing, please contact us here.
In the following command, replace <your_api_key>
with your API key:
echo -e "TWINLAB_URL=https://twinlab.digilab.co.uk\nTWINLAB_API_KEY=<your_api_key>"> ~/.env
4. In Python
:
import twinlab as tl
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.8 to 3.11 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file twinlab-1.6.0.tar.gz
.
File metadata
- Download URL: twinlab-1.6.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 603e14f44527f8805472f83bb8aee93737b59c4b5d3556d361da4c8a987fc69f |
|
MD5 | ba8ed6728c089d1ab74c3aef78469834 |
|
BLAKE2b-256 | 894e8dcd090af0acb6074c5034c53ba2d270b892201ec0dd31f55b75b18f646f |
File details
Details for the file twinlab-1.6.0-py3-none-any.whl
.
File metadata
- Download URL: twinlab-1.6.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42c617d61eb1a02c314ceab25fab733a67aad116724fa273e9bb90c4e5192b8e |
|
MD5 | 082202f94b0a60613c2df3a5a3ec853c |
|
BLAKE2b-256 | d1ab3713553cd75768d7e8672b1d9e3e3e2e85ecbd8906a947392edf206c30d8 |