The Statistics and Calculus with Python Workshop: A comprehensive introduction to mathematics in Python for artificial intelligence applications

The Statistics and Calculus with Python Workshop: A comprehensive introduction to mathematics in Python for artificial intelligence applications

The Statistics and Calculus with Python Workshop: A comprehensive introduction to mathematics in Python for artificial intelligence applications
Автор: Farrell Peter, Fuentes Alvaro, Kolhe Ajinkya Sudhir, Nguyen Quan, Sarver Alexander Joseph, Tsatsos Marios
Дата выхода: 2020
Издательство: Packt Publishing Limited
Количество страниц: 456
Размер файла: 3.4 MB
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы  Дополнительные материалы 

The Statistics and Calculus with Python Workshop....2

Preface....20

About the Book....20

Audience....20

About the Chapters....20

Conventions....21

Code Presentation....22

Setting up Your Environment....22

Software Requirements....22

Installation and Setup....22

Installing Python....23

Project Jupyter....23

Installing Libraries....25

Accessing the Code Files....25

1. Fundamentals of Python....27

Introduction....27

Control Flow Methods....27

if Statements....27

Exercise 1.01: Divisibility with Conditionals....28

Loops....30

The while Loop....30

The for Loop....30

Exercise 1.02: Number Guessing Game....31

Data Structures....34

Strings....34

Lists....35

Exercise 1.03: Multi-Dimensional Lists....36

Tuples....38

Sets....38

Dictionaries....39

Exercise 1.04: Shopping Cart Calculations....40

Functions and Algorithms....42

Functions....42

Exercise 1.05: Finding the Maximum....44

Recursion....45

Exercise 1.06: The Tower of Hanoi....46

Algorithm Design....47

Exercise 1.07: The N-Queens Problem....47

Testing, Debugging, and Version Control....51

Testing....51

Debugging....52

Exercise 1.08: Testing for Concurrency....53

Version Control....57

Exercise 1.09: Version Control with Git and GitHub....58

Activity 1.01: Building a Sudoku Solver....61

Summary....63

2. Python's Main Tools for Statistics....64

Introduction....64

Scientific Computing and NumPy Basics....64

NumPy Arrays....65

Vectorization....69

Exercise 2.01: Timing Vectorized Operations in NumPy....69

Random Sampling....71

Working with Tabular Data in pandas....74

Initializing a DataFrame Object....74

Accessing Rows and Columns....75

Manipulating DataFrames....78

Exercise 2.02: Data Table Manipulation....78

Advanced Pandas Functionalities....82

Exercise 2.03: The Student Dataset....84

Data Visualization with Matplotlib and Seaborn....87

Scatter Plots....88

Line Graphs....89

Bar Graphs....91

Histograms....94

Heatmaps....96

Exercise 2.04: Visualization of Probability Distributions....96

Visualization Shorthand from Seaborn and Pandas....98

Activity 2.01: Analyzing the Communities and Crime Dataset....100

Summary....101

3. Python's Statistical Toolbox....103

Introduction....103

An Overview of Statistics....103

Types of Data in Statistics....104

Categorical Data....104

Exercise 3.01: Visualizing Weather Percentages....107

Numerical Data....109

Exercise 3.02: Min-Max Scaling....112

Ordinal Data....114

Descriptive Statistics....115

Central Tendency....115

Dispersion....116

Exercise 3.03: Visualizing Probability Density Functions....116

Python-Related Descriptive Statistics....118

Inferential Statistics....121

T-Tests....122

Correlation Matrix....124

Exercise 3.04: Identifying and Testing Equality of Means....125

Statistical and Machine Learning Models....127

Exercise 3.05: Model Selection....129

Python's Other Statistics Tools....132

Activity 3.01: Revisiting the Communities and Crimes Dataset....133

Summary....134

4. Functions and Algebra with Python....135

Introduction....135

Functions....135

Common Functions....136

Domain and Range....138

Function Roots and Equations....138

The Plot of a Function....138

Exercise 4.01: Function Identification from Plots....140

Function Transformations....141

Shifts....141

Scaling....142

Exercise 4.02: Function Transformation Identification....143

Equations....145

Algebraic Manipulations....145

Factoring....146

Using Python....148

Exercise 4.03: Introduction to Break-Even Analysis....149

Systems of Equations....151

Systems of Linear Equations....152

Exercise 4.04: Matrix Solution with NumPy....154

Systems of Non-Linear Equations....157

Activity 4.01: Multi-Variable Break-Even Analysis....159

Summary....160

5. More Mathematics with Python....161

Introduction....161

Sequences and Series....161

Arithmetic Sequences....162

Generators....164

Exercise 5.01: Determining the nth Term of an Arithmetic Sequence and Arithmetic Series....166

Geometric Sequences....168

Exercise 5.02: Writing a Function to Find the Next Term of the Sequence....169

Recursive Sequences....171

Exercise 5.03: Creating a Custom Recursive Sequence....172

Trigonometry....174

Basic Trigonometric Functions....174

Exercise 5.04: Plotting a Right-Angled Triangle....175

Inverse Trigonometric Functions....177

