# How to fix problems with DataSetIterators?

**URL:** <https://community.konduit.ai/t/how-to-fix-problems-with-datasetiterators/1072>\
**Category:** DL4J\
**Created:** [December 22, 2020, 10:48pm UTC](https://community.konduit.ai/t/how-to-fix-problems-with-datasetiterators/1072 "2020-12-22T22:48:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fletchni](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@fletchni](https://community.konduit.ai/u/fletchni)\
**Post date:** [December 22, 2020, 10:48pm UTC](https://community.konduit.ai/t/how-to-fix-problems-with-datasetiterators/1072/1 "2020-12-22T22:48:09Z")

</div>

Hello,  
I have two CSV files, one for training data and one for testing data. My goal is to do a time series prediction on stock data. The training data consists of 80% of stocks data over the last 5 years, and the test data consists of the most recent 20% of its data. I create two CSVSequenceRecordReaders and load a file into each separate reader, then with each separate reader, I create a DataSetIterator. Everything up to that point works, except I want to create DataSets with both the TestDataSetIterator and TrainDatasetIterator. When I call the next() method from each iterator, I get NoSuchElementException error. How can I fix my DataSetIterators so that I can properly convert them into DataSet Objects?

Here is the example I am following: [https://github.com/deeplearning4j/oreilly-book-dl4j-examples/blob/master/dl4j-examples/src/main/java/org/deeplearning4j/examples/recurrent/regression/SingleTimestepRegressionExample.java](https://github.com/deeplearning4j/oreilly-book-dl4j-examples/blob/master/dl4j-examples/src/main/java/org/deeplearning4j/examples/recurrent/regression/SingleTimestepRegressionExample.java)

When i get to around line 68, creating a DataSet object from DataSetIterator.next() does not work for either DataSetIterators. I get the error i mentioned above.

---

<div class="post-metadata">

**Author:** ![cagneymoreau](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/cagneymoreau/32/296_2.png) [@cagneymoreau](https://community.konduit.ai/u/cagneymoreau)\
**Post date:** [December 23, 2020, 1:07am UTC](https://community.konduit.ai/t/how-to-fix-problems-with-datasetiterators/1072/2 "2020-12-23T01:07:03Z")

</div>

Did the other example I sent help you at all?

---

<div class="post-metadata">

**Author:** ![fletchni](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@fletchni](https://community.konduit.ai/u/fletchni)\
**Post date:** [December 23, 2020, 7:28pm UTC](https://community.konduit.ai/t/how-to-fix-problems-with-datasetiterators/1072/3 "2020-12-23T19:28:58Z")

</div>

yes, it did. Ive actually solved the DataSetIterator problem. Does it make a difference if i train my network on a DataSet Object rather than a DataSetIterator Object?

---

<div class="post-metadata">

**Author:** ![cagneymoreau](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/cagneymoreau/32/296_2.png) [@cagneymoreau](https://community.konduit.ai/u/cagneymoreau)\
**Post date:** [December 23, 2020, 7:44pm UTC](https://community.konduit.ai/t/how-to-fix-problems-with-datasetiterators/1072/4 "2020-12-23T19:44:43Z")

</div>

You could create differences because of a user error but it should be the same result if done correctly.
