Transforming a Leap Frame

    1. // Create our one hot encoder
    2. val oneHotEncoder = OneHotEncoder(shape = NodeShape.vector(1, 2,
    3. inputCol = "a_string_index",
    4. outputCol = "a_string_oh"),
    5. model = OneHotEncoderModel(2, dropLast = false))
    6. // Assemble some features together for use
    7. // By our linear regression
    8. val featureAssembler = VectorAssembler(
    9. shape = NodeShape().withInput("input0", "a_string_oh").
    10. model = VectorAssemblerModel(Seq(TensorShape(2), ScalarShape())))
    11. // Create our linear regression
    12. // It has two coefficients, as the one hot encoder
    13. // Outputs vectors of size 2
    14. val linearRegression = LinearRegression(shape = NodeShape.regression(3),
    15. model = LinearRegressionModel(Vectors.dense(2.0, 3.0, 6.0), 23.5))
    16. // Create a pipeline from all of our transformers
    17. val pipeline = Pipeline(
    18. // Transform our leap frame using the pipeline
    19. val predictions = (for(lf <- pipeline.transform(leapFrame);
    20. lf2 <- lf.select("prediction")) yield {
    21. lf2.dataset.map(_.getDouble(0))
    22. }).get.toSeq
    23. // Print our predictions
    24. // > 365.70000000000005
    25. println(predictions.mkString("\n"))