I have a LinearRegression
model trained on historical data, now I am trying to re-use the same model on the new data to make predictions.
I know that we can save and load model using model.save
and LinearRegression.load
methods respectively, however, I am unable to find a way to pass in new data to loaded model for predictions.
Code for creating and training model is pasted below:
val assembler = new VectorAssembler().setInputCols(Array("total", "connected", "c_403", "c_480", "c_503", "hour", "day_of_week")).setOutputCol("features")
val output = assembler.transform(df).select($"label", $"features")
val Array(training, test) = output.select("label", "features").randomSplit(Array(0.7, 0.3), seed = 12)
val lr = new LinearRegression()
val paramGrid = new ParamGridBuilder().addGrid(lr.regParam, Array(0.1, 0.01)).addGrid(lr.fitIntercept).addGrid(lr.elasticNetParam, Array(0.0, 0.25, 0.5, 0.75, 1.0)).build()
val trainvalSplit = new TrainValidationSplit().setEstimator(lr).setEvaluator(new RegressionEvaluator()).setEstimatorParamMaps(paramGrid).setTrainRatio(0.75)
val model = trainvalSplit.fit(training)
val holdout = model.transform(test).select("prediction","label")