@agibsonccc My code looks like this:
public class RegressionExperimental_ex {
private static final String NEURAL_NAME = "data-d86660f4";
private static final String DATASET_NAME = "/regression-datasets/" + NEURAL_NAME;
public static File datasetName = new File(Configs.baseDir, DATASET_NAME + File.separator);
private static File featuresDir = new File(datasetName, "features");
private static File labelsDir = new File(datasetName, "labels");
private static final int EPOCHS = 15;
public static void main(String[] args) throws Exception {
var files = Files.list(featuresDir.toPath()).collect(Collectors.toList());
int filesSize = files.size();
int eightyPrecents = (int) (filesSize * 0.80);
//Train data
SequenceRecordReader trainFeatures = new CSVSequenceRecordReader(0, ";");
trainFeatures.initialize(new NumberedFileInputSplit(featuresDir.getAbsolutePath() + "/%d.csv", 1, eightyPrecents));
SequenceRecordReader trainLabels = new CSVSequenceRecordReader(0, ";");
trainLabels.initialize(new NumberedFileInputSplit(labelsDir.getAbsolutePath() + "/%d.csv", 1, eightyPrecents)); //17999
boolean regression = true;
int miniBatchSize = 30;
int numLabelClasses = 1;
SequenceRecordReaderDataSetIterator trainData = new SequenceRecordReaderDataSetIterator(trainFeatures, trainLabels, miniBatchSize, numLabelClasses,
regression, SequenceRecordReaderDataSetIterator.AlignmentMode.ALIGN_END);
//Normalize data
NormalizerStandardize normalizer = new NormalizerStandardize();
normalizer.fit(trainData);
trainData.setPreProcessor(normalizer);
trainData.reset();
SequenceRecordReader testFeatures = new CSVSequenceRecordReader(0, ";");
testFeatures.initialize(new NumberedFileInputSplit(featuresDir.getAbsolutePath() + "/%d.csv", eightyPrecents + 1, filesSize - 1)); //18000 - 21640
SequenceRecordReader testLabels = new CSVSequenceRecordReader(0, ";");
testLabels.initialize(new NumberedFileInputSplit(labelsDir.getAbsolutePath() + "/%d.csv", eightyPrecents + 1, filesSize - 1));
SequenceRecordReaderDataSetIterator testData = new SequenceRecordReaderDataSetIterator(testFeatures, testLabels, miniBatchSize, numLabelClasses,
regression, SequenceRecordReaderDataSetIterator.AlignmentMode.ALIGN_END);
testData.setPreProcessor(normalizer);
// -- Final eval --
SequenceRecordReader finalFeatures = new CSVSequenceRecordReader(0, ";");
finalFeatures.initialize(new NumberedFileInputSplit(featuresDir.getAbsolutePath() + "/%d.csv", filesSize, filesSize));
SequenceRecordReader finalLabels = new CSVSequenceRecordReader(0, ";");
finalLabels.initialize(new NumberedFileInputSplit(labelsDir.getAbsolutePath() + "/%d.csv", filesSize, filesSize));
SequenceRecordReaderDataSetIterator finalData = new SequenceRecordReaderDataSetIterator(finalFeatures, finalLabels, miniBatchSize, numLabelClasses,
regression, SequenceRecordReaderDataSetIterator.AlignmentMode.ALIGN_END);
finalData.setPreProcessor(normalizer);
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.seed(123)
.weightInit(WeightInit.XAVIER)
.updater(new Nadam())
.list()
.layer(new LSTM.Builder()
.activation(Activation.TANH)
.nIn(5)
.nOut(30)
.build())
.layer(new LSTM.Builder()
.activation(Activation.TANH)
.nIn(30)
.nOut(14)
.build())
.layer(new RnnOutputLayer.Builder(LossFunctions.LossFunction.MSE)
.activation(Activation.IDENTITY)
.nIn(30)
.nOut(5)
.build())
.build();
MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
System.out.printf("Started: miniBatchSize: %s, epohs: %s %n", miniBatchSize, EPOCHS);
for (int i = 0; i < EPOCHS; i++) {
long time = System.nanoTime();
net.fit(trainData);
var eval = net.evaluateRegression(testData);
System.out.println(eval);
System.out.println(eval.stats());
time = System.nanoTime() - time;
System.out.println(DATASET_NAME + " Time for epoch № " + (i + 1) + ": " + SECONDS.convert(time, TimeUnit.NANOSECONDS) + " sec");
}
System.out.println("Final:");
RegressionEvaluation regEval = net.evaluateRegression(trainData);
System.out.println(regEval);
System.out.println("---------->");
INDArray timeSeriesOutput = net.output(finalData);
normalizer.revertFeatures(timeSeriesOutput);
normalizer.revertLabels(timeSeriesOutput);
System.out.println(timeSeriesOutput);
long timeSeriesLength = timeSeriesOutput.size(2);
INDArray lastTimeStepProbabilities = timeSeriesOutput.get(NDArrayIndex.point(0), NDArrayIndex.all(), NDArrayIndex.point(timeSeriesLength - 1));
System.out.println("Result: " + lastTimeStepProbabilities);
double[] results = lastTimeStepProbabilities.toDoubleVector();
System.out.println("Double arr: " + Arrays.toString(results));
System.out.println("== End ==");
}
And my dataset: data-d86660f4.zip - Google Drive