Saturday, June 22, 2024
HomeMachine LearningHow Generative AI Can Assist You Enhance Your Knowledge Visualization Charts

How Generative AI Can Assist You Enhance Your Knowledge Visualization Charts


How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts
Picture from DALLE 3
 

5 Key Takeaways:

  • The essential construction of an information visualization chart
  • Utilizing Python Altair to construct an information visualization chart
  • Utilizing GitHub Copilot to hurry up chart era
  • Utilizing ChatGPT to generate related content material to your chart
  • Utilizing DALL-E so as to add partaking photographs to your chart

Are you bored with spending hours creating boring information visualization charts? Use the ability of generative AI to enhance your information visualization. On this article, we’ll discover how you should use generative AI to complement your chart. We’ll use cutting-edge instruments like Python Altair, GitHub Copilot, ChatGPT, and DALL-E to implement our chart with the assist of generative AI.How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

First, let’s implement the essential chart utilizing GitHub Copilot. Subsequent, we add textual annotations (such because the title) utilizing ChatGPT. Lastly, we’ll add photographs to the chart utilizing DALL-E. As a programming language, we’ll use Python and the Python Altair visualization library.

We are going to cowl:

  • Defining the use case
  • Constructing a fundamental chart: utilizing GitHub Copilot
  • Including annotations: ChatGPT
  • Including photographs: DALL-E.

 

 

As a use case, we’ll draw a chart representing the Analysis and growth expenditure by efficiency sectors utilizing the dataset launched by Eurostat underneath an Open Knowledge license. To make the method extra accessible, we’ll use a simplified model of the dataset, already transformed in CSV. The next desk reveals an extract of the dataset:

unit sectperf geo 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021
PC_GDP BES AT 1.87 1.84 2.05 2.09 2.2 2.18 2.19 2.14 2.16 2.2 2.23 2.22
PC_GDP BES BA 0.16 0.19 0.05 0.07 0.08
PC_GDP BES BE 1.38 1.49 1.59 1.62 1.66 1.7 1.73 1.87 2.05 2.33 2.48 2.42 p
PC_GDP BES BG 0.28 0.28 0.36 0.39 0.52 0.7 0.56 0.52 0.54 0.56 0.57 0.51

 

The dataset comprises the next columns:

  • unit – the worth for this column is at all times set to Share of gross home product (PC_GDP)
  • sectperf – efficiency sectors. Attainable values embody: enterprise enterprise (BES); authorities (GOV); larger schooling (HES); personal non-profit (PNP), and TOTAL
  • geo – European nations
  • 2010-2021 – the expenditure worth for the desired yr.

As a selected case, let’s concentrate on BES in Italy and draw a chart utilizing Python Altair, an information visualization library.

 

 

GitHub Copilot is a generative AI device you should use as an assistant whereas writing your code. In GitHub Copilot, you describe the sequence of actions that your software program should run, and GitHub Copilot transforms it into runnable code in your most well-liked programming language. The flexibility to make use of GitHub Copilot consists of studying the way to describe the sequence of actions.

 

Putting in Copilot

 

Earlier than utilizing GitHub Copilot, you have to first arrange a free trial or subscription to your private GitHub account. If you’re a instructor or a pupil, you’ll be able to arrange a free subscription plan on the following hyperlink: https://schooling.github.com/discount_requests/pack_application.

After you have activated a subscription plan, you’ll be able to configure Copilot as an extension of Visible Studio Code (VSC), a free, open-source code editor designed for builders to write down and debug code.

Observe the steps described beneath to configure VSC with Copilot:

  • Obtain VSC from its official web site: https://visualstudio.microsoft.com/it/downloads/
  • Open Visible Studio and navigate to the Extensions tab
  • Obtain and set up the GitHub Copilot extension, and choose Connect with your account from the dashboard.
  • Enter your GitHub credentials.
  • As soon as logged in, the extension will detect current repositories and supply choices for configuring new tasks.

 

