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

Creating a linear regression model with MLib

In this recipe, you will see how you can use a linear regression model to model with MLib.

Getting ready

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

  2. Go to, download the data, and save as lr-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 lr-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 Double-click to start writing your code in it.

Now, you are ready to do some coding.

How to do it...

  1. Create a class named LinearRegressionMlib:

            public class LinearRegressionMlib...