Did you know that GitHub Copilot can be a great
assistant, helping you write in your Jupyter notebook, giving you
suggestion with your Python code or your data analysis task?
I'm Carlotta Castelluccio, Cloud advocate at Microsoft, focusing on
artificial intelligence and machine learning. And in this video I'm
going to give you a practical example of it.
Jupyter notebook is one of the most popular tools used
by data scientists for data and machine learning projects. It
lets you easily combine Markdown text.
An executable source code on one cameras and let you
quickly visualize the results of your experiments or your data.
If you are new to Copilot, you might want to
watch an introductory video about this powerful AI assistant before
deep diving with me in this video into how it
helps you with Jupyter notebook development. For this demo we
are going to create a Jupyter notebook in Visual Studio
Code. We are going to use two extensions GitHub Copilot
extension.
And a GitHub code spaces extension. And now working in
a code space is very similar to working on a
web container in a virtual machine on the cloud. You
can commit to your GitHub repository a few configuration files
to set up your development environment with the settings and
prerequisites required for your data science experiments. So I have
here my two CPU cores, 4 Giga memory code spaces
built upon one of my GitHub repository.
With a few requirements installed, like Python 3, dot, A
and some common Python data science libraries we're going to
import in the notebook. Going to the repo let me
create a new Jupyter notebook that I will rename Titanic
Data Analysis, where Copilot one key element of a notebook
is the kernel.
The kernel is a programming language specific process, in this
case Python, that executes the code cells in the notebook.
The first cell we want to add to this notebook
will be a markdown cell containing the title of the
notebook along with a description of what we are going
to do. To showcase GitHub Copilot capabilities with Jupyter notebooks,
I'm going to load here and explore the Titanic data
set.
One popular data set among data scientists collecting information about
a few 100 passengers who were aboard the Titanic at
the time of the fatal accident. So the title I'll
be giving to this notebook will be Exploring Titanic Data
with Copilot. You can notice how as it start typing,
Copilot starts giving me text completions.
The great suggestions that appear based on the most robable
text that should follow my prompt. To give some context
to the demo I'm going to build. I start also
writing a descripcion of the Titanic history.
And see if Copilot can help me in this task.
So let me write the Titanic is and see what
Copilot suggests. So is a famous ship that sank in
1912. The data set contains information about the passengers on
the ship, and the goal of this notebook is to
explore the data set and find out what factors made
people more likely to survive. Since it's a good fit
for my notebook, I'm going to accept the whole suggestion
by clicking on top.
As a next step, let's start writing some Python code
with the help of our AIP programmer. First of all,
let's import the pandas library to load and handle data
in our notebook, and let's specify the URL of the
Titanic data set we'd like to explore.
By just clicking on the enter button here, I get
suggested code from Copilot, which is the code to upload
the data into a pandas data frame from the specified
URL. This is one way Copilot uses to help us
writing our code, simply suggesting our next line starting from
what we wrote. In this case the prompt is written
in Python.
However, Copilot can also help us use English as programming
language by converting an instruction written in natural language as
a Python comment, for example, into a line of code.
Now we might want to have a quick overview of
the first few rows of our data set, so let's
write our request in English, like a Python comment. So
let's have an overview of the data.
By printing the 1st 5 rows and then let's click
on enter. The result of the code suggested by Copilot
shows all the columns and the first five rows of
our data. So our data set contains the binary indicator
if the passenger survived the passenger class, the name, sex
and the age of the passenger, the ticket number and
the ticket fare.
The Cabin and Port of departure. There are also two
other columns whose titles are not so clear, Site SP
and Part. We can rely on the Q&A feature to
clarify. Let's create a new cell and let's ask our
question to Copilot. What is the meaning of Site SP?
Site SP is the number of siblings and spouses aboard
the Titanic Wonderful?
Next question, what is the meaning of Parch? Let's see
the top Copilot answer. Parch is the number of parents
and children aboard the Titanic. Now that's very much clearer.
Thanks Copilot. Let's conclude this quick data overview by looking
at how many people from the ones trapped in our
data set survived the shipwreck and how many didn't.
Let's again create a new Python comment. Let's compute how
many passengers have survived and let's print the value. So
it is now elaborating the answer yes. So we have
the the command we we were looking for to compute
the number of survived and the print command.
Let's now compute how many passengers did not survive and
let's print the value. Copilot is taking some time to
give us an answer, so in this case we can
start typing the answers to see if we get a
suggestion. For example, not survive which is the name of
our variable, and then equal and we wait for the
suggestion and then we print the result. Great, GitHub copilot
helped us.
Learn from the data that 342 passengers were lucky enough
to survive to the tragedy and 549 lost their lives
in the accident. Now that we have explored the beat
our data, the last piece I wish to show you
is how Copilot can help us perform data visualization.
In our Jupyter notebook, data visualization is a significant step
of data analysis, enabling us to retrieve insights from the
data we might not simply extract otherwise. Something we can
do, for example, is exploring the correlation between the number
of passengers survived and their class to check if the
class is a significant factor in passengers likely to survive.
The Hollywood narration of the Titanic shipwreck told us that
there's a huge correlation between the two.
Let's see if it is true. To do so, let's
create a new card cell in which we write our
instruction, which is. Let's look at the correlation between the
column survive, which is our binary label, and the column
Pclass, which is the passenger class. Let's add that
we want to visualize the number of people per each
class.
Survive or not with a categorical kind of plot and
let's click, Enter. Get up. Copilot convert our comment into
a few lines of code. First of all, it imports
the seaborne library, and then it builds the cat plot.
So let's execute the code suggested by Copilot and let's
look at the resulting graph. We can see that the
first class is the only one for which the number
of people survived.
Is higher than the number of people who did it.
If we look at the first class, number of people
who didn't survive is very much higher than people survived,
even if the total number of passengers in the first
class is the highest. Confirming our first guess. We have
seen how GitHub Copilot can help us with Jupyter Notebooks
development by suggesting the description of our project in the
markdown cells, generating code from our comments, or answering our
questions.
Beat up Copilot is a great tool that makes our
work easier and more featured, enabling us to focus on
more complex and creative task. But let's always remember that
a code generated by Copilot is not perfect and as
as developers are the actual pilots responsible for our code
written with the help of an AI assistant or not.
Thanks for watching this video, hope you enjoyed it. And
if you got some value out of these, make sure
to like and subscribe to the channel if you.
Are interested also in learning more about using GitHub coiled
with other rogramming languages and frameworks, check out the other
videos of this series.