The Statistics and Calculus with Python Workshop

Book description

With examples and activities that help you achieve real results, applying calculus and statistical methods relevant to advanced data science has never been so easy

Key Features

  • Discover how most programmers use the main Python libraries when performing statistics with Python
  • Use descriptive statistics and visualizations to answer business and scientific questions
  • Solve complicated calculus problems, such as arc length and solids of revolution using derivatives and integrals

Book Description

Are you looking to start developing artificial intelligence applications? Do you need a refresher on key mathematical concepts? Full of engaging practical exercises, The Statistics and Calculus with Python Workshop will show you how to apply your understanding of advanced mathematics in the context of Python.

The book begins by giving you a high-level overview of the libraries you'll use while performing statistics with Python. As you progress, you'll perform various mathematical tasks using the Python programming language, such as solving algebraic functions with Python starting with basic functions, and then working through transformations and solving equations. Later chapters in the book will cover statistics and calculus concepts and how to use them to solve problems and gain useful insights. Finally, you'll study differential equations with an emphasis on numerical methods and learn about algorithms that directly calculate values of functions.

By the end of this book, you’ll have learned how to apply essential statistics and calculus concepts to develop robust Python applications that solve business challenges.

What you will learn

  • Get to grips with the fundamental mathematical functions in Python
  • Perform calculations on tabular datasets using pandas
  • Understand the differences between polynomials, rational functions, exponential functions, and trigonometric functions
  • Use algebra techniques for solving systems of equations
  • Solve real-world problems with probability
  • Solve optimization problems with derivatives and integrals

Who this book is for

If you are a Python programmer who wants to develop intelligent solutions that solve challenging business problems, then this book is for you. To better grasp the concepts explained in this book, you must have a thorough understanding of advanced mathematical concepts, such as Markov chains, Euler's formula, and Runge-Kutta methods as the book only explains how these techniques and concepts can be implemented in Python.

