Scorecard : Data Visualization – Banking Case

Scorecard : Data Visualization – Banking Case

标签(空格分隔): Scorecard


Microsoft Excel – use Secondary Axis to Create Two Y Axes

Analytics Lab

Malcolm Gladwell in his book ‘Outliers‘ says that it takes approximately 10,000 hours of training or practice for anybody to master a subject. There is nothing in the world that could beat hands-on practice for learning. Keeping this in mind let me start a new series on YOU CANalytics called ‘Analytics Lab’ where we will practice some of the case studies we have discussed in the past on YOU CANalytics. We will use R and Microsoft Excel (both easily available tools) for this.

It’s a bird…It’s a plane…It’s Excel man! Did I ever tell you what a super hero Excel is. In my opinion Excel is the best tool to start learning advanced analytics! Today we will start the ‘Analytics Lab’ using concepts we have discussed in the banking case study. This time we will create a two Y axes plot by using the secondary axis function in Excel. In the next article we will create the same plot on R.

Banking Case

Recall the banking case: in that you were playing the role of the Chief Risk Officer (CRO) for CyndiCat bank. The bank had disbursed 60816 auto loans in the quarter between April–June 2012. Additionally, you had noticed around 2.5% of overall bad rate for these loans. The idea was to identify customer segments with distinct bad rates. Bad rate, by the way, is percentage of customer defaulted on their payments. You did some exploratory data analysis (EDA) using tools of data visualization and found a relationship between age with bad rates (Part 1). If you recall, you have observed the following age groups wise population histogram and bad rate trend.

Presentation1

Using Secondary Axis to Create Two Y Axes in Excel

A good practice is to present these two graphs in a single chart. This is useful because you and your audience don’t need to jump from one graph to another during analysis. Let me present the data we are going to use for our purpose. I recommend you copy past this data on Excel and evaluate for yourself the merits of a single chart in comparison to two.

Age Groups Number of Loans Bad Loans Good Loans Bad Rate
21-24 310 14 296 4.5%
24-27 511 20 491 3.9%
27-30 4000 172 3828 4.3%
30-33 4568 169 4399 3.7%
33-36 5698 188 5510 3.3%
36-39 8209 197 8012 2.4%
39-42 8117 211 7906 2.6%
42-45 9000 216 8784 2.4%
45-48 7600 152 7448 2.0%
48-51 6000 84 5916 1.4%
51-54 4000 64 3936 1.6%
54-57 2000 26 1974 1.3%
57-60 788 9 779 1.1%

The last column i.e. ‘Bad Rate’ is the percentage of ‘Bad Loans’ to ‘Number of Loans’ i.e. for the age group 21-24 it is 14/310=4.5%.

Slide1

The first thing you need to do is create a bar plot of the first two columns i.e. ‘Age Groups’ and ‘Number of Loans’. Use Column in Charts within Insert tab (as shown above) to create a vertical bar plot. The default excel bar plot will look different. I have done some additional formatting for the bar plot to make it appropriate for my purpose. You could leave the default excel format for most part. The only thing you want to change is the color of the bars from default excel blue to something mellow like grey.

Slide3

The next step is to add the trend line for the last column i.e. ‘Bad Rate’ on top of the above chart. For this, right click you mouse anywhere on top of the above bar chart in Excel and then choose Select Data… You will notice a pop up window similar to the one shown below

Slide4

In the above pop-up window click on Add below Legend Entries (Series). You will get a new pop-up window similar to the one shown below. For series name choose the cell $E$1 (the cell that contain the name ‘Bad Loans’) and for series values select cells $E$2 to $E$14 i.e. the values of ‘Bad Rate’ for all the ‘Age Groups’.

Slide5

Once you will click OK in the above Edit Series pop-up window, you will get additional bars for ‘Bad Loans’. Notice, these bars are really tiny in comparison to ‘Number of Loans’ bars.

