Principles of Data Science - Notes
Data Science Terminology
- Data science is the process of acquiring knowledge through data to:
- Make informed decisions
- Predict the future
- Understand the past/present
- Create new industries/products
Basic Data Science Terminology
- Data: A collection of information in either a structured or unstructured format.
- Structured Data: Data sorted into a row/column structure.
- Unstructured Data: Data in a free form, like text or raw audio/signals.
- Semi-structured data: Data that doesn't conform entirely to a relational database but contains tags (e.g., XML and JSON files)
Why Data Science?
- Data science augments human capabilities by parsing large volumes of data and discovering relationships within the data.
- An example of data science is using machine learning to aid in the diagnosis, treatment, and prevention of illnesses such as COVID-19.
- Creating effective algorithms requires a combination of:
- Math/statistics: Using equations and formulas to perform analysis.
- Computer programming: The ability to use code to create outcomes on a computer.
- Domain knowledge: Understanding the problem domain (e.g. medicine, finance).
The Data Science Venn Diagram
- Math/statistics: Using equations and formulas to perform analysis
- Computer programming: The ability to use code to create outcomes on a computer
- Domain knowledge: Understanding the problem domain (medicine, finance, social science, etc.)
- The intersection of math and coding is machine learning.
The Math
- Math is used to formalize relationships between variables and build data models.
- A data model refers to an organized and formal relationship between elements of data, usually meant to simulate a real-world phenomenon.
- Topics range from basic algebra to advanced probabilistic and statistical modeling.
Computer Programming
- Computer languages communicate with machines.
- Python, Julia, and R are some of the languages available; this book exclusively uses Python.
- Python is used because it is easy to read and write, is a common language, has a vast online community, and has prebuilt data science modules, such as pandas, PyTorch, Scikit-learn, Seaborn, NumPy/scipy, Requests, and BeautifulSoup.
Domain Knowledge
- Domain knowledge focuses on the particular topic you are working on.
- A big part of domain knowledge is presentation. Your results are only as good as your vehicle of communication.
Some More Terminology
- Machine learning: Giving computers the ability to learn from data without explicit rules
- Statistical model: Taking advantage of statistical theorems to formalize relationships between data elements in a (usually) simple mathematical formula.
- Exploratory data analysis (EDA): Preparing data to standardize results and gain quick insights. EDA is concerned with data visualization and preparation.
- Data mining: The process of finding relationships between elements of data
Data Science Case Studies
- An example of a data science case study is automating government paper pushing of social security claims.
- Another case study is scraping job descriptions for data scientists to find the most common keywords that people use in their job descriptions.
Types of Data
Structured vs. Unstructured Data
- Structured Data: Organized into rows and columns.
- Unstructured Data: Exists in a free form (e.g., text, images, videos).
- Semi-structured data contains element of both, examples are XML and JSON files, emails, and some types of NoSQL databases.
Quantitative vs. Qualitative Data
- Quantitative Data: Described using numbers, and basic mathematical procedures, including addition, are possible on the set.
- Qualitative Data: Cannot be described using numbers and basic mathematics
- Quantitative data can be broken down into:
- Discrete counted data that only takes on certain values.
- Continuous measured data that exists on an infinite range of values.
The Four Levels of Data
- Nominal: Data described purely by name or category (e.g., gender, nationality).
- Ordinal: Data with a rank order, but no relative differences between observations (e.g., Likert scales).
- Measure of center: Median
- Interval: Data with meaningful subtraction between data points (e.g., temperature in Celsius).
- Measure of center: arithmetic Mean
- Measure of variation: Standard deviation
- Find the mean of the data.
- For each number in the dataset, subtract it from the mean and then square it.
- Find the average of each square difference.
- Take the square root of the number obtained in Step 3 β this is the standard deviation.
- Ratio: Data with meaningful multiplication and division (e.g., temperature in Kelvin, money).
- Measure of center: Arithmetic mean still holds meaning at this level, as does a new type of mean called the geometric mean, which is the square root of the product of all the values.
- geometric mean is the square root of the product of all the values.
The Five Steps of Data Science
- Data science follows a structured, step-by-step process that, when followed, preserves the integrity of the results and leads to a deeper understanding of the data and the environment the data comes from.
- The five steps of data science are:
- Asking an interesting question
- Obtaining the data
- Exploring the data
- Modeling the data
- Communicating and visualizing the results
Asking an Interesting Question
- The first and perhaps most important step in the data science process.
Obtaining the Data
- Sourcing and collecting the data that you will need to answer the question or solve the problem you have identified.
Exploring the Data
- Examining the characteristics and patterns in your data to gain a better understanding of it.
- Questions to guide data exploration:
- Is the data structured or not?
- What does each row represent?
- What does each column represent?
- Are there any missing data points?
- Do we need to perform any transformations on the columns?
- pandas is a commonly used Python package for data manipulation and analysis.
- DataFrames are two-dimensional in nature. DataFrames are organized in a row/column structure just as spreadsheets are.
- The Series object is simply a DataFrame, but only with one dimension.
Modeling the Data
- Using statistical and ML techniques to build models that can be used to make predictions or inform decision-making.
Communicating and Visualizing the Results
- Effectively sharing your findings and insights with others.
Basic Mathematics
- Mathematics is one of the three crucial components of data science.
- The concepts presented in this chapter will not only be useful in later chapters but also in understanding probabilistic and statistical models.
Vectors and Matrices
- A vector is a one-dimensional array representing a series of numbers. Vectors give us a simple way of storing multiple dimensions of a single data point/observation.
- Example: If β x = (3 6 8) then π 1 = 3
- A matrix is a two-dimensional representation of arrays of numbers.
- The dimension of a matrix, denoted by n x m (n by m), tells us that the matrix has n rows and m columns.
Arithmetic Symbols
- The uppercase sigma, β, symbol is a universal symbol for addition. Whatever is to the right of the sigma symbol is usually something iterable, meaning that we can go over it one by one (for example, a vector).
- Example: If we have a vector (x) of length n, the mean of the vector can be calculated as follows: mean=n1ββxiβ
- The dot product is an operator such as addition and multiplication. It is used to combine two vectors.
- Example: (3,7)β
(9,5)=3β9+7β5=62
Logarithms/Exponents
- An exponent tells you how many times you have to multiply a number by itself.
- A logarithm is a number that answers the question βWhat exponent gets me from the base to this other number?β
- Exponents and logarithms are most important when dealing with growth.
- Example: A=Pert
- A denotes the final amount
- P denotes the principal investment
- e denotes a constant (2.718)
- r denotes the rate of growth
- t denotes the time (in years)
Set Theory
- Set theory involves mathematical operations at the set level. It is sometimes thought of as a basic fundamental group of theorems that governs the rest of mathematics.
- A set is a collection of distinct objects. A set can be thought of as a list in Python but with no repeat objects.
- The magnitude of a set is the number of elements in the set and is represented as follows: β£Aβ£=magnitudeofA
- If we wish to denote that an element is within a set, we can use the epsilon notation, as shown here: 2β1,2,3
- The intersection of two sets is a set whose elements appear in both sets. It is denoted using the β© symbol.
- The union of two sets is a set whose elements appear in either set. It is denoted using the βͺ symbol.
- The Jaccard measure (Jaccard similarity) between the two sets is defined as follows: JS(A,B)=β£AβͺBβ£β£Aβ©Bβ£β
Linear Algebra
- Linear algebra, an area of mathematics that deals with matrices and vectors, provides the necessary tools to perform these calculations efficiently.
- Matrix multiplication
- To multiply matrices, their dimensions must match up. This means that the first matrix must have the same number of columns as the second matrix has rows.
- The resulting matrix will always have dimensions equal to the outer numbers in the dimension pairs.
- Each element is the result of a dot product between rows and columns of the original matrices.