Now Reading
Deep Learning Model For Bank Crisis Prediction

Deep Learning Model For Bank Crisis Prediction

Dr. Vaibhav Kumar
deep neural network for bank crisis prediction
W3Schools

Deep learning is becoming popular day-by-day with the increasing attention towards data as various types of information have the potential to answer the questions which are unanswered till now. There are a variety of other machine learning algorithms, which can be used to find insights from the data. But, with the rapid increase in the size of data and a competition to find more accurate results, it is giving a reason for the popularity of deep learning methods. The financial sector has been using machine learning techniques for a long time in order to gain business growth through higher profit. Credit card fraud detection, stock market prediction, among others, are some of the popular machine learning approaches in this sector, which the companies have actively adopted to streamline their business operations. 

In this article, we will discuss a deep learning technique — deep neural network — that can be deployed for predicting banks’ crisis. This experiment is based on the African economic, banking and systemic crisis data where inflation, currency crisis and bank crisis of 13 African countries between 1860 to 2014 is given. By predicting through a deep learning model, we will see that this model gives a high accuracy in this task.

Deep Learning

Deep learning belongs to the family of machine learning, a broad field of artificial intelligence. It is generally based on artificial neural networks with representation learning, a technique that automatically discovers feature representations from raw data. It is inspired by the biological process of neural networks and has proved its advantage over traditional machine learning algorithms in many applications. With the increase in the size of data, or with the developments in the field of big data, conventional machine learning techniques have shown their limitation in analysis with a colossal amount of data.



Deep learning became mainstream due to the need for unveiling insights into a plethora of data that companies started collecting. The term ‘Deep’ means the increased layers of learning as compared to the traditional machine learning algorithms. It uses multiple layers that are a composition of multiple linear and non-linear transformations. It attempts to model a high-level abstraction in data based on a set of algorithms.There are many deep learning models developed by researchers, which deliver better learning from the representation of large-scale unlabeled data. Some popular deep learning architectures like Convolutional Neural Networks (CNN), Deep Neural Networks (DNN), Deep Belief Network (DBN) and Recurrent Neural Networks (RNN) are applied as predictive models in the domains of computer vision and predictive analytics in order to find insights from data. In this article, the deep neural network has been used to predict the banking crisis. So, let us see the brief introduction to the deep neural network.

Deep Neural Network

A deep neural network is a variant of an artificial neural network having multiple hidden layers between the input layer and the output layer. The number of neurons may be similar or different in each of the hidden layers. It finds the mathematical manipulation to obtain output from the input, whether it is a linear or non-linear relationship. This model is generally preferred to model the complex non-linear relationships between input and output. The algorithm of this model moves across the layers and obtains the probability of each output. A user then assigns a class label based on the obtained probabilities in case of a classification problem.

The architecture of this model devises a compositional model in which the object is referred to as the layered composition of primitives. It has the capability to model complex non-linear relationships in the training data. The benefit of using extra hidden layers in the network enables the composition of features from lower layers. These features potentially model complex data with fewer units. Below is an architecture of a deep neural network where we can see that there are multiple hidden layers between the input layer and the output layer.

deep neural network

Bank Crisis Prediction

Every banking institution tries to find out the future performance in order to take corrective measures at an early stage in case of any probable crisis in future. An investor looking to invest in the banking stocks tries to ensure that there won’t be any issue in future with its investment. The chances of such a potential crisis may be predicted by machine learning algorithms based on several available attributes in its dataset. There may be a variety of datasets available for this task. But finding the right set of attributes that can really impact the prediction result is a challenge. Nevertheless, on the basis of a few key indicators, it has been predicted whether there will be a crisis in the banking system given that high inflation and crisis in the currency segment.

The Dataset

In this work, we took African Economic, Banking and Systemic Crisis Data for the experiment. This dataset is publicly available on Kaggle. This is the data on the economic and financial crisis in 13 African countries between 1869 to 2014. This dataset contains 14 attributes of 1060 observations, i.e. 1060 x 14 is enough data to train a deep learning model for accurate prediction. The set of attributes includes US dollar exchange rate, information of several default measures, inflation to annual CPI, among others, which are the key indicators that affect the banking and economic system of any country. The last attribute of the dataset contains categorical values, whether there was a crisis or no crisis. So, on the basis of input attributes, the deep neural network will predict whether there will be a banking crisis or not.

Deep Neural Network For Prediction

To implement this model, make sure that you have installed the TensorFlow. The Keras library will use TensorFlow as a backend. Now, we will implement the deep neural network for bank crisis prediction. Follow the below steps:

1.Importing the libraries:

import pandas as pd
import numpy as np
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
import seaborn as sns
from keras.models import Sequential
from keras.layers import Dense
import matplotlib.pyplot as plt
from matplotlib import *
import sys
from pylab import *

2. Reading the dataset:

df = pd.read_csv('african_crises.csv')

3. Printing the columns of the dataset

for col in df.columns: 
   print(col)

Output:
case
cc3
country
year
systemic_crisis
exch_usd
domestic_debt_in_default
sovereign_external_debt_default
gdp_weighted_default
inflation_annual_cpi
independence
currency_crises
inflation_crises
banking_crisis

4. Preprocessing the data:

df['banking_crisis'] = df['banking_crisis'].replace('crisis',np.nan)
df['banking_crisis'] = df['banking_crisis'].fillna(1)
df['banking_crisis'] = df['banking_crisis'].replace('no_crisis',np.nan)
df['banking_crisis'] = df['banking_crisis'].fillna(0)
df.drop(['cc3','country'], axis=1, inplace=True)


