August 2017
Beginner to intermediate
340 pages
8h 42m
English
The missing value handling step is easy, since we already performed missing value exploration and summarized the required transformations in the previous section. The following steps are going to implement them.
First, we define a list of imputed values - for each column, we assign a single Double value:
val imputedValues = columnNames.map {
_ match {
case "hr" => 60.0
case _ => 0.0
}
}
And a function which allow us to inject the values into our dataset:
import org.apache.spark.rdd.RDD
def imputeNaN(
data: RDD[Array[Double]],
values: Array[Double]): RDD[Array[Double]] = {
data.map { row =>
row.indices.map { i =>
if (row(i).isNaN) values(i)
else row(i)
}.toArray
}
}
The defined function accepts a Spark RDD where each row is ...
Read now
Unlock full access