aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/examples/get_started
diff options
context:
space:
mode:
authorGravatar Mark Daoust <markdaoust@google.com>2017-09-20 10:21:25 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-09-20 10:24:52 -0700
commit2a4ddfb229a6b890624792fff630cc71a33ce71d (patch)
tree9e0819e060d7c9ffaecf6eb6fdb4d6877d424397 /tensorflow/examples/get_started
parent48bb9403da140a3ed09e70f5f12db8b880ff889f (diff)
Switch regression examples to use units of 1000$
PiperOrigin-RevId: 169411781
Diffstat (limited to 'tensorflow/examples/get_started')
-rw-r--r--tensorflow/examples/get_started/regression/dnn_regression.py11
-rw-r--r--tensorflow/examples/get_started/regression/imports85.py2
-rw-r--r--tensorflow/examples/get_started/regression/linear_regression.py13
-rw-r--r--tensorflow/examples/get_started/regression/linear_regression_categorical.py11
4 files changed, 32 insertions, 5 deletions
diff --git a/tensorflow/examples/get_started/regression/dnn_regression.py b/tensorflow/examples/get_started/regression/dnn_regression.py
index 7aa3659139..951c93b52e 100644
--- a/tensorflow/examples/get_started/regression/dnn_regression.py
+++ b/tensorflow/examples/get_started/regression/dnn_regression.py
@@ -23,6 +23,7 @@ import tensorflow as tf
import imports85 # pylint: disable=g-bad-import-order
STEPS = 5000
+PRICE_NORM_FACTOR = 1000
def main(argv):
@@ -30,6 +31,13 @@ def main(argv):
assert len(argv) == 1
(train, test) = imports85.dataset()
+ # Switch the labels to units of thousands for better convergence.
+ def normalize_price(features, labels):
+ return features, labels / PRICE_NORM_FACTOR
+
+ train = train.map(normalize_price)
+ test = test.map(normalize_price)
+
# Build the training input_fn.
def input_train():
return (
@@ -86,7 +94,8 @@ def main(argv):
# Convert MSE to Root Mean Square Error (RMSE).
print("\n" + 80 * "*")
- print("\nRMS error for the test set: ${:.0f}".format(average_loss**0.5))
+ print("\nRMS error for the test set: ${:.0f}"
+ .format(PRICE_NORM_FACTOR * average_loss**0.5))
print()
diff --git a/tensorflow/examples/get_started/regression/imports85.py b/tensorflow/examples/get_started/regression/imports85.py
index 41e77222ce..c165f0175d 100644
--- a/tensorflow/examples/get_started/regression/imports85.py
+++ b/tensorflow/examples/get_started/regression/imports85.py
@@ -91,7 +91,7 @@ def dataset(y_name="price", train_fraction=0.7):
"""Convert a csv line into a (features_dict,label) pair."""
# Decode the line to a tuple of items based on the types of
# csv_header.values().
- items = tf.decode_csv(line, defaults.values())
+ items = tf.decode_csv(line, list(defaults.values()))
# Convert the keys and items to a dict.
pairs = zip(defaults.keys(), items)
diff --git a/tensorflow/examples/get_started/regression/linear_regression.py b/tensorflow/examples/get_started/regression/linear_regression.py
index dd44077663..74651e7446 100644
--- a/tensorflow/examples/get_started/regression/linear_regression.py
+++ b/tensorflow/examples/get_started/regression/linear_regression.py
@@ -24,6 +24,7 @@ import tensorflow as tf
import imports85 # pylint: disable=g-bad-import-order
STEPS = 1000
+PRICE_NORM_FACTOR = 1000
def main(argv):
@@ -31,6 +32,13 @@ def main(argv):
assert len(argv) == 1
(train, test) = imports85.dataset()
+ # Switch the labels to units of thousands for better convergence.
+ def to_thousands(features, labels):
+ return features, labels / PRICE_NORM_FACTOR
+
+ train = train.map(to_thousands)
+ test = test.map(to_thousands)
+
# Build the training input_fn.
def input_train():
return (
@@ -67,7 +75,8 @@ def main(argv):
# Convert MSE to Root Mean Square Error (RMSE).
print("\n" + 80 * "*")
- print("\nRMS error for the test set: ${:.0f}".format(average_loss**0.5))
+ print("\nRMS error for the test set: ${:.0f}"
+ .format(PRICE_NORM_FACTOR * average_loss**0.5))
# Run the model in prediction mode.
input_dict = {
@@ -85,7 +94,7 @@ def main(argv):
"Highway: {: 0d}mpg, "
"Prediction: ${: 9.2f}")
msg = msg.format(input_dict["curb-weight"][i], input_dict["highway-mpg"][i],
- prediction["predictions"][0])
+ PRICE_NORM_FACTOR * prediction["predictions"][0])
print(" " + msg)
print()
diff --git a/tensorflow/examples/get_started/regression/linear_regression_categorical.py b/tensorflow/examples/get_started/regression/linear_regression_categorical.py
index 38ecfada9d..860d0e437c 100644
--- a/tensorflow/examples/get_started/regression/linear_regression_categorical.py
+++ b/tensorflow/examples/get_started/regression/linear_regression_categorical.py
@@ -23,6 +23,7 @@ import tensorflow as tf
import imports85 # pylint: disable=g-bad-import-order
STEPS = 1000
+PRICE_NORM_FACTOR = 1000
def main(argv):
@@ -30,6 +31,13 @@ def main(argv):
assert len(argv) == 1
(train, test) = imports85.dataset()
+ # Switch the labels to units of thousands for better convergence.
+ def normalize_price(features, labels):
+ return features, labels / PRICE_NORM_FACTOR
+
+ train = train.map(normalize_price)
+ test = test.map(normalize_price)
+
# Build the training input_fn.
def input_train():
return (
@@ -91,7 +99,8 @@ def main(argv):
# Convert MSE to Root Mean Square Error (RMSE).
print("\n" + 80 * "*")
- print("\nRMS error for the test set: ${:.0f}".format(average_loss**0.5))
+ print("\nRMS error for the test set: ${:.0f}"
+ .format(PRICE_NORM_FACTOR * average_loss**0.5))
print()