Chi-Square Test With More Than 2 Categories

tableau chi square test

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 ».

tableau chi square test

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

tableau chi square test

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

tableau chi square test

tableau chi square test

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  .

tableau chi square test

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.

tableau chi square test

Click on « text tables »

tableau chi square test

tableau chi square test

Click on « Swap Rows ans Columns » button.

tableau chi square test

tableau chi square test

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.

tableau chi square test

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

tableau chi square test

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

tableau chi square test

tableau chi square test

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.

tableau chi square test

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.

tableau chi square test

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

tableau chi square test

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 ? ».

tableau chi square test

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.

tableau chi square test

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.

tableau chi square test

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 ».

tableau chi square test

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

tableau chi square test

tableau chi square test

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

tableau chi square test

tableau chi square test

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

tableau chi square test

tableau chi square test

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

tableau chi square test

tableau chi square test

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

tableau chi square test

tableau chi square test

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

tableau chi square test

tableau chi square test

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

tableau chi square test

tableau chi square test

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 ».

tableau chi square test

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

tableau chi square test

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

tableau chi square test

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.

tableau chi square test

tableau chi square test

tableau chi square test

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.

tableau chi square test

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.

tableau chi square test

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.

Subscribe to my newsletter and share this article if you think it can help someone you know. Thank you.

-Steph

Validate Data Mining In Tableau With A Chi-Square Test

validate validation

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.

tableau data mining science chi square test a/b test

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  .

tableau data mining science chi square test a/b test

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 ».

tableau data mining science chi square test a/b test

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

tableau data mining science chi square test a/b test

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 ».

tableau data mining science chi square test a/b test

tableau data mining science chi square test a/b test

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

tableau data mining science chi square test a/b test

Cool, we have our absolute values.

tableau data mining science chi square test a/b test

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 ».

tableau data mining science chi square test a/b test

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

tableau data mining science chi square test a/b test

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

tableau data mining science chi square test a/b test

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.

tableau data mining science chi square test a/b test

tableau data mining science chi square test a/b test

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.

tableau data mining science chi square test a/b test

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.

tableau data mining science chi square test a/b test

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.

tableau data mining science chi square test a/b test

« 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 ».

tableau data mining science chi square test a/b test

tableau data mining science chi square test a/b test

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

tableau data mining science chi square test a/b test

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 ».

tableau data mining science chi square test a/b test

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

tableau data mining science chi square test a/b test

You rename the tab « HasCreditCard Actual ».

tableau data mining science chi square test a/b test

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

tableau data mining science chi square test a/b test

tableau data mining science chi square test a/b test

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.

tableau data mining science chi square test a/b test

tableau data mining science chi square test a/b test

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.

tableau data mining science chi square test a/b test

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 ».

tableau data mining science chi square test a/b test

tableau data mining science chi square test a/b test

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.

Share this article if you think it can help someone you know. Thank you.

-Steph

Combine 2 charts

tableau chart compare paralell data mining science

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.

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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).

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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.

tableau chart compare paralell data mining science

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 ».

tableau chart compare paralell data mining science

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 ».

tableau chart compare paralell data mining science

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

tableau chart compare paralell data mining science

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

tableau chart compare paralell data mining science

Click on the tab of the 2nd bar chart.

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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.

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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 ».

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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

tableau chart compare paralell data mining science

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

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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 ».

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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.

tableau chart compare paralell data mining science

tableau chart compare paralell data mining science

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.

Subscribe to my newsletter and share this article if you think it can help someone you know. Thank you.

-Steph

Create Bins and View Distributions

tableau, bins, bar, chart, distribution, age, data, science

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.

tableau, bins, bar, chart, distribution, age, data, science

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

To do that we will create a new tab.

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

Move the variable « Age » in « Columns ».

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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 ».

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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 ».

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

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 ».

tableau, bins, bar, chart, distribution, age, data, science

Then select « Dimensions »

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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… ».

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

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.

tableau, bins, bar, chart, distribution, age, data, science

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.

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

Here, 404 clients who are 31 years old.

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

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… ».

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

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) ».

tableau, bins, bar, chart, distribution, age, data, science

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.

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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.

tableau, bins, bar, chart, distribution, age, data, science

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 ».

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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 ».

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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.

tableau, bins, bar, chart, distribution, age, data, science

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

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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 ».

tableau, bins, bar, chart, distribution, age, data, science

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.

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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.

tableau, bins, bar, chart, distribution, age, data, science

tableau, bins, bar, chart, distribution, age, data, science

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.

Share this article if you think if can help someone you know.Thank you.

-Steph

Work With An Alias

data science alias bar chart tableau mining

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

In the last article, I showed you how to do a simple A/B test. We will continue with the result we had with the A/B test.

data science alias bar chart tableau mining

