## Chi-Square Test With More Than 2 Categories

I have just enrolled in a Data Science course on Udemy  and I learned good stuff.

In this article, we will do a Chi-square test with more than 2 categories. We will use the A/B test « Country » which has 3 categories which corresponds to 3 countries : German, Spain and France. Select « Gender Actual » tab, make a copy with a right-click and select « Duplicate ».

Name the tab « Gender Actual (2) » by « Country Actual ».

In « Dimensions », move the variable « Geography » over « Gender » in « Columns » to replace « Gender » with « Geography ».

Here’s how to do an A/B statistical test when there are 3 categories. We’ll start with the classic method and then I’ll show you another way to do Chi-square test with any number of categories.

Let’s start with the classical method. In this case, there are 3 categories so we can’t use the online tool of the previous article. In the previous article we used an online tool with only 2 categories « Sample1 » and « Sample2 ». That’s why we’re going to use another online tool, click here  .

In this online tool, we can enter the values without using the total values. That is, we enter only the number of observations in each category. We simply need to enter the values that are on our A/B test. And I’m going to show you how to turn our A/B test into a table. In this way, it will be easier to enter the values in the online tool without making any mistakes.

Go to the « Show me » tool at the top right.

Click on « text tables »

Click on « Swap Rows ans Columns » button.

Cool, now you have a table arranged in exactly the same way as the online tool.

In the online tool, we will select 2 rows and 3 columns.

As we have 3 categories and 2 possible results, we enter our values exactly as in the table we just created on Tableau.

Perfect, our table is ready. You can click on the « Calculate » button.

As you can see, we observe the same thing as the other online tool. There is our indicator « p » value which is less than 5%. Which means there is a meaning.

This statistical significance means that these results are valid for the total number of the bank’s clients and not just for the sample of 10 000 clients. We observe similar differences with A/B test « Country » whose results are based solely on the sample of 10 000 clients. We can conclude that in the total number of the bank’s clients, it’s the clients in Germany who are more likely to leave the bank. This is how we do things cleanly.

You saw, this online tool limited by 5 by 5 tables so you can’t use this tool when you have 6 categories or more. But fortunately it’s possible to do Chi-square test with any number of categories. It’s a special method and for you to understand that, I’ll give you a theoretical explanation.

Here we have 3 countries : German, Spain and France.

What we’re trying to compare is the clients number leaving the bank in each of these countries.

With our basic A/B test based on a sample of 10 000 clients, we obtained 16% for France, 32% for Germany and 17% for Spain. Now the question is : « Do we observe the same results on the total clients number of the bank ? », it means : « In general, does the country have a significant effect on the clients number leaving bank ? ». Germany has the largest number of clients leaving the bank so the idea is : « Why would we need to compare the 3 countries at the same time ? ».

If we do an A/B test statistical test with Germany and France and we get a significant difference in the clients number leaving the bank between these 2 countries, then that would mean that in general, the country has a significant effect on the clients number who bank. Indeed, if we find by comparing Germany and France that the Germans are more likely to leave the bank than the French, we can consider that Spain will not change anything. Germans will always be more likely to leave the bank than the French. Maybe there will be a different relationship between Germany and Spain but there will always be a statistically significant difference between France and Germany with a larger number of clients leaving the bank in Germany than France.

Here is a way to confirm that this logic is true. There is a test and the participants of this test are German, Spanish and French. Imagine that this test was done without looking at what is happening in Spain. Now you get the result and you ask yourself the question : « Would the results changed if you added Spain ? ». The answer is « no » because there is no interdependence between Germany, Spain and France. That is, the decision to leave the bank in France and Germany doesn’t depend on Spain. And therefore, it’s quite correct to separate the categories by putting 1 aside to compare the 2 others. And as now we have 2 categories, we can do a Chi-square test with the online tool that we used in the previous article.

So let’s go back to our worksheet and put a country aside to compare only 2 countries. Select « Country » tab.

What we observe is that the difference between Spain and France is very small, so it wouldn’t be interesting to do a Chi-square test between Spain and France. It’s more interesting to do a Chi-square test between Germany and France and to prove that there is a statistically significant difference between these 2 countries. This will be enough to conclude that the country has a statistically significant impact on the clients number who leave the bank.

Selects « Country Actual » tab.

We will use the online tool of the previous article, click here  .

We will make a copy of « Country Actual » to have a bar chart with absolute values. Select « Country Actual », right-click and select « Duplicate ».

In « Show Me », select « horizontal bars ».

Removes « SUM (Number of Records )» from « Columns » and removes « Exited » and « Geography » from « Rows ».

In « Dimensions », move « Geography » in « Columns ».

In « Measures », move « Number of Records » to « Rows ».

In « Measures », move « SUM(Number of Records) » in « Label ».

In « Dimensions », move « Exited » in « Label ».