Table of contents

  1. The Statistics and Calculus with Python Workshop
  2. Preface
    1. About the Book
      1. Audience
      2. About the Chapters
      3. Conventions
      4. Code Presentation
      5. Setting up Your Environment
      6. Software Requirements
      7. Installation and Setup
      8. Installing Python
      9. Project Jupyter
      10. Installing Libraries
      11. Accessing the Code Files
  3. 1. Fundamentals of Python
    1. Introduction
    2. Control Flow Methods
      1. if Statements
      2. Exercise 1.01: Divisibility with Conditionals
      3. Loops
        1. The while Loop
        2. The for Loop
      4. Exercise 1.02: Number Guessing Game
    3. Data Structures
      1. Strings
      2. Lists
      3. Exercise 1.03: Multi-Dimensional Lists
      4. Tuples
      5. Sets
      6. Dictionaries
      7. Exercise 1.04: Shopping Cart Calculations
    4. Functions and Algorithms
      1. Functions
      2. Exercise 1.05: Finding the Maximum
      3. Recursion
      4. Exercise 1.06: The Tower of Hanoi
      5. Algorithm Design
      6. Exercise 1.07: The N-Queens Problem
    5. Testing, Debugging, and Version Control
      1. Testing
      2. Debugging
      3. Exercise 1.08: Testing for Concurrency
      4. Version Control
      5. Exercise 1.09: Version Control with Git and GitHub
      6. Activity 1.01: Building a Sudoku Solver
    6. Summary
  4. 2. Python's Main Tools for Statistics
    1. Introduction
    2. Scientific Computing and NumPy Basics
      1. NumPy Arrays
      2. Vectorization
      3. Exercise 2.01: Timing Vectorized Operations in NumPy
      4. Random Sampling
    3. Working with Tabular Data in pandas
      1. Initializing a DataFrame Object
      2. Accessing Rows and Columns
      3. Manipulating DataFrames
      4. Exercise 2.02: Data Table Manipulation
      5. Advanced Pandas Functionalities
      6. Exercise 2.03: The Student Dataset
    4. Data Visualization with Matplotlib and Seaborn
      1. Scatter Plots
      2. Line Graphs
      3. Bar Graphs
      4. Histograms
      5. Heatmaps
      6. Exercise 2.04: Visualization of Probability Distributions
      7. Visualization Shorthand from Seaborn and Pandas
      8. Activity 2.01: Analyzing the Communities and Crime Dataset
    5. Summary
  5. 3. Python's Statistical Toolbox
    1. Introduction
    2. An Overview of Statistics
    3. Types of Data in Statistics
      1. Categorical Data
      2. Exercise 3.01: Visualizing Weather Percentages
      3. Numerical Data
      4. Exercise 3.02: Min-Max Scaling
      5. Ordinal Data
    4. Descriptive Statistics
      1. Central Tendency
      2. Dispersion
      3. Exercise 3.03: Visualizing Probability Density Functions
      4. Python-Related Descriptive Statistics
    5. Inferential Statistics
      1. T-Tests
      2. Correlation Matrix
      3. Exercise 3.04: Identifying and Testing Equality of Means
      4. Statistical and Machine Learning Models
      5. Exercise 3.05: Model Selection
    6. Python's Other Statistics Tools
      1. Activity 3.01: Revisiting the Communities and Crimes Dataset
    7. Summary
  6. 4. Functions and Algebra with Python
    1. Introduction
    2. Functions
      1. Common Functions
      2. Domain and Range
      3. Function Roots and Equations
      4. The Plot of a Function
      5. Exercise 4.01: Function Identification from Plots
    3. Function Transformations
      1. Shifts
      2. Scaling
      3. Exercise 4.02: Function Transformation Identification
    4. Equations
      1. Algebraic Manipulations
      2. Factoring
      3. Using Python
      4. Exercise 4.03: Introduction to Break-Even Analysis
    5. Systems of Equations
      1. Systems of Linear Equations
      2. Exercise 4.04: Matrix Solution with NumPy
      3. Systems of Non-Linear Equations
      4. Activity 4.01: Multi-Variable Break-Even Analysis
    6. Summary
  7. 5. More Mathematics with Python
    1. Introduction
    2. Sequences and Series
      1. Arithmetic Sequences
      2. Generators
      3. Exercise 5.01: Determining the nth Term of an Arithmetic Sequence and Arithmetic Series
      4. Geometric Sequences
      5. Exercise 5.02: Writing a Function to Find the Next Term of the Sequence
      6. Recursive Sequences
      7. Exercise 5.03: Creating a Custom Recursive Sequence
    3. Trigonometry
      1. Basic Trigonometric Functions
      2. Exercise 5.04: Plotting a Right-Angled Triangle
      3. Inverse Trigonometric Functions
      4. Exercise 5.05: Finding the Shortest Way to the Treasure Using Inverse Trigonometric Functions
      5. Exercise 5.06: Finding the Optimal Distance from an Object
    4. Vectors
      1. Vector Operations
      2. Exercise 5.07: Visualizing Vectors
    5. Complex Numbers
      1. Basic Definitions of Complex Numbers
      2. Polar Representation and Euler's Formula
      3. Exercise 5.08: Conditional Multiplication of Complex Numbers
      4. Activity 5.01: Calculating Your Retirement Plan Using Series
    6. Summary
  8. 6. Matrices and Markov Chains with Python
    1. Introduction
    2. Matrix Operations on a Single Matrix
      1. Basic Operations on a Matrix
      2. Inspecting a Matrix
      3. Exercise 6.01: Calculating the Time Taken for Sunlight to Reach Earth Each Day
      4. Operations and Multiplication in Matrices
      5. Axes in a Matrix
      6. Exercise 6.02: Matrix Search
      7. Multiple Matrices
        1. Broadcasting
    3. Operations on Multiple Matrices
      1. Identity Matrix
      2. The eye Function
      3. Inverse of a Matrix
      4. Logical Operators
      5. Outer Function or Vector Product
    4. Solving Linear Equations Using Matrices
      1. Exercise 6.03: Use of Matrices in Performing Linear Equations
    5. Transition Matrix and Markov Chains
      1. Fundamentals of Markov Chains
        1. Stochastic versus Deterministic Models
        2. Transition State Diagrams
        3. Transition Matrices
      2. Exercise 6.04: Finding the Probability of State Transitions
        1. Markov Chains and Markov Property
      3. Activity 6.01: Building a Text Predictor Using a Markov Chain
    6. Summary
  9. 7. Doing Basic Statistics with Python
    1. Introduction
    2. Data Preparation
      1. Introducing the Dataset
      2. Introducing the Business Problem
      3. Preparing the Dataset
      4. Exercise 7.01: Using a String Column to Produce a Numerical Column
    3. Calculating and Using Descriptive Statistics
      1. The Need for Descriptive Statistics
      2. A Brief Refresher of Statistical Concepts
      3. Using Descriptive Statistics
      4. Exercise 7.02: Calculating Descriptive Statistics
    4. Exploratory Data Analysis
      1. What Is EDA?
      2. Univariate EDA
      3. Bi-variate EDA: Exploring Relationships Between Variables
      4. Exercise 7.03: Practicing EDA
      5. Activity 7.01: Finding Out Highly Rated Strategy Games
    5. Summary
  10. 8. Foundational Probability Concepts and Their Applications
    1. Introduction
    2. Randomness, Probability, and Random Variables
      1. Randomness and Probability
      2. Foundational Probability Concepts
      3. Introduction to Simulations with NumPy
      4. Exercise 8.01: Sampling with and without Replacement
      5. Probability as a Relative Frequency
      6. Defining Random Variables
      7. Exercise 8.02: Calculating the Average Wins in Roulette
    3. Discrete Random Variables
      1. Defining Discrete Random Variables
      2. The Binomial Distribution
      3. Exercise 8.03: Checking If a Random Variable Follows a Binomial Distribution
    4. Continuous Random Variables
      1. Defining Continuous Random Variables
      2. The Normal Distribution
      3. Some Properties of the Normal Distribution
      4. Exercise 8.04: Using the Normal Distribution in Education
      5. Activity 8.01: Using the Normal Distribution in Finance
    5. Summary
  11. 9. Intermediate Statistics with Python
    1. Introduction
    2. Law of Large Numbers
      1. Python and Random Numbers
      2. Exercise 9.01: The Law of Large Numbers in Action
      3. Exercise 9.02: Coin Flipping Average over Time
      4. A Practical Application of the Law of Large Numbers Seen in the Real World
      5. Exercise 9.03: Calculating the Average Winnings for a Game of Roulette If We Constantly Bet on Red
    3. Central Limit Theorem
      1. Normal Distribution and the CLT
      2. Random Sampling from a Uniform Distribution
      3. Exercise 9.04: Showing the Sample Mean for a Uniform Distribution
      4. Random Sampling from an Exponential Distribution
      5. Exercise 9.05: Taking a Sample from an Exponential Distribution
    4. Confidence Intervals
      1. Calculating the Confidence Interval of a Sample Mean
      2. Exercise 9.06: Finding the Confidence Interval of Polling Figures
      3. Small Sample Confidence Interval
      4. Confidence Interval for a Proportion
    5. Hypothesis Testing
      1. Parts of a Hypothesis Test
      2. The Z-Test
      3. Exercise 9.07: The Z-Test in Action
      4. Proportional Z-Test
      5. The T-Test
      6. Exercise 9.08: The T-Test
      7. 2-Sample T-Test or A/B Testing
      8. Exercise 9.09: A/B Testing Example
      9. Introduction to Linear Regression
      10. Exercise 9.10: Linear Regression
      11. Activity 9.01: Standardized Test Performance
    6. Summary
  12. 10. Foundational Calculus with Python
    1. Introduction
    2. Writing the Derivative Function
      1. Exercise 10.01: Finding the Derivatives of Other Functions
      2. Finding the Equation of the Tangent Line
    3. Calculating Integrals
    4. Using Trapezoids
      1. Exercise 10.02: Finding the Area Under a Curve
    5. Using Integrals to Solve Applied Problems
      1. Exercise 10.03: Finding the Volume of a Solid of Revolution
    6. Using Derivatives to Solve Optimization Problems
      1. Exercise 10.04: Find the Quickest Route
      2. Exercise 10.05: The Box Problem
      3. Exercise 10.06: The Optimal Can
      4. Exercise 10.07: Calculating the Distance between Two Moving Ships
      5. Activity 10.01: Maximum Circle-to-Cone Volume
    7. Summary
  13. 11. More Calculus with Python
    1. Introduction
    2. Length of a Curve
      1. Exercise 11.01: Finding the Length of a Curve
      2. Exercise 11.02: Finding the Length of a Sine Wave
    3. Length of a Spiral
      1. Exercise 11.03: Finding the Length of the Polar Spiral Curve
      2. Exercise 11.04: Finding the Length of Insulation in a Roll
      3. Exercise 11.05: Finding the Length of an Archimedean Spiral
    4. Area of a Surface
      1. The Formulas
      2. Exercise 11.06: Finding the Area of a 3D Surface – Part 1
      3. Exercise 11.07: Finding the Area of a 3D Surface – Part 2
      4. Exercise 11.08: Finding the Area of a Surface – Part 3
    5. Infinite Series
      1. Polynomial Functions
      2. Series
      3. Convergence
      4. Exercise 11.09: Calculating 10 Correct Digits of π
      5. Exercise 11.10: Calculating the Value of π Using Euler's Expression
      6. A 20th Century Formula
      7. Interval of Convergence
      8. Exercise 11.11: Determining the Interval of Convergence – Part 1
      9. Exercise 11.12: Determining the Interval of Convergence – Part 2
      10. Exercise 11.13: Finding the Constant
      11. Activity 11.01: Finding the Minimum of a Surface
    6. Summary
  14. 12. Intermediate Calculus with Python
    1. Introduction
    2. Differential Equations
    3. Interest Calculations
      1. Exercise 12.01: Calculating Interest
      2. Exercise 12.02: Calculating Compound Interest – Part 1
      3. Exercise 12.03: Calculating Compound Interest – Part 2
      4. Exercise 12.04: Calculating Compound Interest – Part 3
      5. Exercise 12.05: Becoming a Millionaire
    4. Population Growth
      1. Exercise 12.06: Calculating the Population Growth Rate – Part 1
      2. Exercise 12.07: Calculating the Population Growth Rate – Part 2
    5. Half-Life of Radioactive Materials
      1. Exercise 12.08: Measuring Radioactive Decay
      2. Exercise 12.09: Measuring the Age of a Historical Artifact
    6. Newton's Law of Cooling
      1. Exercise 12.10: Calculating the Time of Death
      2. Exercise 12.11: Calculating the Rate of Change in Temperature
    7. Mixture Problems
      1. Exercise 12.12: Solving Mixture Problems – Part 1
      2. Exercise 12.13: Solving Mixture Problems – Part 2
      3. Exercise 12.14: Solving Mixture Problems – Part 3
      4. Exercise 12.15: Solving Mixture Problems – Part 4
    8. Euler's Method
      1. Exercise 12.16: Solving Differential Equations with Euler's Method
      2. Exercise 12.17: Using Euler's Method to Evaluate a Function
      3. Runge-Kutta Method
      4. Exercise 12.18: Implementing the Runge-Kutta Method
      5. Pursuit Curves
      6. Exercise 12.19: Finding Where the Predator Catches the Prey
      7. Exercise 12.20: Using Turtles to Visualize Pursuit Curves
      8. Position, Velocity, and Acceleration
      9. Exercise 12.21: Calculating the Height of a Projectile above the Ground
      10. An Example of Calculating the Height of a Projectile with Air Resistance
      11. Exercise 12.22: Calculating the Terminal Velocity
      12. Activity 12.01: Finding the Velocity and Location of a Particle
    9. Summary
  15. Appendix
    1. 1. Fundamentals of Python
      1. Activity 1.01: Building a Sudoku Solver
    2. 2. Python's Main Tools for Statistics
      1. Activity 2.01: Analyzing the Communities and Crime Dataset
    3. 3. Python's Statistical Toolbox
      1. Activity 3.01: Revisiting the Communities and Crimes Dataset
    4. 4. Functions and Algebra with Python
      1. Activity 4.01: Multi-Variable Break-Even Analysis
    5. 5. More Mathematics with Python
      1. Activity 5.01: Calculating Your Retirement Plan Using Series
    6. 6. Matrices and Markov Chains with Python
      1. Activity 6.01: Building a Text Predictor Using a Markov Chain
    7. 7. Doing Basic Statistics with Python
      1. Activity 7.01: Finding Out Highly Rated Strategy Games
    8. 8. Foundational Probability Concepts and Their Applications
      1. Activity 8.01: Using the Normal Distribution in Finance
    9. 9. Intermediate Statistics with Python
      1. Activity 9.01: Standardized Test Performance
    10. 10. Foundational Calculus with Python
      1. Activity 10.01: Maximum Circle-to-Cone Volume
    11. 11. More Calculus with Python
      1. Activity 11.01: Finding the Minimum of a Surface
    12. 12. Intermediate Calculus with Python
      1. Activity 12.01: Finding the Velocity and Location of a Particle

Product information

  • Title: The Statistics and Calculus with Python Workshop
  • Author(s): Peter Farrell, Alvaro Fuentes, Ajinkya Sudhir Kolhe, Quan Nguyen, Alexander Joseph Sarver, Marios Tsatsos
  • Release date: August 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781800209763