Here is the result of the A/B test. What is in orange is the percentage of men who left the bank, it’s 16%. What is in blue is the percentage of women who left the bank, it’s 25%.

With our bar chart we can quickly see that women are more likely to leave the bank than men, all the rest being equal in our sample.

I remind you that this is a basic A/B test. There are 2 type of A/B test, the basic A/B test and the statistical A/B test. The statistical A/B test is done with a statistical test like the KHI-2 test. For our case, the basic A/B test already give us good insights.

To make our bar chart even easier to read, we will work with aliases.

The first thing we will do is we will improve the format. Right-click on this space between « Gender » and the bars and select « Format… ».

data science alias bar chart tableau mining

The « Sheet » tab appears. In « Worksheet » changes the text size to « 12 ».

data science alias bar chart tableau mining

What is good with data mining is that we aren’t obligated to make a perfect chart because we don’t have to present them in a report to managers or a meeting.

For example, if I had to present this chart in a report, it would be necessary to change the vertical title. But we only make a model so this change isn’t necessary.

Now, look at this rectangle. We can see « Exited », « 0 » and « 1 ».

data science alias bar chart tableau mining

« 0 » means that the client stayed in the bank and « 1 » means that the client left the bank. We can also see that client who left the bank are in orange so 25% for women and 16% for men. And the client who stayed in the bank are blue so 75% for women and 84% for men.

We did an excellent basic A/B test but it would be much easier to read if we replace « 0 » with « Stayed » and « 1 » with « Exited ».

With aliases we can do that. An alias is to replace the binary results « 0 » and « 1 » with « Stayed » and « Exited » because it’s not easy to remember the meaning of « 0 » and « 1 ».

There are 2 ways to do it : create a calculated field or use aliases.

We will use aliases. Know that aliases are not going to change the « 0 » and « 1 » in the dataset, this change is only in Tableau.

In « Dimensions », right-click on « Exited » and select « Aliases… ».

data science alias bar chart tableau mining

data science alias bar chart tableau mining

A small window appears. In this small window, you can create an alias for each value contained in the « Exited » variable.

The variable « Exited » contains the value « 0 » and « 1 ». For the value « 0 », we will create the alias « Stayed » to say that the client stayed in the bank. For the value « 1 », we will create the alias « Exited » to say that the client left the bank. Then click on the « OK » button.

data science alias bar chart tableau mining

Look, we can see the new values in the rectangle.

data science alias bar chart tableau mining

The values « 0 » and « 1 » have been replaced by « Stayed » and « Exited ».

Now that the aliases saved, we will take the variable « Exited » in « Dimensions » and move it to « Label ».

data science alias bar chart tableau mining

data science alias bar chart tableau mining

Look, we have our aliases « Stayed » and « Exited » on the bar chart.

In this ways, it’s easier for people to read the bar chart without asking what meaning of « 0 » of « 1 » values. « Stayed » and « Exited » are clearer.

Now you know how to use aliases so that people can easily read the binary values of a chart.

Share this article if you think it can help someone you know. Thank you.

-Steph

Visualize An A/B Test in Tableau

A/B tes

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

We are going to do a simple and very visual A/B test in Tableau.

The first thing to do is save this worksheet and name it « Map ».

Do a right-click on « Sheet1 » at the bottom of the screen and select « Rename Sheet ».

Tableau A/B test data science

The second thing to do is to save this workbook. For that we go to « File » and select « Save to Tableau Public As… »

Tableau A/B test data science

The « Tableau Public Sign In » window appears to connect to your Tableau account.

Tableau A/B test data science

Save the workbook with the name « DataMining » and click on the « Save » button.

Tableau A/B test data science

We will create a new worksheet specifically for the A/B test. Click on the « New Worksheet » icon at the bottom of the screen.

Tableau A/B test data science

Look, you created the new worksheet.

Tableau A/B test data science

To start we need the dependent variable we are studying. This dependent variable is « Exited » which is « 1 » if the client left the bank or « 0 » if the client stayed in the bank. Now look, this dependent variable is in « Measures » so Tableau recognized this variable as a dependent numeric variable.

For our case, the dependent variable « Exited » is actually a category. Our logic in this situation is : « Did the client leave or did the client stay ?. For this reason, we need to move the variable « Exited » in the dimensions.

Tableau A/B test data science

Now, the variable « Exited » is in dimensions.

Tableau A/B test data science

Let’s do a classic A/B test, the A/B test for gender (male or female).Here what we’re going to test, if we keep all the rest constant and if we take a male client and a female client, which of the two is most likely to leave the bank.

Let’s go, move « Gender » in « Column ».

Tableau A/B test data science

We have 2 columns : « Female » and « Male ».

Tableau A/B test data science

Move « Exited » on « Colors ».

Tableau A/B test data science