![Presentation4(https://i1.wp.com/ucanalytics.com/blogs/wp-content/uploads/2014/05/Presentation4.jpg)

Select any of these tiny bars for ‘Bad Rate’ by a mouse click. Then right click your mouse and choose Format Data Series… You will see a pop-up window similar to the one shown below.

Slide6

In the Plot Series On section choose Secondary Axis and press Close in the pop-up window. You will get a bar plot similar to the one shown below. Notice the secondary Y Axis at the right side of the plot with ‘Bad Rate’. Remember, I have re-formatted the default Excel plot so your plot will have different appearance. Now we are left with just one final thing.

Presentation2

We need to now convert the above orange bars for ‘Bad Rate’ to a line plot. This is really simple, click on the orange ‘Bad Rate’ bars and convert them to line by choosing **Line ** in Charts from Insert tab

Slide2
Presentation3

Great! We are done. You might appreciate how useful it is to present these two plots in one single chart with 2 Y axes or the secondary axis in Excel. In the above chart, it is much easier to see where you have thinner data and modify your bad rates accordingly. Now, you could easily create coarse classes as discussed in the banking case study.

2 Axes Risk Plots in R

Analytics Lab – R

Welcome back to Analytics Lab on YOU CANalytics! In our last article, we learned the procedure to visualize risk across a parameter (age groups) in Excel. In this part we will generate the same visualization in R. This lab exercise is a part of the banking case study we have previously worked on (you will find links to the banking case series at the bottom of this article).

Banking Case Study

Recall the banking case: in that you were playing the role of the Chief Risk Officer (CRO) for CyndiCat bank. The bank had disbursed 60816 auto loans in the quarter between April–June 2012. Additionally, you had noticed around 2.5% of overall bad rate for these loans. The idea was to identify customer segments with distinct bad rates. Bad rate, by the way, is percentage of customer defaulted on their payments. You did some exploratory data analysis (EDA) using tools of data visualization and found a relationship between age with bad rates Part 1. If you recall, in the previous article we have generated the following plot on Excel. The plot collectively depicts age groups wise population distribution and bad rate trend. As mentioned above this time we will create a similar plot on R.

Presentation3

Pep Talk before Jumping into R

If this is the first time you are using R & R studio then don’t get intimidated with this brilliant tool for analysis – you will love it once you get familiar with it. R is a language and computing environment for statistics, analysis, data mining, and graphics. If you have used Excel functions (such as =vlookup(), =sum() etc.) then you will find R commands / functions somewhat similar.

R & R Studio

First of all (if you don’t have R and R Studio), you need to download R (link) and R Studio (link) from the given links and install them on your computer. By the way R Studio is an excellent free editor to work with R language. You will find good documentation for R Studio at this link. Additionally you will need the following CVS (data) file to work on this example.

click on the link to download the file

Moreover, you can find the entire R code in the following text file. But wait and read on before you check out this text file.

data<-read.csv("YOU CANalytics R Visualization.csv") #change the directory name#
x <- data$Age.Group
y1 <- data$Number.of.Loans
y2 <- data$Bad.Rate
par(mar=c(5,5,2,5)+.1)
barplot(y1,col="grey",border=0,names.arg=x,angle=45,xlab="Age Groups",ylab="Number of Loans",cex.lab=1.7, cex.main=1.7, cex.sub=1.7,cex.axis=1.2,cex.names=1.2)
par(new=TRUE)
plot(y2,type="l",col="Orange",lwd=5,xlab="",ylab="",xaxt="n",yaxt="n")
axis(4,cex.axis=1.2)
mtext("Bad Rate",side=4,line=3,cex=1.7)
legend("topright",col=c("orange"),lty=1,lwd=5,legend=c("Bad Rate"),cex=1.25)

R Coding

I recommend that you copy and paste the individual lines of code given below in R Studio console (located at the bottom left of R Studio panel as highlighted in the below picture), and execute them one-by-one. In R (unlike C, Java, and other similar languages) one doesn’t need to compile the entire code to produce results – each command in R is executed independently.

R Studio

The first line of the code is importing or reading the CVS file in the R environment. You will need to modify the path of the CVS file based on the location of the file on your computer. The extracted CVS file is named ‘data’ in the R environment.

data<- read.csv("YOU CANalytics Visualization R.csv")

Now in the next three lines of code we are going to assign variable names x, y1 and y2 to ‘Age Groups’, ‘Number of Loans’, and ‘Bad Rate’. These three variables are present in the ‘data’ file. Also, you could view this data in R using the command View(data)

x <- data$Age.Group
y1 <- data$Number.of.Loans
y2 <- data$Bad.Rate

‘Par’ function in R is used to realign plots. In this case mar operator is used to realign margins in the subsequent plot(s). You should play around with the numbers in the function to see the change in the plot, although you will see the impact of this command after you plot the bar plot through the next line of code. By changing the values inside ‘c()’ plots will move according to c(bottom, left, top, right) on the graph canvas.

par(mar = c(5,5,2,5) +.1)

Now, we will plot our first bar plot using barplot function. Notice you could create a bare bones bar plot using this command barplot(y1, names.arg=x). The other arguments within the barplot function in the following command are used to produce cosmetic effects in the plot. I recommend that you play around with the other arguments in the barplot function.

barplot(y1, col="grey", border=0, names.arg=x, angle=45, xlab="Age Groups", ylab="Number of Loans", cex.lab=1.7, cex.main=1.7, cex.sub=1.7, cex.axis=1.2, cex.names=1.2)

The following plot is generated using the above command.

Rplot

Again we will use ‘par’ function to overlay a line plot on top of the bar plot. We will use the following command:

par(new=TRUE)

Now, we will draw a line plot using the following command. This new plot will be overlaid on top of the previous bar plot because of the above par statement. In the plot command type=”l” argument tells R to draw a line graph, with orange color (col=”Orange”) and thicker line width (lwd=5).

plot(y2, type="l", col="Orange", lwd=5, xlab="", ylab="", xaxt="n", yaxt="n")

The following plot will be generated using the above set of commands.

Rplot01

Penultimately, we need to format the new Y axis and label it “Bad Rate”. This is precisely what we are doing through the following two commands.

axis(4, cex.axis=1.2)
mtext("Bad Rate",side=4, line=3, cex=1.7)

The result of the above two commands is labels for the Y axis for ‘Bad Rate’on the right as shown below.

Rplot03

Ultimately, we will place a legend on the top right corner of the graph to make it more friendly to read. We will do it using the legend function as shown below.

legend("topright", col=c("orange"), lty=1, lwd=5, legend= c("Bad Rate"), cex=1.25)

This has completed our exercise and we have the final plot that we were looking for.

Rplot04

你可能感兴趣的:(Scorecard : Data Visualization – Banking Case)