3-minute data science dashboards with ChatGPT-4 and Dash

María Elena Martínez Manzanares
MCD-UNISON
Published in
4 min readMay 5, 2023
ChatGPT and Dash

In this post, we will explore the process of creating an interactive dashboard for low-dimensional hyperparameter tuning and descriptive statistics using Dash and ChatGPT-4 for rapid development. Let’s dive in!

Dash is a popular and powerful framework for creating interactive dashboards in Python. It offers extensive capabilities for building all types of dynamic dashboards, but its flexibility can sometimes result in a steep learning curve and tricky debugging. This is where ChatGPT comes into play — this innovative tool streamlines the development process for various software applications, including personalized dashboards, making it faster and more efficient.

We will evaluate the capabilities of ChatGPT-4 in assisting the creation of data science dashboards, enabling you to develop engaging and informative visualizations easily.

We will generate a dataset of 200 paired data points for this demonstration using Scikit-learn’s make_blobs function. We’ll open ChatGPT-4 and formulate our request based on the best practices outlined in OpenAI’s course, “ChatGPT Prompt Engineering for Developers”. In this case, we formulate the following prompt:

Your job is to create a dashboard code using Dash in Python. The final dashboard must have a slider to control the “eps” hyperparameter of a DBSCAN model created using the sklearn’s DBSCAN module and must display a scatter plot of the clusters obtained using the current hyperparameter. Consider the following instruction for the creation of the dashboard.

-Step 1: When the dashboard is initialized, generate a table of 200 random numbers using scklearn’s make_moons module.
-Step 2: Adjust a DBSCAN model using sklearn’s default parameters.
-Step 3: Create a dashboard using Dash that displays a scatter plot of the clusters obtained using the current hyperparameter.
-Step 4: Add a slider to control de hyperparameter “eps” of the DBSCAN model.

Each time the user changes the value of “eps” the DBSCAN model must readjust the model and display a new scatter plot to visualize the newly obtained clusters.

ChatGPT-4 returns the following snippet:

This 3-minute dashboard looks like this.

Dashboard for hyperparameter tunning

Additionally, if we’re uncertain about the best model for our dataset, we can leverage ChatGPT-4 to expand the dashboard by incorporating another Scikit-learn model. For instance, we can request ChatGPT-4 to create an updated dashboard to investigate the impact of tuning a K-means model on our data, offering a more comprehensive understanding of the clustering options available using the additional prompt.

Improve the dashboard by adding a list of possible models to be adjusted. Allow the user to select DBSCAN model or Kmeans model. If the user selects DBSCAN, the slider must control the “eps” hyperparameter. If the user selects “Kmeans”, the slider must control the “n_clusters” hyperparameter.

After a short debugging of the first version of the code provided, we obtained the following snippet.

This is the resulting dashboard.

Dashboard with a dropdown menu to select the clustering model

Finally, we can ask ChatGPT-4 for a new block in the dashboard that allows us to do a quick exploratory data analysis of the data.

Include at the top of the dashboard a descriptive statistics section adding a histogram and a table with the value of the min, max, mean and std of the generated data. Make the title of the dashboard: “Descriptive statistics and hyperparameter tunning using ChatGP4 and Dash”. In the section of descriptive statistics add the subtitle “Descriptive statistics” and in the section of DBSCAN-Kmeans add the subtitle “DBSCAN and Kmeans hyperparameter tunning”.

In this case, we perform an iterative process with ChatGPT-4 for debugging and addressing the deprecated Dash modules, requiring roughly three additional prompts. The final code is as follows.

If we compile the code, the resulting dashboard looks like this.

Dashboard with descriptive statistics block

Developing the initial dashboard up to its final version took about 15 minutes. The takeaway is that ChatGPT enables the rapid and straightforward creation of interactive dashboards for data analysis or educational purposes. This accelerates the EDA process, the visualization of hyperparameter tuning outcomes, and sharing of results, allowing for effective communication and insights in just a matter of minutes.

--

--

María Elena Martínez Manzanares
MCD-UNISON

I’m a student at the University of Sonora specializing in stochastic processes and currently studying for a Ph.D. in Mathematics and an M.Sc. in Data Science.