An Introduction to Keras

An Introduction to Keras

Keras is a python library implementation that provides a high-level neural networks API. It supports deep learning network implementations like TensorFlow, CNTK or Theano. Keras also support CPU and GPU based processing.

In order to understand what Keras is, we have to understand the following

  1. Models :- Mathematical Model
  2. Model Layers:- Neural Network Layers
  3. Model Input :- Training and Testing Data
  4. Model Output :- Data Predictions.

What is the role of a Model in Deep Learning?

A model can be compared to an object class, except the fact that a model has a learning algorithm and trainable.

Some examples of Machine Learning Models or ML models are given below and their common application

Binary Classification Model

  • uses a logistic regression algorithm
  • predict a binary outcome (one of two possible classes)

Examples of Binary Classification Problems

  • “Is this email spam or not spam?”
  • “Will the customer buy this product?”
  • “Is this product a book or a farm animal?”
  • “Is this review written by a customer or a robot?”


Multiclass classification model

  • generate predictions for multiple classes (predict one of more than two outcomes)
  • multinomial logistic regression

Examples of Multiclass Problems

  • “Is this product a book, movie, or clothing?”
  • “Is this movie a romantic comedy, documentary, or thriller?”
  • “Which category of products is most interesting to this customer?”

Regression model

regression problems predict a numeric value

linear regression algorithm

Examples of Regression Problems

  • “What will the temperature be in Seattle tomorrow?”
  • “For this product, how many units will sell?”
  • “What price will this house sell for?”

What is a layer in model deep learning?

A neural network is built on a stack of layers, where each layer comprises of nodes and connections. Each connection has weight. The stack of layers forms an ML model. When data input is given to the model, the ML algorithm determines weight in connections and nodes and self-learn the pattern. As more and more layers come in, the model gets trained closer to accurate predictions.

In a simplistic way, an ML Model reads data and learn by building neural networks and will be able to predict data output based on what it learned.

What type of models does Keras Support?

Keras support Sequential Models. It also provides you with a model class which you can use to extend Sequential models to highly complex models.

The Sequential model is a linear stack of layers.

What is the life cycle of Keras Models?

Keras have a 5 state life cycle.

  1. Model Definition: The Model definition is the process by which a model is created in Keras. It can be compared to as a creation of an Object class, with a set of constructors that set the stage for model depending on data that is going to be fed with it. There is where you decide the number of layers the model should have, size of data, type of algorithm to use and so on.
  2. Model Network Compilation: After a model is defined, which is nothing but a loose set of instructions, it is compiled to a mathematical model of highly efficient series of matrix transforms depending on the underlying hardware. In keras its done with a simple function call model.compile()
  3. Model Data Fitting / Optimization: This is where we first start to feed our training data to the model. A training data set will contain an array of input patterns and matching output patterns.
  4. Model Testing / Evaluation: A set of testing data is provided to the model which was not previously provided during model fitting, to test performance and accuracy.
  5. Model Prediction: Once Testing is completed, a model can be used to predict outputs for a given input x simply by calling model.predict(x)


Phone: 512-539-0390
NJ Training Academy Inc , 405 Dry Gulch Bend
Cedar Park, Texas, 78613