Machine Learning in Java has never been easier!

Posted by

Java is by far one of the most popular programming languages.  It’s on the top of the TIOBE index and thousands of the most robust, secure, and scalable backends have been built in Java. In addition, there are many wonderful libraries available that can help accelerate your project enormously.  For example, most of BigML’s backend is developed in Clojure which runs on top of the Java Virtual Machine.  And don’t forget the ever-growing Android market, with 850K new devices activated each day!

There are number of machine learning Java libraries available to help build smart data-driven applications. Weka is one of the more popular options. In fact, some of BigML’s team members were Weka users as far back as the late 90s. We even used it as part of the first BigML backend prototype in early 2011. Apache Mahout is another great Java library if you want to deal with bigger amounts of data. However in both cases you cannot avoid  “the fun of running servers, installing packages, writing MapReduce jobs, and generally behaving like IT ops folks“. In addition you need to be concerned with selecting and parametrizing the best algorithm to learn from your data as well as finding a way to activate and integrate the model that you generate into your application.

Java flavored BigML binding

Thus we are thrilled to announce  the availability of the first Open Source Java library that easily connects any Java application with the BigML REST API.  It has been developed by Javi Garcia, an old friend of ours.  A few of the BigML team members have been lucky enough to work with Javi in two other companies in the past.

With this new library, in just a few lines of code you can create a predictive model and generate predictions for any application domain. From finding the best price for a new product to forecasting sales, creating recommendations, diagnosing malfunctions, or detecting anomalies.

The library is shipped with Maven as project manager and has a test suite developed using Cucumber. If you clone it from Github and add your BigML credentials to src/main/resources/binding.properties, you can run the tests:

mvn test

If you’re a Maven aficionado,  you can add BigML to your project by following these two steps:

  1. Install the library to your local maven repo by executing “mvn install” in the bigml-java directory.
  2. Add the dependency to your pom.xml:
<dependency>
  <groupId>org.bigml</groupId>
  <artifactId>java-binding</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
  <groupId>com.googlecode.json-simple</groupId>
  <artifactId>json-simple</artifactId>
  <version>1.1.1</version>
</dependency>

The json-simple dependency is used to wrap the responses of the BigML client. Below you can see the simplest Java class integrating the BigML
binding:

import org.bigml.binding.AuthenticationException;
import org.bigml.binding.BigMLClient;
import org.json.simple.JSONObject;

public class BigmlClient {
    /**
     * A simple Java Class to integrate the BigML API
     *
     * @param args
     */
    public static void main(String[] args) {
        BigMLClient bigml = null;
        try {
            // BigML API's credentials might be passed as parameters
            bigml = BigMLClient.getInstance();
        } catch (AuthenticationException e) {
            e.printStackTrace();
            return;
        }
        // Create a datasource by upload a file
        JSONObject source = bigml.createSource("data/iris.csv", "My First Source", null);
        System.out.println(source.toJSONString());
        // Wait until source is ready
        while (!bigml.sourceIsReady(source)) {
            source = bigml.getSource(source);
            System.out.println("Waiting for source to be ready");
        }
        System.out.println(source.toJSONString());
   }
}

That’s all you need to start using BigML in your Java application

If you are developer and want to start to use our API right away, just drop a line to info@bigml.com and we’ll send you an invite.

Happy Java Hacking!

7 comments

  1. Very cool. I’m a curator for DZone.com. Would you be interested in posting this or an original post about this topic in Javalobby? Shoot me an email if it sounds like a good idea to you.

    1. Hi mi0tch919, feel free to post this on DZone, or give me an address I can use to get in contact you. Thanks!

Leave a comment