twinlab.sample_campaign#

twinlab.sample_campaign(filepath_or_df, campaign_id, num_samples, processor='cpu', verbose=False, debug=False, **kwargs)[source]#

Sample campaign

Draw samples from a pre-trained campaign that exists on the twinLab cloud.

Parameters:
  • filepath_or_df (str) – Location of .csv dataset on local machine for evaluation

  • campaign_id (str) – Name of pre-trained campaign to use for predictions.

  • num_samples (int) – Number of samples to draw for each row of the evaluation data.

  • verbose (bool, optional) – Optional. Determining level of information returned to the user.

Returns:

with the sampled values

Return type:

pandas.DataFrame

Examples

Using a local file:

import pandas as pd
import twinlab as tl

df = pd.DataFrame({'X': [1, 2, 3, 4], 'y': [1, 4, 9, 16]})
tl.upload_dataset(df, "my_dataset")
params = {
    "dataset_id": "my_dataset",
    "inputs": ["X"],
    "outputs": ["y"],
}
tl.train_campaign(params, "my_campaign")
filepath = "path/to/data.csv" # Local
n = 10
df_mean, df_std = tl.sample_campaign(filepath, "my_campaign", n)
print(df_mean)
print(df_std)

Using a pandas.DataFrame:

import pandas as pd
import twinlab as tl

df = pd.DataFrame({'X': [1, 2, 3, 4], 'y': [1, 4, 9, 16]})
tl.upload_dataset(df, "my_dataset")
params = {
    "dataset_id": "my_dataset",
    "inputs": ["X"],
    "outputs": ["y"],
}
tl.train_campaign(params, "my_campaign")
df = pd.DataFrame({'X': [1.5, 2.5, 3.5]})
n = 10
tl.sample_campaign(df, "my_campaign", n)

Deprecated since version 2.5.0: The twinLab Python client version v1 will be deprecated imminently. Please upgrade to the latest version of the twinLab Python client. Avaible at https://pypi.org/project/twinlab/.