<img src="https://d5nxst8fruw4z.cloudfront.net/atrk.gif?account=J5kSo1IWhd105T" style="display:none" height="1" width="1" alt="">

Nexosis @ Work & Play

Exploring the Nexosis API with IPython

September 7, 2017 @ 4:25 PM | Technical


Jeff E has been testing our Python API client library implementation using IPython. Check out some video tutorial he made to show how he did it.


Introduction

I have been playing around with our API using IPython in order to test the Python client library implementation, and see how it works as a user of the API rather than a developer building the API. This was probably some of the most fun that I have had working with code in a while, so I thought I would put together a few videos to show what I was able to do with just a few lines of code. In the following videos, I am runing IPython from a command prompt in Windows, but this will work just the same from your favorite shell on Linux or MacOS.


Getting Started

In the first video, I am going to take you through installing the Nexosis API Python client library, creating the client object, and getting some basic information from the API. If you are not a regular IPython user, you will want to note how the key can be used to find out what is avalable on an object, and that you can use a `?` to see the docstring information of a module, class, or method.

IPython input from in this video:

import nexosisapi
import os
c = nexosisapi.Client(key=os.environ['NEXOSIS_API_KEY'])
c.get_account_balance()
c.datasets.list?
c.datasets.list()
c.datasets.get?
c.datasets.get('Location-A')
c.views.list() 

Creating a forecast

Generating a forecast is one of the most common uses of the API. In this video, I create a session to generate forecasts based on a view that combined the data set for a location, with the holiday data set that we saw in Part 1.

IPython input from this video:

c.sessions.list?
c.sessions.list()
c.sessions.create_forecast?
c.sessions.create_forecast()
c.sessions.create_forecast('location-d-holidays', 'transactions', '2017-01-01', '2017-02-28')
c.sessions.get?
c.sessions.get('015e5999-936a-489d-8153-3c976906220e') 

Working with forecast results

Finally, we get to the most important part where I look at the output of the forecast and do some processing of the data.

IPython input from this video:

c.sessions.list()
c.sessions.get_results('015e5999-936a-489d-8153-3c976906220e')
results = c.sessions.get_results('015e5999-936a-489d-8153-3c976906220e')
print(results.data)
import textgraph
print(textgraph.horizontal_graph([float(r['transactions']) for r in results.data[0:14]]))

Ready to start building machine learning applications?

Get your free API key  Talk to an expert


Jeff Espendschied

Jeff is one our software engineers at Nexosis. Besides wrangling code and pushing for excellence, he goes by the nickname Laugh Track. Or at least he does now.