Problem with DataAnalysis for Iris


I’m currently applying the approach documented in Quickstart with Deeplearning4J to the Iris basic case.

I have correctly included in the pom.xml the required entries. The program compiles well but generates the following exception:

Exception in thread “main” java.util.NoSuchElementException: No more elements found!

It seems like there was a problem with the data, but I use exactly the iris.txt file of DL4J examples with 4 doubles and the class (0,1 or 2):



The code is as follows:

        Random random = new Random();
        FileSplit inputSplit = new FileSplit(new File("C:\\Users\\username\\dl4j-examples-data\\datavec-examples\\IrisData"), random);

        RecordReader recordReader = new CSVRecordReader();

        //sepal length in cm
        //sepal width in cm
        //petal length in cm
        //petal width in cm
        //0 is Iris Setosa
        //1 is Iris Versicolour
        //2 is Iris Virginica
        Schema schema = new Schema.Builder()
                .addColumnsDouble("sepal length", "sepal width", "petal length", "petal width")
                .addColumnCategorical("Class", "0", "1", "2")
        DataAnalysis analysis = AnalyzeLocal.analyze(schema, recordReader); // <===== GENERATES AN EXCEPTION

The exception is raised by the last line of code.
The rest of the code (not shown) to build the network, train, test and save the model runs fine if the code line above is set as a comment.

The detail error stack is:

Exception in thread "main" java.util.NoSuchElementException: No more elements found!
	at org.datavec.api.records.reader.impl.csv.CSVRecordReader.readStringLine(
	at org.datavec.api.records.reader.impl.csv.CSVRecordReader.nextRecord(
	at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.initializeUnderlying(
	at com.thenlpcy.mydl4jwebservernb.MyDL4JWebServerNB.main(
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal (
    at org.apache.commons.exec.DefaultExecutor.execute (
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (
    at org.codehaus.mojo.exec.ExecMojo.execute (
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (
    at org.apache.maven.lifecycle.internal.MojoExecutor$ (
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (
    at (
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (
    at org.apache.maven.DefaultMaven.doExecute (
    at org.apache.maven.DefaultMaven.doExecute (
    at org.apache.maven.DefaultMaven.execute (
    at org.apache.maven.cli.MavenCli.execute (
    at org.apache.maven.cli.MavenCli.doMain (
    at org.apache.maven.cli.MavenCli.main (
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (
    at java.lang.reflect.Method.invoke (
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (

Does anyone knows what may go wrong here?

@lbonansbrux could you post a direct link to a file I can just run so it’s easier for me to look at this? Thanks!

Hi Adam, a zip file containing the small Java Maven project and the data files is available under - Google Drive

Before running the program, simply update the MyDL4JWebServerNB class static String variables with the path to the application’s current directory (lines 67 to 82).

To run the program:

mvn compile exec:java -Dexec.mainClass=com.thenlpcy.mydl4jwebservernb.MyDL4JWebServerNB

Line 121 generates the exception. If commented (with line 122), the program runs well and launches a Tomcat server, which main page is localhost:8080/go. From there 2 pages are available to make predictions.

If line 121 (and 122) are commented, I cannot benefit from the analysis to later on normalize the data in the prediction.

Thanks for your support!



before you call next().


            DataSetIterator iterator = new RecordReaderDataSetIterator(recordReader, batchSize, labelIndex, numClasses);
            DataSet allData =;
            SplitTestAndTrain testAndTrain = allData.splitTestAndTrain(0.65);  //Use 65% of data for training

            DataSet trainingData = testAndTrain.getT

The issue was your analysis used up all the data in the record reader. The record reader maintains a current cursor. When it’s exhausted you need to reinitialize it. The same is true when you use the iterator. The iterator has a reset() method for this reason.

Many thanks Adam!

It works now!