TensorFlow 1.x Deep Learning Cookbook
上QQ阅读APP看书,第一时间看更新

There's more...

We can use the TensorFlow control ops and tensor manipulations that we covered in the first chapter to preprocess the data. For example, in the case of Boston house price, there are about 16 data rows where the MEDV is 50.0. In most probability, these data points contain missing or censored values and it would be advisable not to consider them for the training. We can remove them from the training dataset with the following code:

condition = tf.equal(data[13], tf.constant(50.0))
data = tf.where(condition, tf.zeros(NUM_FEATURES), data[:])

Here, we first define a tensor boolean condition, which will be true if MEDV is equal to 50.0. Then we use TensorFlow tf.where() Op to assign all zeros if the condition is true.