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

Computing simple regression

The SimpleRegression class supports ordinary least squares regression with one independent variable: y = intercept + slope * x, where intercept is an optional parameter. The class is also capable of providing standard error for intercept. Observations (x,y) pairs can either be added to the model one at a time or they can be provided in a two-dimensional array. In this recipe, the data points are added one at a time.


The observations are not stored in memory and therefore there is no limit on the number of observations that can be added to the model.

How to do it...

  1. To compute simple regression, create a method that takes a two-dimensional double array. The array represents a series of (x,y) values:

            public void calculateRegression(double[][] data){ 
  2. Create a SimpleRegression object, and add the data:

            SimpleRegression regression = new SimpleRegression(); 


    If you do not have interception or if...