In « Dimensions », move « Exited » in « Colors ».

We also need total absolute values, which means the total number of men and women. There is a very fast way to get that. Right-click on the vertical axis and select « Add Reference Line ».

Then in « Value », click on the drop-down on the right and select « Sum » to have the total sum of the observations.

And in « Scope », you select « Per Cell » option to specify that you want the total sums for each category, male and female.

Now, we have the total sum at the top of the bars. We will modify labels to have the absolute values. In « Label », we will change « Computation » to « Value » and click on the « OK » button.

Here’s how to enter the data :

For « Sample1 » in #success, you enter 810 because there are 810 people who left the bank. For « Sample1 » in #trials, you enter 5014 because there are 5014 people in total.

For « Sample2 » in #success, you enter 814 because there are 814 people who left the bank. For « Sample2 » in #trials, you enter 2509 because there are 2509 people in total.

Here is the verdict : « Sample2 is more successful ». « Sample2 » corresponds to German’s clients and #success is :« yes, the client left the bank ». This verdict means that of all the clients from German are more likely to leave the bank than clients from France. And look, there is something important, it’s « p<0.001 ». This means that the « p » is strictly less than 0.001. As you can see, « p » value is very small, which concludes that the tests are statistically significant.

Ooh, there’s another thing I wanted to show you with the tab « age » with the 2 bar charts in parallel.

As you can see, there are many categories (more than 5) because each category corresponds to a 5-year ago group with clients of the bank aged from 15 to 90 years old. This is a lot of comparison but it would be a good exercise for you to find what are the 2 categories to compare that shows that there is a significant statistic difference.

I give you a hint, compare slices from 50 to 54 years old or from 35 to 39 years olds. In fact, you should compare all peer categories where you observe difference on this basic A/B test. Do a basic A/B test with absolutes values. Then do a Chi-square test to check if the difference is statistically significant, I mean, if the result is valid for the total number of bank’s clients.

This is a way to statistically validate the insights we see onTableau. You see, it’s not very difficult and it’s effective. Here is a way to find insights on Tableau and validate them.

-Steph

## Validate Data Mining In Tableau With A Chi-Square Test

I have just enrolled in a Data Science course on Udemy  and I learned good stuff.

In this article we will start using statistics. Don’t worry we’ll do something simple, we’ll use the Chi-square test in a basic way. There is a special section to learn how to do statistics at an advanced level.

I’ll explain why we’re going to learn how to use the Chi-square test. The results we have with theses 2 bar charts are good. We see on theses 2 bar charts that age has a significant impact on the rate of client leaving the bank. We also see in which age groups the clients leaves the bank the most and which age groups the clients leave the bank the least. With that we have good insights.

In the A/B test « Gender », we can see that there is a correlation between the male and female sex and the choice to leave the bank. But as I said before, this A/B test is basic. The results of a basic A/B test visually shows us what is probably happenning in reality but we aren’t 100% sure of these results. To validate these results, we need do to use statistical tests like Chi-square test.

Doing a report based on basic A/B test is very risky and you can have completely false insights. I don’t advise you to do it (unless you want to leave your job). It’s for this reason that using Chi-square will help us to have strong insights.

Chi-square will allow us to know if our results are statistically significant. Our results are based on a sample of 10 000 clients and Chi-square test will tell us if these results are due to chance effects or if these results can represent all the client of the bank.

For example in our A/B test « Gender », we observed that in our sample of 10 000 clients, women are more likely to leave the bank compared to men.

Now, we aren’t sure if the results of this sample represent the behavior of all the bank’s clients.

To use basic Chi-square test, we use an online tool. Click here  .

On internet, there are plenty of websites to do a Chi-square test but we’ll use this one so that you can understand how it works. To do a Chi-square test, we need to use absolute values and in our A/B test we have percentage.

Let’s go back to Tableau. We’ll create a new tab with a version of A/B test with absolute values. In this way, we keep the A/B test with the percentages. Do a right-click on the « Gender » tab and select « Duplicate ».

Name the new tab « Gender Actual » to specify that it’s absolute values.