Look, we have 2 colors. Blue for « 0 », it means the clients who stayed in the bank. Orange for « 1 », it means the clients who have left the bank.

To be more specific, we want know how many clients stayed and how many clients left the bank.

Move the variable « number Of Records » into « Rows ».

Tableau A/B test data science

Tableau A/B test data science

What we can notice is that the total number of men is higher than the total number of women. Then we can see that among the women, a large proportion left and that among the men a small proportion left. However, this is not enough to allow us to understand what is happening.

We will add « number Of Record » as a label. Move « number Of Record » to « Label ».

Tableau A/B test data science

Tableau A/B test data science

Change the label’s size in « 12 » and bold.

Tableau A/B test data science

Now we know the number of people in each category.

To better visualize this, we will replace the numbers with percentages. We want to see what percentage of female clients are gone and what percentage of male client are gone. With percentages we can easily make the comparison that with the absolute numbers, it’s not possible because the total number of woman is different from the total number of man.

To convert a absolute number to a percentage, you need to click on the arrow next to « SUM(number Of Record) ».

Tableau A/B test data science

And click on « Add Table Calculation… »

Tableau A/B test data science

Tableau A/B test data science

In « Calculation Type », select « Percent of Total ».

Tableau A/B test data science

Be careful, here there is one important thing to do. Change « Table(across) » and choose « Table(down) ».

Tableau A/B test data science

« Table(down) » will give us the total percentage in each column. Now you can close the window, the changes have been made.

Boom, we have the percentages.

We will create labels to make it easier to read. Click on the small arrow next to « SUM(number Of Record) » and select « Format… ».

Tableau A/B test data science

The « Pane » tab appears. In the tab « Pane » in « Numbers », choose « Percentage » and select « 0 » decimal.

Tableau A/B test data science

We will make it even more consistent. Move « SUM(number Of Record) » by holding key « Ctrl » or « Command » to « Rows » to replace the old « SUM(number Of Record) ».

Tableau A/B test data science

As you can see, the vertical axis is in percentage.

Tableau A/B test data science

Let’s do an analysis of what we see. We see that the percentage of female clients who left the bank is 25%. We see that the percentage of male clients who left the bank is 16%. What we see that female clients are more likely to leave the bank than male clients, all the rest being equal.

This A/B test is not complete because we have not done any test of statistical significance but this approach is effective for quickly obtaining results.

We’re going to do a full A/B test later but today you learned how to do an effective A/B test by focusing on relevant things. With a test of statistical signifiance, there are irrelevant variables and it takes a little more time but we’ll that later.

Share this article if you think it can help someone you know. Thank you.

-Steph

Connect Tableau Public To A CSV File

tableau connect file csv data science

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

After downloading the file « OfficeSupplies.csv », you will open this file with Tableau. When you open Tableau, there is a « Connect » column :

tableau connect file csv data science

Click on « Text File » and open the file « OfficeSupplies.csv » :

tableau connect file csv data science

The connection manager appears for this source file :

tableau connect file csv data science

At the top left, there is « Connect » where the file is located and below it, there is « File » with 1 file. There is 1 file because you imported 1 file. I’ll show you later how to import several files of the same type.

tableau connect file csv data science

In the center, there is a window with the files you connected. And it’s possible to connect several files.

tableau connect file csv data science

For exemple, if you do a drag and drop here, Tableau will try to connect these 2 files.

tableau connect file csv data science

You can work with data comes from several differents files, different tables from different CSV files. We’ll see that later.

At the bottom, there is a preview of the file with columns and rows. Colums « Order Date », « Region », « Rep » and « Items » identified as data in text format. Columns « Units » et « Unit Price » identified as data in number format.

tableau connect file csv data science

Now you’re gonna go on the dashboard. To access it, click here.

tableau connect file csv data science

Here is the dashboard. 

tableau connect file csv data science

We will discuss the various function in more detail in the next section.

Now, I just want to show you that we have « Data » column with our source file.

tableau connect file csv data science

If you do a right-click and click on « View Data », you see the data as in the previous window.

tableau connect file csv data science

tableau connect file csv data science

You’ve seen, it’s simple to connect a source file to Tableau.

Wait, I’ll show you how you can connect more source files. Click here to return to the connection manager where you can connect several different files.

tableau connect file csv data science

Of if you want to stay on the dashboard, you can click on the top left on « Data » then « New Data Source ».

tableau connect file csv data science

Or click on this icon on the dashboard. Here are the files types you can connect to Tableau

tableau connect file csv data science

What is interesting with the « Statistical File » is that we can connect files type SAS, SPSS and R.

tableau connect file csv data science

We have access to different server with OData and others.

tableau connect file csv data science

It’s perfect, now you can connect a data source to Tableau and you’ll see later how to connect data faster.

Share this article if you think it can help someone you know. Thank you.

-Steph