1: Introduction to Data Science
- Page ID
- 45255
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\dsum}{\displaystyle\sum\limits} \)
\( \newcommand{\dint}{\displaystyle\int\limits} \)
\( \newcommand{\dlim}{\displaystyle\lim\limits} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\(\newcommand{\longvect}{\overrightarrow}\)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\ket}[1]{\left| #1 \right>}\)
\(\newcommand{\bra}[1]{\left< #1 \right|}\)
\(\newcommand{\braket}[2]{\left< #1 \vphantom{#2} \right| \left. #2 \vphantom{#1} \right>}\)
\(\newcommand{\braopket}[3]{\left< #1 \vphantom{#2}\vphantom{#3} \right| #2 \vphantom{#1}\vphantom{#3} \left| #3 \vphantom{#1}\vphantom{#2} \right>}\)
\(\newcommand{\qmvec}[1]{\mathbf{\vec{#1}}}\)
\(\newcommand{\op}[1]{\hat{\mathbf{#1}}}\)
\(\newcommand{\expect}[1]{\langle #1 \rangle}\)
\(\newcommand{\dfn}[1]{\emph{\textbf{#1}}}\)
The US National Institute of Standards and Technology (NIST) defines data science as a "field that combines domain expertise, programming skills, and knowledge of mathematics and statistics to extract meaningful insights from data." In data science we analyze data to pull out valuable insights, draw conclusions, make predictions, and support decision making.
Data science is part of everyday life. If you've ever seen personalized ads or browsed recommended song lists based on music that you're currently listening, you've experienced data science at work. Data science combines skills from statistics and mathematics, computer science, and domain-specific knowledge. This makes the field very versatile, with domains spanning healthcare, finance, business, education, scientific and social research, and many more.
The first important part of data science is the data itself. In this book we will discover the importance of using a large dataset with diverse data points if we want our conclusions about the data to be useful. Then, with an appropriate large and diverse dataset, we will use programming techniques to apply statistical calculation to explore the data, make predictions and inferences, and draw conclusions about the data.
A Little Tour of Data Science
We now take a look at a simple example of data science at work by exploring data from the classic book The Secret Garden by Frances Hodgson Burnett. We'll investigate what a large and diverse dataset means, then we explore the dataset and see whether we can make a prediction with the data. Along the way we'll see some of the code and statistical concepts that are used by data scientists.
[The book The Secret Garden is online in the public domain at Project Gutenberg. You can use the link to read the online book if you like.]
Gather Data
The first step is to locate the data and load it into the computer memory so we can use the Python programming language to work with it.
I.
THERE IS NO ONE LEFT
When Mary Lennox was sent to Misselthwaite Manor to live with her uncle
everybody said she was the most disagreeable-looking child ever seen.
It was true, too. She had
Now that we have the book chapters stored in memory at a location or variable named garden_chapters, we can start the data analysis. One of the most common starting points is to look at the size of the data. Below we find how many characters and how many words the book has.
Number of characters: 379,495
Number of words: 83,346
In the output above we see that the character dataset and the word dataset are both large, and each dataset is likely diverse because it has a variety of characters or words, as most books do.
Analyze Data
Next we will analyze specific words in the text and see whether the data tells us something about the book.
First, we take the list of all chapters of the book and store them in a special container that's commonly used for data analysis: a DataFrame. A DataFrame is a table consisting of rows and columns. We'll put each chapter in a row of the DataFrame, so the DataFrame has one column which contains the chapters of the book.
| chapters | |
|---|---|
| 0 | I.\r\nTHERE IS NO ONE LEFT\r\n\r\n\r\nWhen Mar... |
| 1 | II.\r\nMISTRESS MARY QUITE CONTRARY\r\n\r\n\r\... |
| 2 | III.\r\nACROSS THE MOOR\r\n\r\n\r\nShe slept a... |
| 3 | IV.\r\nMARTHA\r\n\r\n\r\nWhen she opened her e... |
| 4 | V\r\nTHE CRY IN THE CORRIDOR\r\n\r\n\r\nAt fir... |
From the output above, we can see the first five rows of the DataFrame, numbered 0-4. Each row shown is the beginning part of a chapter.
The book The Secret Garden has several major characters and their names are: Mary, Colin, Dickon, Craven, Martha, Ben, and Medlock. Without reading the book, we want to use the dataset of the words in the book to predict which of these characters is the main character of the story.
To do this, we'll count the number of times each name appears in the book. Counting the number of occurrences of a data value in a dataset is a basic statistics concept. From the count of each name we can infer who the main character is by choosing the name with the highest count.
| Name | Count | |
|---|---|---|
| 0 | Mary | 694 |
| 1 | Colin | 333 |
| 2 | Dickon | 311 |
| 3 | Craven | 114 |
| 4 | Martha | 194 |
| 5 | Ben | 148 |
| 6 | Medlock | 134 |
From the output above, we see that Mary has the highest count, so we can conclude or infer that Mary is most likely the main character. When we infer something, we reach a conclusion about it by combining facts with reasoning, rather than by directly observing it. In this case the fact (Mary has the highest name count) and the reasoning (the most important character will appear the most times in the book) are used to infer that Mary is the main character, without actually reading the book.
Visualize Data
Even though the name count for Mary is already very convincing, often in data science we display the resulting data in an appropriate plot to clearly show the pattern in the data. This is called data visualization.
Let's plot the counts of all the names and see if data visualization really shows who the main character is.
It's pretty clear that Mary's name appears the most in the book, so we can infer that Mary is the main character of the story. If you've read the book The Secret Garden, you can confirm whether our data science exercise reaches a correct conclusion, and if you haven't read the book, a quick online search can also confirm our conclusion.
Through this quick tour, we see a few key components of a data science application:
- A large and diverse dataset. If we only looked at one chapter of the book (a small dataset), the count of each character name in the chapter may not be the same as the count in the entire book and we might arrive at the wrong main character. This is why choosing a large and diverse dataset is important.
- Using the appropriate statistical methods and visualization methods, we can see different patterns in the data, such as how large the dataset is.
- With a good dataset and appropriate statistical methods, we can come to a correct conclusion about a characteristic of the book (such as who the main character is) without personally reading the book.
It is the extraction of meaningful patterns or insights from data that makes data science an important tool for many industries, and it also makes data science the basis for machine learning and artificial intelligence.
Summary
A data scientist uses programming and statistical techniques to analyze large and diverse datasets and infer characteristics of the data.
The ability to make inferences from data allows for data driven decisions, such as what medical treatment to use or what business policy to implement, and leads to the development of artificial intelligence models that work with and make predictions based on insights and relationships in the data.


