Skip to main content
Workforce LibreTexts

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}}}\)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    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.

    import requests
    
    # download the entire book from the Project Gutenberg website
    url = 'https://www.gutenberg.org/cache/epub/113/pg113.txt'
    garden = requests.get(url).text
    
    # separate into chapters
    garden_chapters = garden.split('CHAPTER ')[1:]
    print(garden_chapters[0][:200])  # print the first 200 characters of the first chapter to check
    Output?
    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.

    # Find the number of characters and number of words in the book
    
    # initialize counters at 0, since there are 0 characters and 0 words at the start
    total_characters = 0
    total_words = 0
    
    # go through the chapters and count all printable characters and words
    for chapter in garden_chapters:
        total_characters += len(chapter) - chapter.count(' ')
        words = chapter.split()
        total_words += len(words)
    
    print(f'Number of characters: {total_characters:,d}')
    print(f'Number of words: {total_words:,d}')
    Output?
    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.

    # Store the chapters into a table or a DataFrame and name it chapters
    
    import pandas as pd
    
    # store the chapters into a table where each chapter is one row of the table
    chapters = pd.DataFrame({'chapters': garden_chapters})
    
    # print the first 5 rows of the table to check
    chapters.head()
    Output?
      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.

    # Find the number of times the names of the characters appear
    
    # identify the names of the characters to count
    names = ['Mary', 'Colin', 'Dickon', 'Craven', 'Martha', 'Ben', 'Medlock']
    
    # create room in memory to store the counts of each name
    name_counts = pd.DataFrame(columns=['Name', 'Count'])
    counts = {}
    
    # go through each name and count how many times it appears in the chapters
    for name in names:
        count = 0
        for chapter in chapters['chapters']:
            count += chapter.lower().count(name.lower())
        counts[name] = count
    
    # store the name counts into a DataFrame for easier viewing
    for name, count in counts.items():
        name_counts = pd.concat([name_counts, pd.DataFrame({'Name': [name], 'Count': [count]})], ignore_index=True)
    
    name_counts
    Output?
      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.

    # Plot the count of each name
    
    import matplotlib.pyplot as plt
    
    name_counts.plot(x='Name', y='Count', kind='barh', legend=False)
    plt.xlabel("Character Name")
    plt.ylabel("Number of Occurrences")
    plt.title("Count of Each Character's Name in 'The Secret Garden'")
    plt.show()
     

    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.


    This page titled 1: Introduction to Data Science was last modified on Sun, 11 Oct 2026 21:43:03 GMT and is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Clare Nguyen.