Classification with a multilayer perceptron

We can now build an architecture with two dense layers and train a classifier for a more complex dataset. Let's start by creating it:

from sklearn.datasets import make_classificationnb_samples = 1000nb_features = 3X, Y = make_classification(n_samples=nb_samples, n_features=nb_features,                            n_informative=3, n_redundant=0, n_classes=2, n_clusters_per_class=3)

Even if we have only two classes, the dataset has three features and three clusters per class; therefore, it's almost impossible that a linear classifier can separate it with very high accuracy. A plot of the dataset is shown in the following graph:

Three-dimensional representation of the dataset

For benchmarking purposes, it's useful to test a ...

Get Machine Learning Algorithms - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.