Utilizing Copilot as a Code Assistant

 

Utilizing Copilot, let’s generate the essential chart for our visualization. To construct the chart, we carry out two steps:

  • Load and preprocess information – load the dataset as a Pandas DataFrame, drop pointless columns, choose solely rows associated to Italy, and use the Pandas soften() to transform columns associated to 2010-2021 into rows.
  • Construct the chart as a line chart.

Let’s begin with step one, load and preprocess information. Write the next directions for Copilot:

How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

Press the ENTER button in your keyboard, and Copilot begins producing the code comparable to the written directions. The next code snippet reveals a attainable output produced by Copilot:

import pandas as pd
import altair as alt

df = pd.read_csv('tsc00001.csv')
df = df.drop(columns=['unit'])
df = df[df['geo'] == 'IT']
df = df.drop(columns=['geo'])
df = pd.soften(df, id_vars=['sectperf'], var_name="date", value_name="worth")
df['date'] = df['date'].astype(int)
df['value'] = df['value'].astype(float)

 

Keep in mind that Copilot is a generative mannequin, so the output produced in your case could be completely different from the earlier one.

Now, let’s proceed with the directions to construct the chart. Write the next directions for Copilot:

How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

Copilot will produce a Python code just like the code snippet proven beneath:

chart = alt.Chart(df).mark_line().encode(
    x='date:O',
    y='worth',
    colour="sectperf"
)

chart.save('chart.html')

 

Save the script, and run it from the command line. As an output, the script produces an HTML file named chart.html. Open it utilizing your most well-liked browser. The next determine reveals the produced chart:

How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

Now that you’ve constructed the essential chart, you’ll be able to enhance it manually or utilizing Copilot. For instance, you’ll be able to ask Copilot to generate the code to extend the stroke width for BES. Add a comma after the colour line, and begin writing the directions as proven beneath:

How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

Press ENTER and watch for Copilot to write down the code for you. The next code snippet reveals a attainable output generated by Copilot:

strokeWidth=alt.situation(
        alt.datum.sectperf == 'BES',
        alt.worth(5),
        alt.worth(1)
    )

 

The next determine reveals the improved chart:

 
How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts
 

You’ll be able to additional enhance the chart by asking Copilot to rotate X labels, set the title, and so forth. You’ll be able to study extra particulars on the way to enhance your chart in [1]. The next determine reveals the decluttered model of the chart. You will discover the whole code at this hyperlink.

How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

As soon as the essential chart is prepared, we will proceed with the following step, utilizing ChatGPT to set the chart title.

 

Including annotations: ChatGPT

 

ChatGPT is a complicated language mannequin developed by OpenAI. It’s designed to interact in human-like conversations and supply clever responses. We will use ChatGPT to generate textual content for our chart, together with the title and the annotations.

To make use of ChatGPT, navigate to https://chat.openai.com/, log in to your account, or create a brand new one, and begin writing your prompts within the enter textual content field like a stay chat. Everytime you wish to begin a brand new subject, create a brand new chat session by clicking on the highest left button New Chat.

The Internet interface additionally offers a paid account that offers some extra options, corresponding to the chance to make use of superior fashions, and a collection of extra functionalities, corresponding to precedence assist, expanded customization choices, and unique entry to beta options and updates. .

To work together with ChatGPT, write an enter textual content (immediate) that defines the directions to be carried out. Alternative ways exist to construction a immediate for ChatGPT. On this article, we contemplate a immediate composed of three predominant consecutive texts:

  • Telling ChatGPT to behave in a selected [role] – for instance “You might be an examiner taking a look at highschool college students’ English papers.”
  • Telling ChapGPT to tailor its outputs to an supposed [audience] – for instance “Clarify your gradings in a approach that may be understood by excessive schoolers.”
  • Outline the [task] – for instance “Grade this textual content and clarify your reasoning.”

In our instance, we will formulate the immediate as follows:

Act as an information analyst wanting to speak to choice makers. Generate 5 titles for the next subject: A chart displaying efficiency sectors from 2010 to 2021. Efficiency sectors embody enterprise enterprise (BES); authorities (GOV); larger schooling (HES); and personal non-profit (PNP). You wish to concentrate on BES, which has the very best values over time.

ChatGPT generates 5 titles, as proven within the following determine:

How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

When you run the identical immediate once more, ChatGPT will generate one other 5 titles. For instance, we will select the primary title, Driving Development: A Decade of Enterprise Enterprise Efficiency Dominance (2010-2021), and set it because the title of our chart:

chart = alt.Chart(df).mark_line().encode(
   …
).properties(
    width=600,
    top=400,
    title=['Driving Growth:',
        'A Decade of Business Enterprise Performance Dominance (2010-2021)']
)

 

The next determine reveals the ensuing chart:

How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

The chart is sort of prepared. To enhance our chart readability and interact our viewers emotionally, we will add a picture.

 

Including photographs: DALL-E

 

DALL-E is a generative AI mannequin created by OpenAI. It combines the ability of GPT-3 with picture era capabilities, permitting it to create sensible photographs from textual descriptions. To make use of DALL-E, you have to arrange an account on the Open AI web site and purchase some credit.

Alternative ways exist to construction a immediate for DALL-E. On this article, we contemplate a immediate composed of:

In our case, we will generate a generic picture with the next subject: a black and white icon representing analysis and growth expenditure.

The next determine reveals a attainable output generated by DALL-E:

How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

Let’s select the third picture and add it to the chart, as proven within the following code snippet:

df_red = pd.DataFrame({'url': ['red.png']})

crimson = alt.Chart(df_red).mark_image(
    align='heart',
    baseline="prime",
    width=300,
    top=300
).encode(
    url="url"
)

chart = (crimson | chart + textual content)

 

To view the picture within the chart, you have to run it in an internet server. Run the next Python command from the listing containing the HTML file to run a easy internet server: python3 -m http.server, after which level to localhost:8000/chart.html. You must see a chart just like the next:

How Generative AI Can Help You Improve Your Data Visualization ChartsHow Generative AI Can Help You Improve Your Data Visualization Charts

You’ll be able to customise your chart as you like. For instance, you’ll be able to generate an icon for every efficiency sector.

 

 

Congratulations! You have got simply realized to make use of generative AI instruments to empower your information visualization charts!

  • First, write your fundamental chart utilizing GitHub Copilot.
  • Subsequent, use ChatGPT to generate textual descriptions to your chart, such because the title and the annotations.
  • Lastly, use DALL-E to generate photographs to incorporate in your chart to enhance readability and interact the viewers.

You’ll be able to obtain the complete code described on this instance from this GitHub repository. As well as, you will discover extra particulars on the way to use generative AI in information storytelling in [1].

 

References

 

[1] A. Lo Duca.Knowledge Storytelling with Generative AI utilizing Python and Altair. Manning Publications.

[2] A. Lo Duca. Utilizing Python Altair for Knowledge Storytelling. Educative Inc.

 

Angelica Lo Duca (Medium) (@alod83) is a researcher on the Institute of Informatics and Telematics of the Nationwide Analysis Council (IIT-CNR) in Pisa, Italy. She is a professor of “Knowledge Journalism” for the Grasp diploma course in Digital Humanities on the College of Pisa. Her analysis pursuits embody Knowledge Science, Knowledge Evaluation, Textual content Evaluation, Open Knowledge, Internet Functions, Knowledge Engineering, and Knowledge Journalism, utilized to society, tourism, and cultural heritage. She is the writer of the guide Comet for Knowledge Science, revealed by Packt Ltd., of the upcoming guide Knowledge Storytelling in Python Altair and Generative AI, revealed by Manning, and co-author of the upcoming guide Studying and Working Presto, by O’Reilly Media. Angelica can also be an enthusiastic tech author.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments