Indico Data receives top position in Everest Group's Intelligent Document Processing (IDP) Insurance PEAK Matrix® 2024
Read More
  Everest Group IDP
             PEAK Matrix® 2022  
Indico Named as Major Contender and Star Performer in Everest Group's PEAK Matrix® for Intelligent Document Processing (IDP)
Access the Report

BLOG

Tutorial: Using indico’s Machine Learning API (for Beginners)

April 5, 2016 | Developers, Text Data Use Case, Tutorials

Back to Blog

About this Tutorial

This tutorial assumes you have no programming experience and do not have a development environment. It will guide you through setting up a development environment and producing the code to access advanced machine learning solutions.

If you run into any issues while following this tutorial, please feel free to create an issue on this repository or contact us at contact@indico.io

Code Editor

You will probably need some kind of text editor for your code. Unless you have a preference already, I recommend Atom.

Table of Contents

Getting Started: Development Environment

Ubuntu / Linux
OSX
Windows

Using Indico

Code

Getting Started: Development Environment

Ubuntu / Linux

  1. Open the Terminal application (CTRL + ALT + T) or (Super Key & search “Terminal”) and update your package manager package lists.
  2. sudo apt-get update
    

  3. Install Python 2.7.
  4. sudo apt-get install -y python
    

  5. Install pip, a Python package manager.
  6. sudo apt-get install -y python-pip
    

  7. Install the Python developer library.
  8. sudo apt-get install -y build-essential python-dev
    

  9. Install the imaging dependencies.
    For Ubuntu 12.04 LTS or Raspian Wheezy 7.0

    sudo apt-get install -y libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk
    

    For Ubuntu 14.04

  10. sudo apt-get install -y libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
    

  11. Install the indicoio Python package.
  12. sudo pip install indicoio
    

indicoio should be successfully installed! Now you’re ready for the next step.

OSX

  1. Open up a Terminal – go to Spotlight (CMD + SPACE) and search “Terminal”.
  2. Make sure you have XCode and its developers tools installed.
  3. xcode-select --install
    

  4. Install Homebrew (a great package manager for OSX).
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    Add Homebrew’s path to the start of your existing $PATH variable.

    open ~/.profile
    

    Then, add the following to the bottom of the file.

    export PATH=/usr/local/bin:/usr/local/sbin:$PATH
    

    Now, reload the profile.

  5. source ~/.profile
    
  6. Make sure you have Python2.7 installed.
    python --version
    # should respond with Python 2.7.x
    

    If you don’t have Python installed:

  7. brew update
    brew doctor
    brew install python
    
  8. Install the appropriate imaging libraries.
  9. brew install libjpeg
    brew install zlib
    
  10. Install the indicoio Python package.
  11. sudo pip install indicoio
    

indicoio should be successfully installed! Now you’re ready for the next step.

Windows

Setting up Windows is going to be a little bit involved, so if you have a choice, I highly recommend using either OSX or Linux instead.
For development in Windows, I recommend getting Cygwin, which gives Windows some commands commonly found in Linux / OSX environments.

  1. Download Cygwin and run the downloaded installer (64 bit or 32 bit depending). Go ahead and choose all the default options. When it asks to choose a mirror, choose whichever one you’d like – it doesn’t matter.
  2. Add the Cygwin path to your environment variables. See these instructions. For Windows 8 and 10, you can access environment variables by searching “Environment Variables” in your Start menu.
  3. Find the PATH variable under your System Environment Variables. Make sure there is a semicolon at the end “;” or add one if there isn’t. Then, paste C:cygwin64bin at the end (ensure that folder exists). LEAVE THIS WINDOW OPEN. We’ll be making more changes.
  4. Download the latest version of Python 2 (first link). Choose the Windows x86(-64) MSI installer (again 64 bit or regular).
  5. After you’ve run the Python Installer, go add to the PATH variable again: C:Python27 AND C:Python27Scripts.
  6. Now, open a Command Prompt. (Start Menu + “cmd”). If you are on an older version of Windows, you may have to do Start -> Run -> “cmd”.
  7. Test the commands to make sure everything was installed and setup properly.
  8. ls
    python
    pip
    

    If ls fails, Cygwin was not installed and setup properly.
    If python fails, Python was not installed and setup properly.
    If pip fails, C:Python27Scripts either does not exist or was not added properly.

  9. In the Command Prompt still:
  10. pip install indicoio
    

indicoio should be successfully installed! Now you’re ready for the next step.

Using indico

Pull up your favorite code editor (Atom. is the one recommended at the top of this tutorial).

  1. Create a new file and save it as trying-indico.py
  2. Add the following line to the top of this file:
  3. import indicoio
    

    This imports the indicoio package that contains several functions that will help you access the Machine Learning APIs that indico provides.

  4. Get your indico API key by signing up for indico. You get a good number of free calls per month to test as much as you need. You’ll find your API key at the top of your dashboard once you log in.
  5. Add it to the script!
  6. indicoio.config.api_key = "Paste your API Key here, inside the quotation marks"
    

    Now you’re ready to see some Machine Learning action! 😉

  7. There are a bunch of APIs available – visit our docs to get set up with one (or a few!) of them. Switch the code snippets to python.

You can check out all the different kinds of APIs indico provides and learn more about what they do.

Sentiment HQ Example

Here’s an example of how to make a call to our Sentiment HQ API.

import indicoio
indicoio.config.api_key="Your API key here"
sentiment = indicoio.sentiment_hq("Meditating on happiness makes me very happy.")
print sentiment

To run this script, pull up your terminal (or command prompt) and navigate to the folder that you saved this script by using ls to list the contents of the current folder and cd to change to the folder you want. Then, run the command python followed by the filename.

$ python trying-indico.py
0.994322896004

The sentiment of “Meditating on happiness makes me very happy” is 0.994. The closer the value is to 1 the more positve sentiment it is. Likewise, the closer to 0 the more negative the sentiment is. Looking good!

Try using an article URL!

import indicoio
indicoio.config.api_key="Your API key here"
sentiment = indicoio.sentiment_hq("http://www.vanityfair.com/news/2015/10/the-serious-problem-with-treating-donald-trump-seriously", url=True)
print "Sentiment of the article is: {0}".format(sentiment)
# Let's get some keywords too! (This is a comment by the way. Comments aren't run as code, but just act as notes from one programmer to another.)
keywords = indicoio.keywords("http://www.vanityfair.com/news/2015/10/the-serious-problem-with-treating-donald-trump-seriously", url=True, top_n=5)
print "Top 5 keywords of the article are:n{0}".format(keywords)

Now that you’re all set up, why not try building an app with one of our APIs? Check out these tutorials:

Foundations for Building a Flask + indico Web App
Make Content Recommendations Better With Machine Learning
Going from Tweets to Trends in Minutes
Stock Image Similarity with Image Features (or How a Program is More Fashionable than Me)

Feel free to reach out to us with questions, or feedback as to how we can improve our tutorials to help you build with indico at contact@indico.io.

[addtoany]

Increase intake capacity. Drive top line revenue growth.

[addtoany]

Unstructured Unlocked podcast

April 24, 2024 | E45

Unstructured Unlocked episode 45 with Daniel Faggella, Head of Research, CEO at Emerj Artificial Intelligence Research

podcast episode artwork
April 10, 2024 | E44

Unstructured Unlocked episode 44 with Tom Wilde, Indico Data CEO, and Robin Merttens, Executive Chairman of InsTech

podcast episode artwork
March 27, 2024 | E43

Unstructured Unlocked episode 43 with Sunil Rao, Chief Executive Officer at Tribble

podcast episode artwork

Get started with Indico

Schedule
1-1 Demo

Resources

Blog

Gain insights from experts in automation, data, machine learning, and digital transformation.

Unstructured Unlocked

Enterprise leaders discuss how to unlock value from unstructured data.

YouTube Channel

Check out our YouTube channel to see clips from our podcast and more.
Subscribe to our blog

Get our best content on intelligent automation sent to your inbox weekly!