Skip to content

Commit f8233e0

Browse files
Updating logic for outputting predictions to be in line with new default iterable
behavior. Change: 141082521
1 parent a0acc3f commit f8233e0

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

tensorflow/examples/tutorials/input_fn/boston.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from __future__ import division
1818
from __future__ import print_function
1919

20+
import itertools
21+
2022
import pandas as pd
2123
import tensorflow as tf
2224

@@ -64,7 +66,9 @@ def main(unused_argv):
6466

6567
# Print out predictions
6668
y = regressor.predict(input_fn=lambda: input_fn(prediction_set))
67-
print("Predictions: {}".format(str(y)))
69+
# .predict() returns an iterator; convert to a list and print predictions
70+
predictions = list(itertools.islice(y, 6))
71+
print("Predictions: {}".format(str(predictions)))
6872

6973
if __name__ == "__main__":
7074
tf.app.run()

tensorflow/g3doc/tutorials/input_fn/index.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ logging verbosity](../monitors/index.md#enabling-logging-with-tensorflow) to
222222
from __future__ import absolute_import
223223
from __future__ import division
224224
from __future__ import print_function
225+
226+
import itertools
227+
225228
import pandas as pd
226229
import tensorflow as tf
227230

@@ -301,8 +304,6 @@ which means the function can process any of the `DataFrame`s you've imported:
301304
To train the neural network regressor, run `fit` with the `training_set` passed
302305
to the `input_fn` as follows:
303306

304-
<!-- TODO(skleinfeld): Decide on the best step value to use here for pedagogical purposes -->
305-
306307
```python
307308
regressor.fit(input_fn=lambda: input_fn(training_set), steps=5000)
308309
```
@@ -355,7 +356,9 @@ Finally, you can use the model to predict median house values for the
355356

356357
```python
357358
y = regressor.predict(input_fn=lambda: input_fn(prediction_set))
358-
print ("Predictions: {}".format(str(y)))
359+
# .predict() returns an iterator; convert to a list and print predictions
360+
predictions = list(itertools.islice(y, 6))
361+
print ("Predictions: {}".format(str(predictions)))
359362
```
360363

361364
Your results should contain six house-value predictions in thousands of dollars,

0 commit comments

Comments
 (0)