Python Guide

Getting Started

Signup for an account

Go to Terrene's portal, and sign-up for a new user account. After signing up, activate your account by adding a payment method to your account.

Install Terrene's Python SDK

To install from Pypy, run the following command

pip install terrene

Authorize the Python SDK

Use the email and password you used to create an account on Terrene, to create a credentials object that can be used to authenticate your requests to the API.

from terrene.auth import EmailPasswordCredentials

credentials = EmailPasswordCredentials(
    email="<email address>", password="<password>")

Create a workspace

Workspaces are the primary way of managing subscriptions and access levels on Terrene. To create a new workspace, do the following:

from terrene.apps import WorkspaceManager

workspace_manager = WorkspaceManager(credentials=credentials)
workspace = workspace_manager.create(
    name="My Workspace", description="A workspace for Terrene's tutorial")

Note: call workspace_manager.create(...) only once, if you call it multiple times, you'll end up with multiple workspaces with the same name and description.

Upload the training dataset

Load your CSV dataset using Python's open method, then use Terrene's SDK to upload it.

with open('/path/to/file.csv', 'r') as input_file:
    csv_file_input = workspace.csv_input_manager.create(
        name="my file", description="training dataset",

Create a predictive Model

Create the model

Change the values of input_variables and output_variables with the name of the columns you want as your input and your output columns. These names should correspond to the name of the columns you uploaded earlier.

model = workspace.predictive_model_manager.create(
    name="my predictive model", description="predictive model",
    input_variables="col1, col2, col3, col4", output_variables="col5")

Train the model

You can change the value of the epochs to control how many training cycles the model goes through. The higher the epochs, the more time the training time will take and the more accurate the training will be.

model.train(transfer=csv_file_input, epochs=100)

Create REST endpoints to the model

endpoint = workspace.model_endpoint_manager.create(
    enrich=model, name="my endpoint", description="used to make predictions")

Make predictions

To make predictions, call the predict method on the ednpoint:

prediction = endpoint.predict({"col1": 0, "col2": 0, "col3": 0, "col4": 0})

Create a data warehouse

Create a data warehouse to store your model predictions.

store = workspace.standard_warehouse_manager.create(
    name="default storage", description="default warehouse for my workspace")

Store predictions

To store the predictions in a warehouse, update the endpoint and add a store to it. = store
endpoint.table = "predictions"

Next Steps

Once your model endpoint is up and running the way you wanted, you can use it to make predictions from Terrene's iOS, Android, Python, etc. SDKs