Database Reference
In-Depth Information
What about the other models? Let's compute the accuracy for the other three:
val svmTotalCorrect = data.map { point =>
if (svmModel.predict(point.features) == point.label) 1
else 0
}.sum
val nbTotalCorrect = nbData.map { point =>
if (nbModel.predict(point.features) == point.label) 1
else 0
}.sum
Note that the decision tree prediction threshold needs to be specified explicitly, as high-
lighted here:
val dtTotalCorrect = data.map { point =>
val score = dtModel.predict(point.features)
val predicted = if ( score > 0.5 ) 1 else 0
if (predicted == point.label) 1 else 0
}.sum
We can now inspect the accuracy for the other three models.
First, the SVM model:
val svmAccuracy = svmTotalCorrect / numData
Here is the output for the SVM model:
svmAccuracy: Double = 0.5146720757268425
Next, our naïve Bayes model:
val nbAccuracy = nbTotalCorrect / numData
The output is as follows:
nbAccuracy: Double = 0.5803921568627451
Finally, we compute the accuracy for the decision tree:
val dtAccuracy = dtTotalCorrect / numData
Search WWH ::




Custom Search