Book Image

Java Data Science Cookbook

By : Rushdi Shams
Book Image

Java Data Science Cookbook

By: Rushdi Shams

Overview of this book

If you are looking to build data science models that are good for production, Java has come to the rescue. With the aid of strong libraries such as MLlib, Weka, DL4j, and more, you can efficiently perform all the data science tasks you need to. This unique book provides modern recipes to solve your common and not-so-common data science-related problems. We start with recipes to help you obtain, clean, index, and search data. Then you will learn a variety of techniques to analyze, learn from, and retrieve information from data. You will also understand how to handle big data, learn deeply from data, and visualize data. Finally, you will work through unique recipes that solve your problems while taking data science to production, writing distributed data science applications, and much more - things that will come in handy at work.
Table of Contents (16 chapters)
Java Data Science Cookbook
About the Author
About the Reviewer
Customer Feedback

Clustering data from classes

If you have a dataset with classes, which is an unusual case for unsupervised learning, Weka has a method called clustering from classes. In this method, Weka first ignores the class attribute and generates the clustering. Then during the test phase, it assigns classes to the clusters based on the majority value of the class attribute within each cluster. We will cover this method in this recipe.

How to do it...

  1. In this recipe, we will use a dataset with class values for instances. We will use a weather.nominal.arff file, which can be found in the data directory of the installed Weka directory.

    In our code, we will have two instance variables. The first variable will contain the instances of our dataset and the second variable will contain an Expectation-Minimization clusterer:

            Instances weather = null; 
            EM clusterer; 
  2. Next, we will be loading our dataset, reading it, and setting the last index as its class index:

           public void loadArff...