Linear regression using Encog

Now, we will quickly look at how Encog can be used to make a regression model. We will be using the dataset that we used in a previous section, Loading the data. The following steps show how to make the model: 

  1. To load the data, we will use the VersatileMLDataSet function, as follows:
File datafile = new File("data/ENB2012_data.csv");
VersatileDataSource source = new CSVDataSource(datafile, true, CSVFormat.DECIMAL_POINT);
VersatileMLDataSet data = new VersatileMLDataSet(source);
data.defineSourceColumn("X1", 0, ColumnType.continuous);
data.defineSourceColumn("X2", 1, ColumnType.continuous);
data.defineSourceColumn("X3", 2, ColumnType.continuous);
data.defineSourceColumn("X4", 3, ColumnType.continuous);
data.defineSourceColumn("X5", 4, ColumnType.continuous);
data.defineSourceColumn("X6", 5, ColumnType.continuous);
data.defineSourceColumn("X7", 6, ColumnType.continuous);
data.defineSourceColumn("X8", 7, ColumnType.continuous);
  1. As we have two pieces of output, Y1 and Y2, they can be added by using the defineMultipleOutputsOthersInput function, as follows:
ColumnDefinition outputColumn1 = data.defineSourceColumn("Y1", 8,    ColumnType.continuous);
ColumnDefinition outputColumn2 = data.defineSourceColumn("Y2", 9, ColumnType.continuous);
ColumnDefinition outputscol [] = {outputColumn1, outputColumn2};
data.analyze();

data.defineMultipleOutputsOthersInput(outputscol);
  1. The next step is to develop a simple regression model by using the FEEDFORWARD instance:
EncogModel model = new EncogModel(data); 
model.selectMethod(data, MLMethodFactory.TYPE_FEEDFORWARD);
model.setReport(new ConsoleStatusReportable());

data.normalize();
model.holdBackValidation(0.3, true, 1001);
model.selectTrainingType(data);
MLRegression bestMethod = (MLRegression)model.crossvalidate(5, true);
NormalizationHelper helper = data.getNormHelper();

System.out.println(helper.toString());
System.out.println("Final model: " + bestMethod);

Now, our regression model is ready. The last few lines of the output are given in the following screenshot:

..................Content has been hidden....................

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