Summary

This notebook show how to upload a bonsai algorithm.

from pynexus import BonsaiAPI from pynexus.settings import APPNEXUS_ACCOUNT

Modify your logs

APPNEXUS_ACCOUNT.update({ 'username': "", 'password': "" })


In [2]:
import re

model= """
if segment[1].age <= 180:
    1
else:
    5
"""

# Needed if from a notebook
model_str = "\n".join([re.sub("(\s{4})", "\t", line) for line in model.split('\n')])
model_name = "test_bonsai_1"
member_id = int('your_member_id')

bonsai_api = BonsaiAPI(**APPNEXUS_ACCOUNT)

In [14]:
bonsai_api.add_model(model_name=model_name, 
                     member_id=member_id, advertiser_id=int('your_advertiser_id'),
                     model_output="bid_modifier", model_str=model_str)


2016-09-02 12:08:11 INFO 1. Validating the model
2016-09-02 12:08:13 INFO 2. Uploading the model
2016-09-02 12:08:14 INFO Status: OK

In [15]:
[x for x in bonsai_api.get_models() if x['name'] == model_name]


Out[15]:
[{'active': True,
  'advertiser_id': your_advertiser_id,
  'code': None,
  'custom_model_structure': 'decision_tree',
  'id': 17519,
  'last_modified': '2016-09-02 10:08:14',
  'member_id': your_member_id,
  'model_output': 'bid_modifier',
  'name': 'test_bonsai_1'}]

In [ ]: