O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating predictions for the Kaggle/StumbleUpon evergreen classification dataset

We will use our logistic regression model as an example (the other models are used in the same way):

val dataPoint = data.first val prediction = lrModel.predict(dataPoint.features) 

The following is the output:

prediction: Double = 1.0  

We saw that, for the first data point in our training dataset, the model predicted a label of 1 (that is, evergreen). Let's examine the true label for this data point.

val trueLabel = dataPoint.label 

You can see the following output:

trueLabel: Double = 0.0  

So, in this case, our model got it wrong!

We can also make predictions in bulk by passing in an RDD[Vector] as input:

 val predictions = lrModel.predict(data.map(lp ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required