jduff1075
jduff1075

Reputation: 410

Spark (1.6) ML Linear Regression - how to predict w/ a model

I have a working linear regression model:

lrModel
org.apache.spark.ml.regression.LinearRegressionModel

and I have data in a dataframe:

data
org.apache.spark.sql.DataFrame = [label: double, features: vector]

How do I use the model to predict? in my case, I want to do something like:

lrModel.predict(data)  // which doesn't work

then compare the expected value (label) to the predicted value

Upvotes: 3

Views: 490

Answers (1)

Alberto Bonsanto
Alberto Bonsanto

Reputation: 18022

To predict you need to have a Dataframe, and convert it using the transform method which is part of all ML Models. Note that all of them require DataFrames to have the same structure of your training data, hence a fetures column.

Upvotes: 1

Related Questions