5. Feature scaling of the data

df_scaled = preprocessing.scale(df)
df_scaled = pd.DataFrame(df_scaled, columns=df.columns)
df_scaled['banking_crisis'] = df['banking_crisis']
df = df_scaled


6. Defining input and output attributes

X = df.loc[:,df.columns != 'banking_crisis']
y = df.loc[:, 'banking_crisis']

7. Splitting the dataset into the Training set and Test set

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

8. Defining the deep neural network Model (We can add more hidden layers in order to check whether it increases the accuracy or not. The hyperparameters in the below functions can be tuned for to improve the accuracy.)

# Initialising the ANN
classifier = Sequential()
# Adding the input layer and the first hidden layer
classifier.add(Dense(output_dim = 32, init = 'uniform', activation = 'sigmoid', input_dim = 11))
# Adding the second hidden layer
classifier.add(Dense(output_dim = 32, init = 'uniform', activation = 'sigmoid'))
# Adding the third hidden layer
classifier.add(Dense(output_dim = 8, init = 'uniform', activation = 'sigmoid'))
# Adding the output layer
classifier.add(Dense(output_dim = 1, init = 'uniform', activation = 'sigmoid'))
# Compiling the ANN
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
#Fitting the model
classifier.fit(X_train, y_train, epochs=200)


9. Scoring of model on training and test data

See Also

scores = classifier.evaluate(X_train, y_train)
print ("Training Accuracy: %.2f%%\n" % (scores[1]*100))
scores = classifier.evaluate(X_test, y_test)
print ("Testing Accuracy: %.2f%%\n" % (scores[1]*100))

10. Predicting the results by deep neural network

y_pred = classifier.predict_classes(X_test)

11. Plotting the confusion matrix

cm = confusion_matrix(y_test, y_pred)
labels = ['No Banking Crisis', 'Banking Crisis']
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111)
cax = ax.matshow(cm)
plt.title('Confusion matrix of the DNN Classifier')
fig.colorbar(cax)
ax.set_xticklabels([''] + labels)
ax.set_yticklabels([''] + labels)
plt.xlabel('Predicted')
plt.ylabel('True')
plt.show()

Binding all of the above together:

#importing Libraries
import pandas as pd
import numpy as np
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
import seaborn as sns
from keras.models import Sequential
from keras.layers import Dense
import matplotlib.pyplot as plt
from matplotlib import *

#Reading dataset, here, the african bank crisis data is used in this experiment
df = pd.read_csv('african_crises.csv')

#Data preprocessing
df['banking_crisis'] = df['banking_crisis'].replace('crisis',np.nan)
df['banking_crisis'] = df['banking_crisis'].fillna(1)
df['banking_crisis'] = df['banking_crisis'].replace('no_crisis',np.nan)
df['banking_crisis'] = df['banking_crisis'].fillna(0)
df.drop(['cc3','country'], axis=1, inplace=True)

#View columns in the dataset
for col in df.columns:
print(col)

#Scaling of data
df_scaled = preprocessing.scale(df)
df_scaled = pd.DataFrame(df_scaled, columns=df.columns)
df_scaled['banking_crisis'] = df['banking_crisis']
df = df_scaled

#Defiing input and output attributes
X = df.loc[:,df.columns != 'banking_crisis']
y = df.loc[:, 'banking_crisis']

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)


#Defining the Deep Neural Network Model
# Initialising the ANN
classifier = Sequential()
# Adding the input layer and the first hidden layer
classifier.add(Dense(output_dim = 32, init = 'uniform', activation = 'sigmoid', input_dim = 11))
# Adding the second hidden layer
classifier.add(Dense(output_dim = 32, init = 'uniform', activation = 'sigmoid'))
# Adding the fourth hidden layer
classifier.add(Dense(output_dim = 8, init = 'uniform', activation = 'sigmoid'))
# Adding the output layer
classifier.add(Dense(output_dim = 1, init = 'uniform', activation = 'sigmoid'))
# Compiling the ANN
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
#Fitting the model
classifier.fit(X_train, y_train, epochs=200)


#Scoring of model on training and test data
scores = classifier.evaluate(X_train, y_train)
print ("Training Accuracy: %.2f%%\n" % (scores[1]*100))
scores = classifier.evaluate(X_test, y_test)
print ("Testing Accuracy: %.2f%%\n" % (scores[1]*100))

#Plotting the confusion matrix
from sklearn.metrics import confusion_matrix
import sys
from pylab import *
y_pred = classifier.predict_classes(X_test)
cm = confusion_matrix(y_test, y_pred)
labels = ['No Banking Crisis', 'Banking Crisis']
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111)
cax = ax.matshow(cm)
plt.title('Confusion matrix of the DNN Classifier')
fig.colorbar(cax)
ax.set_xticklabels([''] + labels)
ax.set_yticklabels([''] + labels)
plt.xlabel('Predicted')
plt.ylabel('True')
plt.show()

The below screenshot shows the training and testing accuracy scores of the deep neural network model

Deep Neural Network Training Loss

The below plot of a confusion matrix shows the classification (predicting bank crisis) by the deep neural network.

deep neural network confusion matrix

(Also Read: Singular Value Decomosition and Its Application in Recommneder System)

What Do You Think?

If you loved this story, do join our Telegram Community.


Also, you can write for us and be one of the 500+ experts who have contributed stories at AIM. Share your nominations here.

Copyright Analytics India Magazine Pvt Ltd

Scroll To Top