How I used Naïve Bayes and Logistic Regression to detect Breast Cancer using TabPy

This blog also aims to explain using Tableau with Python.

Purva Sawant
Acing AI
4 min readJun 14, 2018

--

This week I — Vimarsh Karbhari teamed up with Purva Sawant. She has devised a way to use Tableau with Python using Tabpy. Tableau is a powerful tool which I have used. I have used Python for most of my Data Science related projects. Using Python with Tableau can unlock a series of interesting ways in which we can visualize data and use different models for detecting patterns. This article aims to use Naïve Bayes and Logistic regression which is a very basic and rudimentary model which can be used to detect breast cancer. This can be used as a starting point to use different models using Tabpy to achieve better results. The article is a step by step illustration on the setup required as steps to derive the solution.

A cing AI’s AI Interview Questions articles for Microsoft, Netflix, Google, Apple, Amazon, Facebook and Uber have been very engaging to the readers. As a followup, next couple of articles were on how to prepare for these interviews split into two parts, Part 1 and Part 2. To learn from experts please visit Acing AI expert Insights. Now on to the article…

Courtesy: Google

With the release of Tableau 10.1, we can use Python scripts as calculated fields in Tableau. This works by using the Tableau Python Server- TabPy

Prerequisites:

  1. Python 3.0
  2. Tableau Python Server: TabPy

Steps:

Install tableau python server : TabPy

  1. Download TabPy from the link: GitHub — tableau/TabPy: Execute Python code on the fly and display results in Tableau visualizations

2. Click on clone or download button on upper right corner

Github — TabPy

3. Installing instructions: Tableau Integration with Python — Step by Step

4. Extract TabPy-master.zip: Execute setup.bat

5. Wait for this message

6. Set up Tableau Desktop with Python

7. Configure a Tableau connection for listening from python in Tableau. Go on Help menu > Settings and Performance > Manage External Service Connection

Python code for Tabpy integration: (See Github Link below for details)

Here, we have used Naïve Bayes and Logistic regression for classifying the cancer as malignant or benign. It is a supervised learning technique. (Github link in the image description)

Python code for classification problem: https://github.com/sawantpurva/Tab-Py-Integration

We have checked the connection by running the tabpy_client statement in python and check that is tableau connected by going to localhost:9004/endpoints. The same definition is seen there.

Checking connection
Jupyter Notebook

We have created various parameters in tableau to change the classification attributes to change the classification interaction variables.

Sample Parameters for users to change variable values

TabPy Query:

SCRIPT_STR(“return tabpy.query(‘DiagnosticsDemo’,_arg1,_arg2,_arg3,_arg4,_arg5,_arg6,_arg7,_arg8,_arg9)[‘response’]”,[Cl.thickness Parameter],[Cell.size Parameter],[Cell.shape Parameter],[Marg.adhesion Parameter],[Epith.c.size Parameter],[Bare.nuclei Parameter],[Bl.cromatin Parameter],[Normal.nucleoli Parameter],[Mitoses Parameter])

TabPy script in Tableau

Result:

The sole motivation of this article is to learn Naïve Bayes and Logistic Regression and understand TabPy and its applications in real world. Using this as a proof of concept, we intend to explore and tackle more problems with similar approach.

I aim to make this a living document, so any updates and suggested changes can always be included. Feedback is welcomed. If you enjoyed reading this article, please share your views in the comment section below to show your support.

How I build an AI to play Dino run on Acing AI has over 950 claps and was an article which had great engagement. Continuing the trend this article is an important addition to showcase a portfolio in Acing AI Portfolios.

Subscribe to our Acing AI newsletter, I promise not to spam and its FREE!

Thanks for reading! 😊 If you enjoyed it, test how many times can you hit 👏 in 5 seconds. It’s great cardio for your fingers AND will help other people see the story.

--

--