How it works...

In this recipe, we demonstrated usage of a multilayer perceptron classifier. We began by loading the classic Iris dataset in libsvm format. Next, we split the dataset with a ratio of 80% for training set data and 20% for test set data. In our definition phase, we configured the multilayer perceptron classifier with an input layer of four nodes, a hidden layer of five nodes, and a four-node layer for output. We generated a trained model by invoking the fit() method, and then produced predictions utilizing the trained model.

Finally, we retrieved predictions and labels, passing them to the multi-class classification evaluator that computes an accuracy value.

A simple visual inspection of predicted versus actual without much ...

Get Apache Spark 2.x Machine Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.