Linear regression

We will start with a basic linear regression model, implemented with the LinearRegression class. Similar to the classification example, we will initialize a new model instance, pass the parameters and data, and invoke the buildClassifier(Instances) method, as follows:

import weka.classifiers.functions.LinearRegression; 
... 
data.setClassIndex(data.numAttributes() - 2);LinearRegression model = new LinearRegression(); model.buildClassifier(data); System.out.println(model);

The learned model, which is stored in the object, can be provided by calling the toString() method, as follows:

    Y1 =
    
        -64.774  * X1 +
         -0.0428 * X2 +
          0.0163 * X3 +
         -0.089  * X4 +
          4.1699 * X5 +
         19.9327 * X7 +
          0.2038 * X8 +
         83.9329
  

The linear regression model ...

Get Machine Learning in Java - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.