Regression Problem

I am study Quickstart with Deeplearning4J. This is classfier example, but I change to linear regression. My target is to predict a number, may be this number not in my dataset lables.
By the example,

RecordReaderDataSetIterator trainIterator = new RecordReaderDataSetIterator.Builder(trainRecordReader, batchSize)
.classification(finalSchema.getIndexOfColumn(“Exited”), 2)
.build();

I change to

RecordReaderDataSetIterator trainIterator = new RecordReaderDataSetIterator.Builder(trainRecordReader, batchSize).regression(finalSchema.getIndexOfColumn(“LABEL_STD”))
.build();

and

MultiLayerConfiguration config = new NeuralNetConfiguration.Builder()
.seed(0xC0FFEE)
.weightInit(WeightInit.XAVIER)
.activation(Activation.TANH)
.updater(new Adam.Builder().learningRate(0.001).build())
.l2(0.000316)
.list(
new DenseLayer.Builder().nOut(finalSchema.numColumns() - 1).build(),
new DenseLayer.Builder().nOut(finalSchema.numColumns() - 1).build(),
new DenseLayer.Builder().nOut(finalSchema.numColumns() - 1).build(),
new DenseLayer.Builder().nOut(finalSchema.numColumns() - 1).build(),
new DenseLayer.Builder().nOut(finalSchema.numColumns() - 1).build(),
new RnnOutputLayer.Builder(LossFunctions.LossFunction.MSE).nOut(1).activation(Activation.IDENTITY).build())
.setInputType(InputType.feedForward(finalSchema.numColumns() - 1))
.build();

but i got the following error

[vert.x-eventloop-thread-0] INFO org.deeplearning4j.ui.VertxUIServer - Deeplearning4j UI server started at: http://localhost:9000
[main] INFO org.deeplearning4j.ui.VertxUIServer - StatsStorage instance attached to UI: InMemoryStatsStorage(uid=206f2af3)
Exception in thread “main” java.lang.IllegalStateException: Expected rank 3 labels array, got label array with shape [80, 1]
at org.nd4j.common.base.Preconditions.throwStateEx(Preconditions.java:639)
at org.nd4j.common.base.Preconditions.checkState(Preconditions.java:301)
at org.deeplearning4j.nn.layers.recurrent.RnnOutputLayer.backpropGradient(RnnOutputLayer.java:58)
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.calcBackpropGradients(MultiLayerNetwork.java:1984)
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.computeGradientAndScore(MultiLayerNetwork.java:2799)
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.computeGradientAndScore(MultiLayerNetwork.java:2742)
at org.deeplearning4j.optimize.solvers.BaseOptimizer.gradientAndScore(BaseOptimizer.java:174)
at org.deeplearning4j.optimize.solvers.StochasticGradientDescent.optimize(StochasticGradientDescent.java:61)
at org.deeplearning4j.optimize.Solver.optimize(Solver.java:52)
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.fitHelper(MultiLayerNetwork.java:2343)
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.fit(MultiLayerNetwork.java:2301)
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.fit(MultiLayerNetwork.java:2364)
at com.jufan.machinelearning.trainer.JoblogTrainer.AnalysisAndTraining(JoblogTrainer.java:189)
at com.jufan.machinelearning.trainer.JoblogTrainer.main(JoblogTrainer.java:50)

how and i solve it.

Thanks a lot.

@Justin you need to use a sequence record reader for training RNNs. This is classification but should give you a starting point: deeplearning4j-examples/Conv1DUCISequenceClassification.java at 60de3144b7619a6c80fab899baac9301df1a882d · eclipse/deeplearning4j-examples · GitHub

@agibsonccc Thank you.
have any example to predictor a number, not classify.

@Justin I’m aware of that. My point was showing you how to use the input data. Use some of that example as your base for that.
Beyond that,you just need to tell the iterator that you have a regression problem and what column it is. See more here: https://deeplearning4j.konduit.ai/v/en-1.0.0-m1.1/deeplearning4j/reference/computation-graph#example-1-regression-data-recordreadermultidatasetiterator

@agibsonccc Thank you for your kind explanation.

following is my column

TransformProcess transformProcess = new TransformProcess.Builder(schema)
.removeColumns(“ECM01”, “ECM03”, “SHB02”, “SHB021”, “SHB03”, “SHB031”, “ECM45”, “SHBCONF”, “SFB22”, “SFB221”, “SHB04”, “SFB05”,“SFB06”,“SHB10”)
.categoricalToOneHot(“ECM04”)
.categoricalToOneHot(“PRDTYPE”)//PRDTYPE
.categoricalToOneHot(“SPL”)//SPL
.categoricalToOneHot(“SPEC1”) //SPEC1
.categoricalToOneHot(“SPL”) //ACTIONTYPE
.normalize(“BORE”, Normalize.MinMax, analysis)//BORE
.normalize(“STROKE”, Normalize.MinMax, analysis)//STROKE
.categoricalToOneHot(“APPLYPRD”)//APPLYPRD
.normalize(“SHB111”, Normalize.MinMax, analysis)
.normalize(“SHB033”, Normalize.MinMax, analysis)
.normalize(“LABEL_COST”, Normalize.MinMax, analysis)
.normalize(“LABEL_STD”, Normalize.MinMax, analysis)
.build();

following , trainIterator, is my iterator:

Schema finalSchema = transformProcess.getFinalSchema();
TransformProcessRecordReader trainRecordReader = new TransformProcessRecordReader(new CSVRecordReader(), transformProcess);
trainRecordReader.initialize(inputSplit);
int batchSize = 80;
RecordReaderDataSetIterator trainIterator = new RecordReaderDataSetIterator.Builder(trainRecordReader, batchSize)
.regression(finalSchema.getIndexOfColumn(“LABEL_STD”))
.build();

my problem is , train a model to predictor “LABEL_STD”

@Justin I kept telling you multiple times you need to use the sequence record reader for this not the normal one. Please take the time to read and understand what I told you.

If you don’t do that then I can assume you’re ignoring what I wrote and unfortunately that means helping you is a waste of time.

If it is because english is not your first language or some other issue please notify me of that and I can try to clarify things for you.

@agibsonccc English is not your first language. Thank your help.
I would try “sequence record reader”
Thank you.

@agibsonccc Thank your telling multiple times to use the sequence record reader. and time to time reading your suggestion. By the key work “sequence record reader” and my tangle about TransformProcess.
I find a good example

may be good for me.

@Justin thanks for engaging with me. That’s a much better indicator of where you are at. Now I get what you are doing. Please use the TransformProcessSequenceRecordReader for your use case: deeplearning4j/TransformProcessSequenceRecordReader.java at master · eclipse/deeplearning4j · GitHub

@agibsonccc Thanks for your kind suggestion