# Problem with DataAnalysis for Iris

**URL:** <https://community.konduit.ai/t/problem-with-dataanalysis-for-iris/2562>\
**Category:** DataVec\
**Created:** [May 17, 2023, 6:02pm UTC](https://community.konduit.ai/t/problem-with-dataanalysis-for-iris/2562 "2023-05-17T18:02:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lbonansbrux](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lbonansbrux/32/1113_2.png) [@lbonansbrux](https://community.konduit.ai/u/lbonansbrux)\
**Post date:** [May 17, 2023, 6:02pm UTC](https://community.konduit.ai/t/problem-with-dataanalysis-for-iris/2562/1 "2023-05-17T18:02:52Z")

</div>

Hi!

I’m currently applying the approach documented in [Quickstart with Deeplearning4J](https://www.dubs.tech/guides/quickstart-with-dl4j/#loading-data) 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):

5.1,3.5,1.4,0.2,0  
…  
5.9,3.0,5.1,1.8,2

The code is as follows:

```auto
        Random random = new Random();
        random.setSeed(0xC0FFEE);
        FileSplit inputSplit = new FileSplit(new File("C:\\Users\\username\\dl4j-examples-data\\datavec-examples\\IrisData"), random);

        RecordReader recordReader = new CSVRecordReader();
        recordReader.initialize(inputSplit);

        //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")
                .build();
        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:

```auto
Exception in thread "main" java.util.NoSuchElementException: No more elements found!
	at org.datavec.api.records.reader.impl.LineRecordReader.next(LineRecordReader.java:117)
	at org.datavec.api.records.reader.impl.csv.CSVRecordReader.readStringLine(CSVRecordReader.java:193)
	at org.datavec.api.records.reader.impl.csv.CSVRecordReader.next(CSVRecordReader.java:173)
	at org.datavec.api.records.reader.impl.csv.CSVRecordReader.nextRecord(CSVRecordReader.java:199)
	at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.initializeUnderlying(RecordReaderDataSetIterator.java:194)
	at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:341)
	at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:421)
	at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:53)
	at com.thenlpcy.mydl4jwebservernb.MyDL4JWebServerNB.main(MyDL4JWebServerNB.java:100)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:1000)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:947)
    at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:471)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:827)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:272)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:195)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

```

Does anyone knows what may go wrong here?

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [May 18, 2023, 7:41am UTC](https://community.konduit.ai/t/problem-with-dataanalysis-for-iris/2562/2 "2023-05-18T07:41:42Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![lbonansbrux](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lbonansbrux/32/1113_2.png) [@lbonansbrux](https://community.konduit.ai/u/lbonansbrux)\
**Post date:** [May 19, 2023, 1:27pm UTC](https://community.konduit.ai/t/problem-with-dataanalysis-for-iris/2562/3 "2023-05-19T13:27:42Z")

</div>

Hi Adam, a zip file containing the small Java Maven project and the data files is available under [https://drive.google.com/file/d/1AMeFuOYuAiI7IuXPPIESxweLe3-9pBoh/view?usp=share\_link](https://drive.google.com/file/d/1AMeFuOYuAiI7IuXPPIESxweLe3-9pBoh/view?usp=share_link)

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!

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [May 19, 2023, 10:43pm UTC](https://community.konduit.ai/t/problem-with-dataanalysis-for-iris/2562/4 "2023-05-19T22:43:14Z")

</div>

@lbonansbrux

add:  
recordReader.initialize(inputSplit);

before you call next().

```auto
           recordReader.initialize(inputSplit);

            DataSetIterator iterator = new RecordReaderDataSetIterator(recordReader, batchSize, labelIndex, numClasses);
            DataSet allData = iterator.next();
            allData.shuffle();
            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.

---

<div class="post-metadata">

**Author:** ![lbonansbrux](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/lbonansbrux/32/1113_2.png) [@lbonansbrux](https://community.konduit.ai/u/lbonansbrux)\
**Post date:** [May 20, 2023, 8:55am UTC](https://community.konduit.ai/t/problem-with-dataanalysis-for-iris/2562/5 "2023-05-20T08:55:42Z")

</div>

Many thanks Adam!

It works now!

Resolved.
