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 constructs a function that linearly combines the input variables to estimate the heating load. The number in front of the feature explains the feature's impact on the target variable: the sign corresponds to the positive/negative impact, while the magnitude corresponds to its significance. For instance, the relative compactness of the feature X1 is negatively correlated with heating load, while the glazing area is positively correlated. These two features also significantly impact the final heating load estimate. The model's performance can similarly be evaluated with the cross-validation technique.

The ten-fold cross-validation is as follows:

Evaluation eval = new Evaluation(data); 
eval.crossValidateModel(model, data, 10, new Random(1), new String[]{}); 
System.out.println(eval.toSummaryString()); 

We can provide the common evaluation metrics, including the correlation, the mean absolute error, the relative absolute error, and so on, as output, as follows:

Correlation coefficient                  0.956  
Mean absolute error                      2.0923 
Root mean squared error                  2.9569 
Relative absolute error                 22.8555 % 
Root relative squared error             29.282  % 
Total Number of Instances              768      
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.181.47