Getting Started with Terrene's API

Integrate machine learning into your product today, not 6 months from now. Get started immediately by integrating Terrene's autoML engine without having to break the bank on data scientists

Install Python SDK

If you prefer to install from source, please visit the githup repo
Command
pip install terrene

Authentication


Python
from terrene.contrib import Client

client = Client('https://<your-instance>.api.terrene.co')
client.authenticate_with_email_and_password('<email>', '<password>')

Create a Reducer

For more information regarding reducer runtime and available tools, please visit the reducers docs
Python
from terrene.store import BaseReducer

reducer = client.create(BaseReducer, dict(
   name='CSV Reducer Python SDK',
   description='CSV Reducer created by the python sdk',
   code='import pandas\ncontent = pandas.read_csv(content)'))

# test the reducer run method
dataframe, stderr = reducer.run(open('dist/titanic.csv'))
print(dataframe, stderr)

Create a TFrame


Python
from terrene.store import TFrame

tframe = client.create(TFrame, dict(
   name='Titanic dataset tframe',
   description='some test tframe'))

background_job = tframe.from_reducer(reducer, open('dist/titanic.csv'))
while True:
   background_job.sync()
   if background_job.progress == 100 or background_job.failed:
       break
   time.sleep(1)

# print the loaded dataframe
tframe_df = tframe.download_dataframe()

# modify the tframe and upload it back
time.sleep(3)
tframe_df['New_Col'] = 'test'
background_job = tframe.upload_dataframe(tframe_df)
while True:
   background_job.sync()
   if background_job.progress == 100 or background_job.failed:
       break
   time.sleep(1)

Create a Predictive Model

For more information regarding predictive models and available tools, please visit the predictive model docs
Python
from terene.model import PredictiveModel

model = client.create(PredictiveModel, dict(
   name='Titanic Predictive Model', description='Predictive Model',
   input_variables=['Age', 'Sex', 'Cabin', 'Parch'],
   output_variables=['Survived']))
suggested_trainers = model.suggest(tframe)

# display suggested_trainers
print(suggested_trainers)

Train Your Model


Python
# train model with suggested trainer
background_job = model.train(tframe, suggested_trainers[0])
while True:
   background_job.sync()
   if background_job.progress == 100 or background_job.failed:
       break
   time.sleep(1)

Generate Predictions


Python
preds = model.predict({'Age': 12, 'Sex': 'male', 'Cabin': 'C30', 'Parch': 1})
print(preds)

# test batch predictions
time.sleep(2)
background_job = model.predict_from_tframe(tframe)
while True:
   background_job.sync()
   if background_job.progress == 100 or background_job.failed:
       break
   time.sleep(1)

# get the predicted tframe
time.sleep(2)
tframe_with_preds = tframe.download_dataframe()
print(tframe_with_preds)

Send Notifications


Python
# TFrame notification
tframe.warn(subject="Test Warning", content='Lorem ipsum....', target='read')  # target can be 'read', 'write', or 'execute'


# Global notification
tframe.inform(subject="Test Warning", content='Lorem ipsum....', target='read')  # target can be 'read', 'write', or 'execute'