To have the absolute values, move « Number of Records » in « Measures » to the « Marks » area and put it over top of « SUM(Number of Records ».

Move « Number of Records » in « Measures » to « Rows » over « SUM(Number of Records ».

Cool, we have our absolute values.

We also need total absolute values, which means the total number of men and women. There is a very fast way to get that. Right-click on the vertical axis and select « Add Reference Line ».

Then in « Value », click on the drop-down on the right and select « Sum » to have the total sum of the observations.

And in « Scope », you select « Per Cell » option to specify that you want the total sums for each category, male and female.

Now, we have the total sum at the top of the bars. We will modify labels to have the absolute values. In « Label », we will change « Computation » to « Value » and click on the « OK » button.

Perfect, we have the total amount of observation at the top of each bar : 4543 women and 5457 men. We have what we need to use our online tool.

OK, I’ll explain how this tool works. « Sample1 » and « Sample2 » correspond to the independent variable « Gender ». You choose in which order you enter the data, « Sample1 » for men or the opposite. In our case, we use « Sample1 » for women and « Sample2 » for men.

« #success » corresponds to the result Y=1, which means in our case « yes, the client left the bank ».

« #trials » is the total number of observations, which means the total number of women in « Sample1 » and the total number of men « Sample2 ».

That’s how you enter the data :

• For « Sample1 » in #success, you enter 1139 because there are 1139 women who left the bank. For « Sample1 » in #trials, you enter 4543 because there are 4543 women in total.

• For « Sample2 » in #success, you enter 898 because there are 898 men who left the bank. For « Sample2 » in #trials, you enter 5457 because there are 5457 men in total.

Here is the verdict : « Sample1 is more successful ». « Sample1 » corresponds to women and #success is :« yes, the client left the bank ». This verdict means that of all the bank’s client, women are more likely to leave the bank than men. And look, there is something important, it’s « p<0.001 ». This means that the « p » is strictly less than 0.001.

« p » is the value that indicates whether an independent variable has a statistically significant effect on a dependent variable. In our case, the independent variable is « Gender » and the dependent variable is « Exited », which is : « yes, the client left the bank ». So « p » is strictly less than 0.001, which means that the independent variable « Gender » has a statistically significant effect on the dependent variable « Exited ». This shows us that out of the total number of bank’s clients, women are more likely to leave the bank than men.

This is how we use Chi-square test with this online tool. This is the same principle on all online tools that you can find on Google or DuckDuckGo . You can repeat these instructions that I gave you with other tools, you will get the same results.

It’s cool with the Chi-square we validated the A/B test and to specify that this A/B test is validated, we’ll color the tab in green.

Right-click on the tab, select « Color » and select « Green ».

Perfect, now we’ll validate another A/B test. Selects « HasCreditCard » tab.

We’re going to create an A/B test « HasCreditCard » only with absolute values. To save time, right-click on « Gender Actual » tab and select « Duplicate ».

We’ll remove the green color on the tab « Gender Actual (2) ». Right-click on the tab and select « Color » and « None ».

You rename the tab « HasCreditCard Actual ».

Move the variable « HasCrCard » over « Gender » in « Columns ».

Excellent, everything is ready to do a Chi-square test. We’ll remove « Exited » labels to better see the absolutes values. Make a click and drag out.

Perfect, let’s go back to our online tool. In this case, « Sample1 » is « no », which means client who don’t have credit card and « Sample2 » for « yes », which means clients who have a credit card.

That’s how you enter the data :

• For « Sample1 » in #success, you enter 613 because there are 613 clients who left the bank. For « Sample1 » in #trials, you enter 2945 because there are 2945 clients who don’t have a credit card.
• For « Sample2 » in #success, you enter 1424 because there are 1424 clients who left the bank. For « Sample2 » in #trials, you enter 7055 because there are 7055 clients who have a credit card.

Let’s look at the verdict, it’s « No significant difference ». « p » value is very high, it’s above 5%. This confirms that the independent variable « HasCrCard » has no statistically significant effect on the dependent variable « Exited ». That was the conclusion we had made when we had done the A/B test with percentages.

We had seen that there was 21% of « Exited » (clients who left the bank) in the category « no » and 20% in the category « yes ». With these results we concluded that most likely the variable « HasCrCard » had no impact on the rate of clients who left the bank. Chi-square test confirms our conclusion and we can put the tab « HasCrCard » in green to say that it’s OK.

Right-click on the tab « HasCreditCard » => « Color » => « Green ».

Excellent, now, you can do a statistical A/B test with 2 categories. Soon, we will do statistical A/B tests with more than 2 categories.

-Steph

## Combine 2 charts

I have just enrolled in a Data Science course on Udemy  and I learned good stuff.

We’ll move to the next level. We’ll work with 2 bar charts in parallel to have a more efficient data mining. In a previous article, we created 2 different bar charts. The 1st was an A/B test (actually, it’s a classification test) that told us in which age range the clients were most likely to leave the bank. The 2nd was a bar chart showing the age distribution of clients in our sample of 10 000 clients.

Let’s go. We’re going to have an A/B test with age range and we’ll add a bar chart of the client distribution below. To add a bar chart, we must start by choosing what we want to keep and what we want to add. In our case, we want to keep the columns because they’re the same in the 2 bar charts.

And we just want to add a new line so we will add a new variable in « Rows ». As we want to add a bar chart of distribution, we will use the variable which corresponds to the number of observation « Number of Records ».

In « Measures » moves the variable « Number of Records » in « Rows » to the right of « SUM(Number of Records).

We have a 2nd bar chart below the 1st bar chart. As you can see, these 2 bar charts are in one column. « Columns » is « Age(bins) ». These 2 bar charts are in 2 different lines which are the lines that correspond to the 2 « SUM(Number of Records) » in « Rows ».

The space on the left has also changed. There is « All » which represents the 2 bar charts at the same time. It means, when your select « All », you make change in the 2 bar charts.

Below this tab « All » we have 2 tabs. The 1st tab represents the 1st bar chart so the 1st « SUM(Number of Records) » in « Rows » and the 2nd tab represents the 2nd bar chart so the 2nd « SUM(Number of Records) » in « Rows ».

Which means that if you want to make changes on the 2 bar charts at the same time, you make the changes in the tab « All ». If you want to make changes only in the first bar chart, you select the first tab below « All ». If you want to make changes only in the 2nd bar chart, you select the second tab below « All ».

So if you change the color in tab « All », our 2 bar charts will be colored by the same color.

Select the « All » tab and click on « Colors ».

Click on « Edit Colors… » and select « Stayed ». Select the green color and click on the « OK » button.

As you can see, the color changed in the 2 bar charts.

Click on the tab of the 2nd bar chart.

Removes the « Exited » variable from « Colors » to remove colors only in the 2nd bar chart.

Removes the « SUM(Number of Records) » variable from « Label » to remove the labels only in the 2nd bar chart.

We will add color on this 2nd bar chart. Click on « Colors », click on « More colors… » and select the blue color. Click on the « OK » button.

Now, we would like to see the colors vary in intensity depending on the number of observations. Take « SUM(Number of Records) » from the 2nd line in « Rows » and holding « Ctrl » or « Command », move it to « Colors ».

Cool ! We will take care of the 1st bar chart. Select the tab of the 1st bar chart.

Click on « Colors ». Click on « Edit Colors… ». Select « Stayed ». Select the brown color and click on the « OK » button.

For more clarity, we will add labels in 2nd bar chart. Click on the tab of the 2nd bar chart. Take « SUM(Number of Records) » from « Colors » and holding « Ctrl » or « Command » and move it to « Labels ».

Perfect. Now we will change the location of the bar chart. We will put the 2nd bar chart instead of the 1st bar chart. According to the logic of « Rows » and « Columns », simply put the 2nd line « SUM(Number of Records) » to the left to pass in 1st line.

BOOM, the bar chart of the age distribution is going over because it’s in the 1st line in « Rows ». With these changes, tabs to change the bar charts have changed order.

Observation

What we can observe with these bar chart is that we see on the 1st bar chart that the majority of bank’s clients are in the age group of 30 to 34 years old and 35 to 39 years old. In these 2 age groups, we see on the 2nd bar chart that client of 30 to 34 years old are less likely to leave the bank than clients between 35 and 39 years old. Look at ages 30 to 34, the rate of clients leaving the bank is 8% while in the 35 to 39 age group, the number of clients leaving the bank is 13%.

In the age group of 40 to 54 years old, we see on the 2nd bar chart that the rate of clients leaving the bank is increasing and is above of the average rate of clients leaving the bank (20%). But we see in the 1st bar chart that the number of clients in the age group of 40 to 54 years old decrease with the age groups.

Do you remember the potential for anomalies in age groups 75, 85 and 90 ? We’ll check it. In the 1st bar chart we can see that there are 11 clients in the age group of 80 to 84 years old, 2 clients in the age group of 85 to 89 years old and 2 clients in the age group of 90 to 94 years old. We can conclude that these observations in age group of 80, 85 and 90 aren’t very significant from a statistical point of view because 2 clients is something negligible in this sample of 10 000 clients.

In the first age group of 15 to 19 years old, we can see that there are 49 clients, which is not very significant.

Compare these 2 bar chart in parallel allows us to have additional insights.

-Steph

## Create Bins and View Distributions

I have just enrolled in a Data Science course on Udemy  and I learned good stuff.

It’s cool, you finished the 1st part. Now we’re going to do more deep Data Mining analysis with this bank’s dataset.

To make these analyzes more deep, we’ll create a more statistical approach.

To do that we will create a new tab.

For this new tab, we want to understand how client distributed according to their age. Is there a majority of young or old people ?

Move the variable « Age » in « Columns ».

As we want to see the distribution of client ages, we need to use the variable « Number of Records » to see the number of observations. Move the variable « Number of Record » to « Rows ».

Boom, we have a chart but there is only one point on the top right. What happened is that Tableau took the sum of the ages of all the bank’s clients and the sum of all the « Number of Records », it means the total number of clients, 10 000 clients.

We’ll find a solution but before we’ll change the format to better see the chart. Right-click in the middle of the chart and select « Format ».

For the font’s size, select « 12 ».

Here you can see that the total age is 39 218 but that’s not what we’re looking for. What we want to see is the number of clients for each age.

I’ll explain what’s going on. We took the aggregated sums of our variables. Aggregate means that we took the total sum of the variable for each category. We added the ages but in fact we want to see the total number of observations for each age separately.

To have that, just click on the arrow in « SUM(Age) » in « Columns ».

Then select « Dimensions »

You see, Tableau doesn’t take the aggregated sum of ages but it takes ages separately. We have a curve that shows us the continuous distribution of our clients ages. That is to say, for each age, the curve gives is the number of clients of this age.

We’ll look at the dataset. Right-click on « Churn Modelling » and select « View Data… ».

There is window that appears that shows us the data in detail. If you scroll to the right, you will find the column « Age ».

We see that the ages rounded. As all ages rounded, Tableau is able to group clients by age. By positioning the mouse on the curve, we can see that there are 200 clients who are 26 years old.

If in the dataset, ages weren’t rounded, you would have seen clients with 26.5 or 26.3 years. It would create a lot of irregularity, there would be plenty of spikes with lots of variations.

Oooooh look, there is a variation that isn’t normal.

Let’s analyze it in detail. Around this peak, we see that there are 348 clients who are 29 years old.

Here, 404 clients who are 31 years old.

And this peak down that shows us that there are 327 clients who are 30 years old.

How to explain this irregularity ? It’s possible that many people of 29 years old are about to turn 30 years old and many people of 31 years old who just had 31 years old. It’s chance that make us have inaccuracies. You may have other inaccuracies if you data isn’t precise and rounded. In our case, the ages are rounded but we want to get rid of our small irregularity that we see on our curve.

There is way to see our distribution without our irregularities, it’s « bins ». « Bins » consists of grouping the information into different categories. That is we’re going to regroup our clients in different age groups.

Right-click on « Age » in « Measures ». Select « Create » and select « Bins… ».

A window appears. We’ll group our clients in 5-years increments. In « Size of bins », write « 5 » and click on the « OK » button.

As you can see, the variable « Age » has remained in « Measures » but there is a new variable in « Dimensions ».This is the variable we created « Age(bins) ».

Our « Age(bins) » variable was correctly placed in « Dimensions » because it is a category variable because each category corresponds to a 5-year age group.

For example, one category is 20 to 24 age group. Now we’ll create a new distribution based on « bins ».

To do that, we’ll remove the variable « Age » from « Columns » with a click and drag outside.

You move the variable « Age(bins) » from « Dimensions » to « Columns ».

Note

In this case, it’s not possible to directly replace « Age » by « Age(bins) » over « Age » on « Columns ». This is because « Age » is a measure and « Age(bins) is a dimension.

That’s nice distribution, it’s usually the type of distribution (chart) we see in economics or mathematics. The difference with the old chart is that this chart is discrete. This chart is discrete because the clients grouped by age group while the previous chart was continuous.

On this distribution (chart), each bar corresponds to an age range. For example, this bar corresponds to the 25-29 age group.

Now, we’ll change the colors.

In « Row », move « SUM(Number of Record) » while holding down the « Ctrl » or « Command » key on your keyboard to « Colors ».

We get our distribution in blue but we’ll change the color to red. Click on « Colors » and click on « Edit Colors »

In the window that appears, click on the blue square on the right to display the color pallet.

Select the red color and click on the « OK » button.

Click on the « OK » button of the « Edit Colors » window.

To facilitate the reading of the bar chart, we’ll add the number of clients in each age group. In « Row », move « SUM (Number of Record) » while holding the « Ctrl » or « Command » key on your keyboard to « Label ».

That’s it, we can see how many clients there are in each age group.

We see that the dominant bar is the 35-39 age bracket and the second dominant bar is the 30-34 age bracket. Overall, we can see that most clients are between 25 and 40 years old, which seems consistent.

On our bar chart, we have absolute values. We’ll replace that with percentages. Click in the little arrow in « SUM(Number of Records) » in « Label » and you select « Add Table Calculation… » but I’ll show you another way to do it.

Instead of clicking « Add Table Calculation… », click on « Quick Table Calculation » and select « Percent of total ».

It’s cool, we have the exact percentage of people in each age bracket. Now, we can see that in the 25 to 40 age group, we have 20 + 23 +17= 60% of clients.

I’ll show you one last thing.You can change the size of the slices easily, just click on « Age(bins) » and select « Edit ».

In the windows, you can change the size of the slices (bins). Put « 10 » instead of « 5 » to get 10-years slices. Click on the « OK » button.

Now, we have a distibution with fewer slices and the dominant slice is 30 to 39 years old.

Well, it was just to show you how to change the size of bins. To go back to the old distribution with the 5-years slices, click on « Back » button.

As you can see, the values on bars are in percentages but the values on the axis are in absolutes values. Here is an exercise that I ask you to do : « Put the values of the axis in percentage ». I’ll give you the answer the next article.

-Steph

## A Pratical Tip To Validate Your Approach

I have just enrolled in a Data Science course on Udemy  and I learned good stuff.

How was the A/B test « Number Of Product » ? Easy or difficult ?

Here is the result I found.

I think you noticed there was something bizarre. There is an anomaly. We imagine that the more the client has products, the more the client is satisfied with the bank so this type of clients should stay in the bank.

In the first 2 bars we can see that a client who has 1 product is more likely to leave the bank than a client who has 2 products. But when a client has 3 or 4 products, we see a huge rate of clients leaving the bank.

Look, there is a little bizarre detail. In the 2nd bar, we can’t see the « Exited » label. This is because there is no place in the orange part to put the text. To make it simpler, we’ll remove the label « Exited ». Drag and drop on the « Exited » text label to the outside.

Perfect, we can read the percentages. On the 1st bar, we can see that among the client that have 1 products, 28% left the bank. On the 2nd bar, we can see that among clients who have 2 products, 8% left the bank. This show us that clients who have 1 products are more likely to leave the bank than clients with 2 products.

And for the next bars, we observe an anomaly. On the 3rd bar, we can see that among the clients who have 3 products, 83% left the bank. On the 4th bar, we can see that among clients who have 4 products, 100% left the bank. We clearly see that there is a problem and we need to do a deeper analysis to understand what is going on .

As a Data Scientist, we need to explain what happens in bars 3 and 4. Usually when a client has 3 or 4 banking products, that means he/she is satisfied and is loyal to the bank. But in our case, it’s the opposite because there is a high rate of client who left the bank. This is the time to do deeper analysis.

The first thing to analyze is the quality of the data. There is a very big anomaly and it may be because there is something insignificant in our data that disturbs the statistics. For example, it’s possible that when the bank selected these clients in this sample, there were very few clients with 4 products and all those clients with 4 products left the bank. Sometimes chance can create anomalies and you have to play attention to these effects of chance because they don’t seem important but they can create false interpretations.

To start, we will check the number of clients with 4 products.

In « Measure », move « Number Of Records » (which gives the number of observations) on « Label ».

We observe on the first 2 bars than many clients with 1 or 2 products selected for our sample. For clients with 3 or 4 products, we can see that there were fewer clients selected for our sample.

There are 220 clients with 3 products and 60 clients with 4 products. These small number of clients probably explain why we observe these anomalies.

In this sample of randomly selected clients, there are very few clients with 4 products and they all left the bank. In this situation, we can confirm that it’s a chance. When thing like that happen, you have to be very careful not to make conclusion too fast and make misinterpretations.

The conclusion is that a lot of clients have been selected for category 1 and 2. For category 3 and 4, there have been few clients selected so we can’t do accurate statistics. We need to do deeper analyze for these categories of clients with 3 and 4 products.

Now, let’s put the percentage back on the bar chart. Click on the « Back » button.

.

Or do a click and drag of « SUM(Number of Record) » to outside.

We saw that there is an anomaly and what is interesting to do is to have a comment to remember to do a more in-depth analysis of columns 3 and 4.

Right-click between the bar chart’s title and the bars. Select « Annotate » then « Areas… ».

A window appears. In this window, you write « Low observation in last 2 categories » and click on the « OK » button.

Click on the comment and move it on bars 3 and 4.

The next time you work on this bar chart, you will see this comment that will remind you to seriously analyze client who have 3 and 4 products.

# Validate our approach

It’s time to show you how to validate an approach and how to validate the data. For this we will create a new A/B test.

Duplicate this worksheet with a right-click on the « NumberOfProducts » tab and select « Duplicate ».

And rename the tab « Validation ».

For this tab, we will erase the comment. Select the comment and press the « Delete » button on your keyboard.

Everything is ready, the idea is to find a variable that doesn’t affect our results. That is a variable that has no impact on a client’s decision to leave or stay in the bank.

Take for example, the variable « Customer Id ». Client’s identification number has no influence on the client’s decision to stay or leave the bank.

We’ll do an A/B test with the last digit of the « Customer Id » and we’ill check that there is the same clients proportion who leave the bank in the 10 categories of the last digit of the « Customer Id ». The 10 categories are the numbers 0,1,2,3,4,5,6,7,8,9.

Let’s g.To start, we will create the variable that contains the last digit of the « Customer Id ». To have this variable, we will create a « Calculated Field ».

Right-click on « Customer Id », select « Create » and click on « Calculated Field ».

Name the calculated field « LastDigitOfCustID ». In the text field, we use the « RIGHT » function with « Customer Id » in parenthesis to select the last character of the « Customer Id ». In our case, the last character of the « Customer Id » is the last digit.

Here is the code to write in the text field : Right ({Customer Id},1)

Oooops, you see there is a small mistake => The calculation contains errors.

There is an error in the formula because « Customer Id » is a number variable and the « RIGHT » function applies to a variable of type « STRING ».

To use the « RIGHT » function, we will convert « Customer Id » into a string. We will use the « STR » function with « Customer Id » in parenthesis.

Here is the code to write in the text field

And click on the « OK » button : Right (STR({Customer Id}),1).

Now, you can see that our calculated field « LastDigitOfCustID » is in « Dimensions ».

Click on « LastDigitOfCustID » and move it on top of « NumOfProducts » in « Columns ».

Now we have a new bar chart and we see that for every last digit of the « Customer Id » there is about the same proportion of clients leaving the bank. All these proportions don’t correspond exactly to the average of 20% but these slight variations aren’t important.

Seeing this uniform distribution allows us to validate our data because these data are homogenous.

# Conculsion

Here’s how you can check the homogeneity of your data. You take a variable that has no impact on the fact that a client leaves or stays in the bank. The example we did with the last digit of the « Customer Id » is excellent. We were able to verify that in each of the categories taken by this variable, if there was the same proportion of clients leaving the bank. As is the case, we can validate our data.

Imagine another result. When we do the test with the last digit of the « Customer Id », we observe that for one of the numbers, the rate of clients who left is really higher than the average. This shows us that there is a problem in our data because it indicates an anomaly.

You can find other ways to verify your data by using other « insignificant variables » to see if the distribution is homogeneous. But be careful when you select an « insignificant variable » because there may be traps.

Here is an example. If you create a variable that takes the first letter of the first name, the distribution will not be homogeneous. The reason is simple, there are many more people who have a name that starts with the letter « M » than with the letter « Y ».

-Steph

## Why Live With Your Passion

I watched an Olivier Roland’s video  and I learned good stuff.

We hear every day that it’s important to do a job that fascinates us. When you do a job that fascinates you , you will never work again but if you don’t do that, you will miss your life and so on. We hear that all the time.

# To be passionate

Now, let’s look at it concretely. Look at the people around you and you don’t need to do a deep analysis. You just have to ask yourself this question : « Are the people I know passionate about the work they do ? ». The answer is : « It’s a tiny minority that does that ». There is often a big gap between theory and practice.

I encourage you to dare to realize your dreams. I encourage you to take baby steps forward everyday to live your dreams. Realizing a dream is not just about being fulfilled. From the moment you do a job that your are passionate about, you have automatically and mechanically by a pure leverage effect, bring more values to the world.

Having the skill is very important and we can have people who aren’t passionate about their work but who are very competent. But between 2 people who have the same skill, it’s always the person who is the most passionate who will succeed to transmit the flame, to make you have sparks on your eyes, to make you dream and maybe to motivate you to do a project that you hesitate to do that will change your life.

It’s this passion that will create maximum leverage on the rest of the world and bring something beautiful, new, artistic. It’s important and we need to do something we’re passionate about. I can even say that it’s a duty for the rest of humanity and I will explain why.

# Don’t be passionate

Everyday we see people who are passionate about their work and people who aren’t passionate or who hate their work. When we meet people who aren’t passionate or hate their work, it is felt in each of their gestures, in each of their eyes, in each of their words. Everytime we meet people like that we feel a bit sadness, disappointment and frustration.

These people don’t like their work but the problem is that these people don’t like their work so much that they make us hate this job. We all had teachers at school like that. This teacher who doesn’t like his/her job and perhaps also the subject he/she teaches and the consequence is that the majority of the class hate the job of teacher and the subject he/she teaches (and it’s hard to have a good grade with these teachers). Do you remember those teachers ?

# Struggle

I know that isn’t easy. It’s always difficult for me today but instead of staying with your friends complaining about injustices in your city by drinking alcohol and smoking weed after school or work (yes, I was like that), use this time to take a step towards the realization of your dreams. What’s cool with internet is that we can easily do a lot of things like learning a new skill , get a freelance job online , having a blog, a podcast, a Youtube channel or selling things on Amazon , eBay  or Shopify .

If you hesitate to create your dreams, say to yourself it’s not a question of being happy and being fulfilled. It’s about bringing value to the world, bringing a smile, a spark, an energy to the world.

-Steph

## Look For Anomalies

I have just enrolled in a Data Science course on Udemy  and I learned good stuff.

We’ll learn how to duplicate a bar char to create a new A/B test. We’ll create several A/B test to look for anomalies.

But before that, we’ll name the sheet. Right-click on the tabe and select « Rename Sheet ».

Rename the sheet « Gender ».

Now right-click on the « Gender » tab and select « Duplicate ».

Rename this new tab « Country ».

We’ll do an A/B test with the countries and we’ll reuse everything we did with the A/B test « Gender » to save time.

As you can see « Gender » is in « Columns ».

To use this A/B test with a variable other than « Gender », move the variable you want on top of « Gender » in « Columns ».

Go, go ! There is « Geography » in « Dimensions », takes « Geography » and puts it on « Gender ».

Boom with 1 click we have our A/B test for countries.

We have the percentage of clients who left and stayed in the bank for each country (Germany, Spain and France).

In this A/B test we can see that in Germany, many clients left the bank with a rate of 32%. For Spain and France, the rate of clients who left the bank is below the average departure rate (20%), 17% for Spain and 16% for France.

Already, we have interesting insigns. We can find out if in Germany there is a new aggressive competitor with more interesting offers or if there is a new law unfavorable to the bank’s offers that has been voted. It’s necessary to do reseach in Germany to find the reason for this high rate of departure.

You have seen, usually an A/B test has 2 categories but in our case, there are 3 categories. We could call it an A/B/C test but it’s a bit bizarre. When there are more than 2 categories, we call it a classification test.

In this article, I will continue to use the term A/B test but remember the term classification test for the next time.

Let’s do another A/B test quickly.

Duplicate this A/B test by right-clicking on the « Country » tab and selecting « Duplicate ».

This time we will study the variable « Has Cr Card ». This variable is « 1 » if the client has a credit card and « 0 » if the client doesn’t have a credit card.

You saw ? This variable is a categorical variable because it is binary « 1 » and « 0 » but it is in « Measures ». Since this variable is categorical, it should be in « Dimensions » so we will move the variable « Has Cr Card » from « Measure » to « Dimensions ».

Now that it’s done, move « Has Cr Card » over « Geography » in « Columns ».

It’s cool, we have a new A/B test for credit cards. What we can observe in this A/B test is that there is not a big difference between the departure rate of clients who don’t have a credit card (21%) and the departure rate of clients who have a credit card (20%).

It’s time to create aliases for this A/B test. Right-click on « Has Cr Card » and select « Alias…. ».

To start, « 0 » means that the clients don’t have a credit card so in « Value », you write « No ». « 1 » means that the clients has a credit card so in « Value », you write « Yes ». Then you click on the « OK » button.

That’s it, the bar chart is easy to read now. We understand that among clients who don’t have a credit card, 21% left the bank and among clients who have a credit card, 20% left the bank. We can conclude that having or not having a credit card doesn’t have a significant impact on the decision to leave the bank.

It’s time to rename this tab. Right-click on the « Sheet4 » tab and select « Rename Sheet ». Name the sheet « HasCreditCard ».

Let’s go, let’s do another A/B test with another variable. Let’s look at « Measure » and study the variable « IsActiveMember ».

The variable « IsActiveMember » is « 1 », if the client is active and « 0 » it the client is inactive. It’s necessary to detail the definition of IS ACTIVE. IS ACTIVE depends on the criteria of the bank. For example, it could be : « Did the client log in at least once to their bank account last month ? » or « Has the client made at least one banking transaction last month ? », etc.

As you can see, the variable « IsActiveMember » is a categorical variable (binary 1 and 0) so it’s a variable to move to « Dimensions ».

Here’s another way to move a variable from « Measures » to « Dimensions ». Right-click on « IsActiveMember » and select « Convert to Dimensions ».

Perfect, the variable « IsActiveMember » is in « Dimensions ».

We will duplicate our « HasCreditCard » sheet. Right-click on « HasCreditCard » tab and select « Duplicate ».

Renamce this tab « IsActiveMember ».

Since we have diplucted what we did with « HasCreditCard », we simply need to take the variable « IsActiveMember » from « Dimensions » and more that over « HasCrCard » in « Columns ».

Let’s create aliases to make reading this bar chart easier. Right-click on « IsActiveMember » and select « Aliases… ».

For « 0 », we put « No » because the client is not active and for « 1 », we put « Yes » because the client is active. Click on the « OK » button.

Here is what we can see with this A/B test « IsActiveMember ». Among inactive clients, 27% left the bank. Among active clients, 14% left the bank. This show is that clients who are not active are more likely to leave the bank than active clients.

Indeed, a client who is active means that he/she uses his/her bank account and products of the bank so an active client is satisfied with the bank. It’s possible that some clients leave the bank because of external factors such as a competitor, new regulations or elements of the private life of the client.

It’s cool, we created 4 A/B tests in a few minutes.

1. An A/B test « Gender » that allowed us to see that women were more likely to leave the bank.

2. An A/B test « Country » that allowed us to see that it is in Germany that clients are most likely to leave the bank.

3. An A/B test « HasCreditCard » which allowed us to see that having or not having a credit card didn’t have a significant impact on the descision to leave the bank.

4. An A/B test « IsActive Member » allows us to see that client who aren’t active are more likely to leave the bank .

I will leave you a homework. You’ll do an A/B test with the variable « Number Of Product » which is still a category variable. The variable « Number Of Products » indicates the number of product that the client has in the bank. Add aliases to make reading the bar chart easier.

I trust you I’ll give you the answer in th next article,