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
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Clustering using KMeans algorithm with MLib


In this recipe, we will demonstrate how you can cluster data points without labels using KMeans algorithm with MLib. As discussed in the introduction of this chapter, MLib is the machine learning component of Apache Spark and is a competitive (even better) alternative to Apache Mahout.

Getting ready

  1. You will be using the Maven project you created in the previous recipe (solving simple text mining problems with Apache Spark). If you have not done so yet, follow steps 1-6 in the Getting ready section of that recipe.

  2. Go to https://github.com/apache/spark/blob/master/data/mllib/kmeans_data.txt, and download the data and save as km-data.txt in the data folder of your project that you created by following the instruction in step 1. Alternatively, you can create a text file named km-data.txt in the data folder of your project and copy-paste the data from the aforementioned URL.

  3. In the package that you created, create a Java class file named KMeansClusteringMlib...