Keras Basic Neural Network

Keras supports a range of neural networks. Basic neural network is a standard structure of a layers followed by other layers.


  • hidden_layers = a tuple defining the number of neurons per hidden layer. default is (100,) which means one hidden layer of 100 neurons. (100, 100) would mean two hidden layers of 100 neurons.
  • activation_fn = the activation function used in the neurons. Default is "relu". Other activation functions include: {‘identity’, ‘logistic’, ‘tanh’, ‘relu’, 'elu', 'leaky relu'}
  • solver = This is the type of algorithm used for the gradient descent. Default is "adam", other choices include: {‘lbfgs’, ‘sgd’, ‘adam’}
  • alpha = The L2 regularization penalty, default is: 0.0001
  • n_classes = Number of input variables being fed into the neural network
  • first_layer = Number of nodes in the first layer of the neural network
  • dropout_option = Default is False. If set to True, 50% of the nodes in each layer will be randomly frozen. This is to reduce the amount of reliance each node has on each other.

Practical Example

from deployml.keras import NeuralNetworkBase

# We define the model with the number of inputs which is the number 
# of keys minus one as one will be the outcome. First layer also 
# the same number but it doesn't have to be
NN = NeuralNetworkBase(hidden_layers=(4, 4),

# We define the data (pandas data frame) = input_data

# We define the key of the column we are trying to predict
NN.outcome_pointer = 'attended'

# Now we've defined the network we produce a training curve 
# and show it with scaled data using a standard scaler
NN.train(scale=True, batch_size=100)

# We then print out the precision, recall and F-1 score 

# And show the ROC curve 

Not Enough?

It's understandable that you might want a more custom model. Whilst we are always working on making Deploy-ML more versatile, you can define your own Keras model and import it into the Deploy-ML learning and packaging framework!