Exercise 5.05: Finding the Shortest Way to the Treasure Using Inverse Trigonometric Functions....179

Exercise 5.06: Finding the Optimal Distance from an Object....180

Vectors....182

Vector Operations....182

Exercise 5.07: Visualizing Vectors....185

Complex Numbers....188

Basic Definitions of Complex Numbers....189

Polar Representation and Euler's Formula....191

Exercise 5.08: Conditional Multiplication of Complex Numbers....194

Activity 5.01: Calculating Your Retirement Plan Using Series....196

Summary....196

6. Matrices and Markov Chains with Python....198

Introduction....198

Matrix Operations on a Single Matrix....198

Basic Operations on a Matrix....199

Inspecting a Matrix....201

Exercise 6.01: Calculating the Time Taken for Sunlight to Reach Earth Each Day....202

Operations and Multiplication in Matrices....205

Axes in a Matrix....208

Exercise 6.02: Matrix Search....209

Multiple Matrices....211

Broadcasting....212

Operations on Multiple Matrices....213

Identity Matrix....213

The eye Function....213

Inverse of a Matrix....214

Logical Operators....214

Outer Function or Vector Product....215

Solving Linear Equations Using Matrices....216

Exercise 6.03: Use of Matrices in Performing Linear Equations....217

Transition Matrix and Markov Chains....219

Fundamentals of Markov Chains....220

Stochastic versus Deterministic Models....220

Transition State Diagrams....220

Transition Matrices....225

Exercise 6.04: Finding the Probability of State Transitions....226

Markov Chains and Markov Property....229

Activity 6.01: Building a Text Predictor Using a Markov Chain....230

Summary....231

7. Doing Basic Statistics with Python....232

Introduction....232

Data Preparation....232

Introducing the Dataset....232

Introducing the Business Problem....233

Preparing the Dataset....234

Exercise 7.01: Using a String Column to Produce a Numerical Column....239

Calculating and Using Descriptive Statistics....240

The Need for Descriptive Statistics....240

A Brief Refresher of Statistical Concepts....241

Using Descriptive Statistics....245

Exercise 7.02: Calculating Descriptive Statistics....247

Exploratory Data Analysis....248

What Is EDA?....249

Univariate EDA....250

Bi-variate EDA: Exploring Relationships Between Variables....255

Exercise 7.03: Practicing EDA....257

Activity 7.01: Finding Out Highly Rated Strategy Games....259

Summary....260

8. Foundational Probability Concepts and Their Applications....261

Introduction....261

Randomness, Probability, and Random Variables....261

Randomness and Probability....262

Foundational Probability Concepts....262

Introduction to Simulations with NumPy....263

Exercise 8.01: Sampling with and without Replacement....266

Probability as a Relative Frequency....267

Defining Random Variables....270

Exercise 8.02: Calculating the Average Wins in Roulette....274

Discrete Random Variables....276

Defining Discrete Random Variables....276

The Binomial Distribution....278

Exercise 8.03: Checking If a Random Variable Follows a Binomial Distribution....280

Continuous Random Variables....282

Defining Continuous Random Variables....282

The Normal Distribution....284

Some Properties of the Normal Distribution....287

Exercise 8.04: Using the Normal Distribution in Education....291

Activity 8.01: Using the Normal Distribution in Finance....293

Summary....294

9. Intermediate Statistics with Python....295

Introduction....295

Law of Large Numbers....295

Python and Random Numbers....296

Exercise 9.01: The Law of Large Numbers in Action....296

Exercise 9.02: Coin Flipping Average over Time....297

A Practical Application of the Law of Large Numbers Seen in the Real World....299

Exercise 9.03: Calculating the Average Winnings for a Game of Roulette If We Constantly Bet on Red....300

Central Limit Theorem....303

Normal Distribution and the CLT....304

Random Sampling from a Uniform Distribution....304

Exercise 9.04: Showing the Sample Mean for a Uniform Distribution....304

Random Sampling from an Exponential Distribution....306

Exercise 9.05: Taking a Sample from an Exponential Distribution....307

Confidence Intervals....310

Calculating the Confidence Interval of a Sample Mean....310

Exercise 9.06: Finding the Confidence Interval of Polling Figures....313

Small Sample Confidence Interval....314

Confidence Interval for a Proportion....315

Hypothesis Testing....316

Parts of a Hypothesis Test....316

The Z-Test....317

Exercise 9.07: The Z-Test in Action....318

Proportional Z-Test....320

The T-Test....321

Exercise 9.08: The T-Test....322

2-Sample T-Test or A/B Testing....325

Exercise 9.09: A/B Testing Example....326

Introduction to Linear Regression....327

Exercise 9.10: Linear Regression....328

Activity 9.01: Standardized Test Performance....330

Summary....331

10. Foundational Calculus with Python....332

Introduction....332

Writing the Derivative Function....332

Exercise 10.01: Finding the Derivatives of Other Functions....334

Finding the Equation of the Tangent Line....335

Calculating Integrals....336

Using Trapezoids....339

Exercise 10.02: Finding the Area Under a Curve....339

