Throughout this book, we've on giving ready-to-use for real-world problems. For some relatively simple tasks, a simple neural network can provide a good-enough solution to a problem. In this recipe, we'll demonstrate how straightforward it can be to implement a shallow neural network for binary classification in Keras.
- Start with importing all libraries as follows:
import numpy as np import pandas as pd from sklearn.preprocessing import LabelEncoder from keras.models import Sequential from keras.layers import Dense from keras.callbacks import EarlyStopping
- Next, we load the dataset:
dataframe = pandas.read_csv("Data/sonar.all-data", header=None) data = dataframe.values
- Let's split the labels from the features:
X = data[:,0:60].astype(float) y = data[:,60]
- Currently, the labels are strings. We need to binarize them for our network:
encoder = LabelEncoder() encoder.fit(y) y = encoder.transform(y)
- Let's define a simple network...