Build a Neural Network in Python (Binary Classification)

This is a cheat sheet for me to copy the code when I need it!

Luca Chuang
Luca Chuang’s BAPM notes
1 min readOct 1, 2020

--

Set up the environment

Import modules that we are going to use

Set our data

We use Titanic: Machine Learning from Disaster as the example dataset

  • Read the dataset
  • Deal with the missing value
  • Recode variables
  • Check distribution of target variable

Prepare data for modeling

  • Split the data(X,y)
  • Convert to NumPy array

Build, Compile, Fit model

  • Use the Sequential API to build your model
  • Specify an optimizer (rmsprop or Adam)
  • Set a loss function (binary_crossentropy)
  • Fit the model (make a new variable called ‘history’ so you can evaluate the learning curves)
  • EarlyStopping callbacks to prevent overfitting (patience of 10)

Evaluate the Model

  • Learning curves (Loss)
  • Learning curves (Accuracy)
  • Confusion matrix

--

--