Using Integrals to Solve Applied Problems....340

Exercise 10.03: Finding the Volume of a Solid of Revolution....341

Using Derivatives to Solve Optimization Problems....343

Exercise 10.04: Find the Quickest Route....344

Exercise 10.05: The Box Problem....345

Exercise 10.06: The Optimal Can....346

Exercise 10.07: Calculating the Distance between Two Moving Ships....346

Activity 10.01: Maximum Circle-to-Cone Volume....347

Summary....348

11. More Calculus with Python....349

Introduction....349

Length of a Curve....349

Exercise 11.01: Finding the Length of a Curve....352

Exercise 11.02: Finding the Length of a Sine Wave....353

Length of a Spiral....353

Exercise 11.03: Finding the Length of the Polar Spiral Curve....355

Exercise 11.04: Finding the Length of Insulation in a Roll....356

Exercise 11.05: Finding the Length of an Archimedean Spiral....356

Area of a Surface....357

The Formulas....357

Exercise 11.06: Finding the Area of a 3D Surface – Part 1....361

Exercise 11.07: Finding the Area of a 3D Surface – Part 2....362

Exercise 11.08: Finding the Area of a Surface – Part 3....363

Infinite Series....363

Polynomial Functions....363

Series....364

Convergence....365

Exercise 11.09: Calculating 10 Correct Digits of π....366

Exercise 11.10: Calculating the Value of π Using Euler's Expression....367

A 20th Century Formula....367

Interval of Convergence....368

Exercise 11.11: Determining the Interval of Convergence – Part 1....369

Exercise 11.12: Determining the Interval of Convergence – Part 2....371

Exercise 11.13: Finding the Constant....372

Activity 11.01: Finding the Minimum of a Surface....372

Summary....373

12. Intermediate Calculus with Python....375

Introduction....375

Differential Equations....375

Interest Calculations....376

Exercise 12.01: Calculating Interest....376

Exercise 12.02: Calculating Compound Interest – Part 1....378

Exercise 12.03: Calculating Compound Interest – Part 2....380

Exercise 12.04: Calculating Compound Interest – Part 3....381

Exercise 12.05: Becoming a Millionaire....381

Population Growth....383

Exercise 12.06: Calculating the Population Growth Rate – Part 1....384

Exercise 12.07: Calculating the Population Growth Rate – Part 2....386

Half-Life of Radioactive Materials....386

Exercise 12.08: Measuring Radioactive Decay....386

Exercise 12.09: Measuring the Age of a Historical Artifact....387

Newton's Law of Cooling....389

Exercise 12.10: Calculating the Time of Death....389

Exercise 12.11: Calculating the Rate of Change in Temperature....391

Mixture Problems....392

Exercise 12.12: Solving Mixture Problems – Part 1....393

Exercise 12.13: Solving Mixture Problems – Part 2....395

Exercise 12.14: Solving Mixture Problems – Part 3....397

Exercise 12.15: Solving Mixture Problems – Part 4....398

Euler's Method....398

Exercise 12.16: Solving Differential Equations with Euler's Method....398

Exercise 12.17: Using Euler's Method to Evaluate a Function....400

Runge-Kutta Method....401

Exercise 12.18: Implementing the Runge-Kutta Method....402

Pursuit Curves....403

Exercise 12.19: Finding Where the Predator Catches the Prey....403

Exercise 12.20: Using Turtles to Visualize Pursuit Curves....405

Position, Velocity, and Acceleration....406

Exercise 12.21: Calculating the Height of a Projectile above the Ground....406

An Example of Calculating the Height of a Projectile with Air Resistance....409

Exercise 12.22: Calculating the Terminal Velocity....411

Activity 12.01: Finding the Velocity and Location of a Particle....412

Summary....413

Appendix....414

1. Fundamentals of Python....414

Activity 1.01: Building a Sudoku Solver....414

2. Python's Main Tools for Statistics....418

Activity 2.01: Analyzing the Communities and Crime Dataset....418

3. Python's Statistical Toolbox....423

Activity 3.01: Revisiting the Communities and Crimes Dataset....423

4. Functions and Algebra with Python....427

Activity 4.01: Multi-Variable Break-Even Analysis....427

5. More Mathematics with Python....432

Activity 5.01: Calculating Your Retirement Plan Using Series....432

6. Matrices and Markov Chains with Python....435

Activity 6.01: Building a Text Predictor Using a Markov Chain....436

7. Doing Basic Statistics with Python....438

Activity 7.01: Finding Out Highly Rated Strategy Games....438

8. Foundational Probability Concepts and Their Applications....440

Activity 8.01: Using the Normal Distribution in Finance....441

9. Intermediate Statistics with Python....443

Activity 9.01: Standardized Test Performance....444

10. Foundational Calculus with Python....448

Activity 10.01: Maximum Circle-to-Cone Volume....448

11. More Calculus with Python....449

Activity 11.01: Finding the Minimum of a Surface....449

12. Intermediate Calculus with Python....453

Activity 12.01: Finding the Velocity and Location of a Particle....453

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.


Похожее:

Список отзывов:

Нет отзывов к книге.