Essential Math for Data Science Take Control of Your Data with Fundamental Linear Algebra, Probability, and Statistics, First… (Thomas Nield) (Z-Library)

Author: Thomas Nield

科学

Data is a fantastic raw resource for powering change in an organization, but all too often the people working in those organizations don't have the necessary skills to communicate with data effectively. With this practical book, subject matter experts will learn ways to develop strong, persuasive points when presenting data to different groups in their organizations. Author Carl Allchin shows anyone how to find data sources and develop data analytics, and teaches those with more data expertise how to visualize data to convey findings to key business leaders more effectively. Once both your business and data experts possess the skills to work with data and interpret its significance, you can deal with questions and challenges in departments across your organization. • Learn the fundamental data skills required to work with data • Use data visualization to influence change in your organization • Learn how to apply data techniques to effectively work with data end to end • Understand how to communicate data points clearly and persuasively • Appreciate why different stakeholders often have divergent needs and views • Create a playbook for using data with different departments

📄 File Format: PDF
💾 File Size: 11.7 MB
17
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
Thomas Nield Essential Math for Data Science Take Control of Your Data with Fundamental Linear Algebra, Probability, and Statistics N ield
📄 Page 2
DATA “In the cacophony that is the current data science education landscape, this book stands out as a resource with many clear, practical examples of the fundamentals of what it takes to understand and build with data. —Vicki Boykis Senior Machine Learning Engineer at Tumblr Essential Math for Data Science US $59.99 CAN $74.99 ISBN: 978-1-098-10293-7 Twitter: @oreillymedia linkedin.com/company/oreilly-media youtube.com/oreillymedia Master the math needed to excel in data science, machine learning, and statistics. In this book, author Thomas Nield guides you through areas like calculus, probability, linear algebra, and statistics and how they apply to techniques like linear regression, logistic regression, and neural networks. Along the way you’ll also gain practical insights into the state of data science and how to use those insights to maximize your career. Learn how to: • Use Python code and libraries like SymPy, NumPy, and scikit-learn to explore essential mathematical concepts like calculus, linear algebra, statistics, and machine learning • Understand techniques like linear regression, logistic regression, and neural networks in plain English, with minimal mathematical notation and jargon • Perform descriptive statistics and hypothesis testing on a dataset to interpret p-values and statistical significance • Manipulate vectors and matrices and perform matrix decomposition • Integrate and build upon incremental knowledge of calculus, probability, statistics, and linear algebra, and apply it to regression models including neural networks • Navigate practically through a data science career and avoid common pitfalls, assumptions, and biases while tuning your skill set to stand out in the job market Thomas Nield is the founder of Nield Consulting Group as well as an instructor at O’Reilly Media and the University of Southern California. He enjoys making technical content relatable and relevant to those unfamiliar or intimidated by it. Thomas regularly teaches classes on data analysis, machine learning, mathematical optimization, and practical artificial intelligence. He’s the author of Getting Started with SQL (O’Reilly) and Learning RxJava (Packt). N ield
📄 Page 3
Praise for Essential Math for Data Science In the cacophony that is the current data science education landscape, this book stands out as a resource with many clear, practical examples of the fundamentals of what it takes to understand and build with data. By explaining the basics, this book allows the reader to navigate any data science work with a sturdy mental framework of its building blocks. —Vicki Boykis, Senior Machine Learning Engineer at Tumblr Data science is built on linear algebra, probability theory, and calculus. Thomas Nield expertly guides us through all of those topics—and more—to build a solid foundation for understanding the mathematics of data science. —Mike X Cohen, sincXpress As data scientists, we use sophisticated models and algorithms daily. This book swiftly demystifies the math behind them, so they are easier to grasp and implement. —Siddharth Yadav, freelance data scientist I wish I had access to this book earlier! Thomas Nield does such an amazing job breaking down complex math topics in a digestible and engaging way. A refreshing approach to both math and data science—seamlessly explaining fundamental math concepts and their immediate applications in machine learning. This book is a must-read for all aspiring data scientists. —Tatiana Ediger, freelance data scientist and course developer and instructor
📄 Page 4
(This page has no text content)
📄 Page 5
Thomas Nield Essential Math for Data Science Take Control of Your Data with Fundamental Linear Algebra, Probability, and Statistics Boston Farnham Sebastopol TokyoBeijing
📄 Page 6
978-1-098-10293-7 [LSI] Essential Math for Data Science by Thomas Nield Copyright © 2022 Thomas Nield. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: Jessica Haberman Development Editor: Jill Leonard Production Editor: Kristen Brown Copyeditor: Piper Editorial Consulting, LLC Proofreader: Shannon Turlington Indexer: Potomac Indexing, LLC Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea June 2022: First Edition Revision History for the First Edition 2022-05-26: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781098102937 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Essential Math for Data Science, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author, and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
📄 Page 7
Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. Basic Math and Calculus Review. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Number Theory 2 Order of Operations 3 Variables 5 Functions 6 Summations 11 Exponents 13 Logarithms 16 Euler’s Number and Natural Logarithms 18 Euler’s Number 18 Natural Logarithms 21 Limits 22 Derivatives 24 Partial Derivatives 28 The Chain Rule 31 Integrals 33 Conclusion 39 Exercises 39 2. Probability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Understanding Probability 42 Probability Versus Statistics 43 Probability Math 44 Joint Probabilities 44 Union Probabilities 45 Conditional Probability and Bayes’ Theorem 47 Joint and Union Conditional Probabilities 49 v
📄 Page 8
Binomial Distribution 51 Beta Distribution 53 Conclusion 60 Exercises 61 3. Descriptive and Inferential Statistics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 What Is Data? 63 Descriptive Versus Inferential Statistics 65 Populations, Samples, and Bias 66 Descriptive Statistics 69 Mean and Weighted Mean 70 Median 71 Mode 73 Variance and Standard Deviation 73 The Normal Distribution 78 The Inverse CDF 85 Z-Scores 87 Inferential Statistics 89 The Central Limit Theorem 89 Confidence Intervals 92 Understanding P-Values 95 Hypothesis Testing 96 The T-Distribution: Dealing with Small Samples 104 Big Data Considerations and the Texas Sharpshooter Fallacy 105 Conclusion 107 Exercises 107 4. Linear Algebra. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 What Is a Vector? 110 Adding and Combining Vectors 114 Scaling Vectors 116 Span and Linear Dependence 119 Linear Transformations 121 Basis Vectors 121 Matrix Vector Multiplication 124 Matrix Multiplication 129 Determinants 131 Special Types of Matrices 136 Square Matrix 136 Identity Matrix 136 Inverse Matrix 136 Diagonal Matrix 137 Triangular Matrix 137 vi | Table of Contents
📄 Page 9
Sparse Matrix 138 Systems of Equations and Inverse Matrices 138 Eigenvectors and Eigenvalues 142 Conclusion 145 Exercises 146 5. Linear Regression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 A Basic Linear Regression 149 Residuals and Squared Errors 153 Finding the Best Fit Line 157 Closed Form Equation 157 Inverse Matrix Techniques 158 Gradient Descent 161 Overfitting and Variance 167 Stochastic Gradient Descent 169 The Correlation Coefficient 171 Statistical Significance 174 Coefficient of Determination 179 Standard Error of the Estimate 180 Prediction Intervals 181 Train/Test Splits 185 Multiple Linear Regression 191 Conclusion 191 Exercises 192 6. Logistic Regression and Classification. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 Understanding Logistic Regression 193 Performing a Logistic Regression 196 Logistic Function 196 Fitting the Logistic Curve 198 Multivariable Logistic Regression 204 Understanding the Log-Odds 208 R-Squared 211 P-Values 216 Train/Test Splits 218 Confusion Matrices 219 Bayes’ Theorem and Classification 222 Receiver Operator Characteristics/Area Under Curve 223 Class Imbalance 225 Conclusion 226 Exercises 226 Table of Contents | vii
📄 Page 10
7. Neural Networks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 When to Use Neural Networks and Deep Learning 228 A Simple Neural Network 229 Activation Functions 231 Forward Propagation 237 Backpropagation 243 Calculating the Weight and Bias Derivatives 243 Stochastic Gradient Descent 248 Using scikit-learn 251 Limitations of Neural Networks and Deep Learning 253 Conclusion 256 Exercise 256 8. Career Advice and the Path Forward. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 Redefining Data Science 258 A Brief History of Data Science 260 Finding Your Edge 263 SQL Proficiency 263 Programming Proficiency 266 Data Visualization 269 Knowing Your Industry 270 Productive Learning 272 Practitioner Versus Advisor 272 What to Watch Out For in Data Science Jobs 275 Role Definition 275 Organizational Focus and Buy-In 276 Adequate Resources 278 Reasonable Objectives 279 Competing with Existing Systems 280 A Role Is Not What You Expected 282 Does Your Dream Job Not Exist? 283 Where Do I Go Now? 284 Conclusion 285 A. Supplemental Topics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 B. Exercise Answers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 viii | Table of Contents
📄 Page 11
Preface In the past 10 years or so, there has been a growing interest in applying math and statistics to our everyday work and lives. Why is that? Does it have to do with the accelerated interest in “data science,” which Harvard Business Review called “the Sexiest Job of the 21st Century”? Or is it the promise of machine learning and “artificial intelligence” changing our lives? Is it because news headlines are inundated with studies, polls, and research findings but unsure how to scrutinize such claims? Or is it the promise of “self-driving” cars and robots automating jobs in the near future? I will make the argument that the disciplines of math and statistics have captured mainstream interest because of the growing availability of data, and we need math, statistics, and machine learning to make sense of it. Yes, we do have scientific tools, machine learning, and other automations that call to us like sirens. We blindly trust these “black boxes,” devices, and softwares; we do not understand them but we use them anyway. While it is easy to believe computers are smarter than we are (and this idea is frequently marketed), the reality cannot be more the opposite. This disconnect can be precarious on so many levels. Do you really want an algorithm or AI performing criminal sentencing or driving a vehicle, but nobody including the developer can explain why it came to a specific decision? Explainability is the next frontier of statistical computing and AI. This can begin only when we open up the black box and uncover the math. You may also ask how can a developer not know how their own algorithm works? We will talk about that in the second half of the book when we discuss machine learning techniques and emphasize why we need to understand the math behind the black boxes we build. To another point, the reason data is being collected on a massive scale is largely due to connected devices and their presence in our everyday lives. We no longer solely use the internet on a desktop or laptop computer. We now take it with us in our ix
📄 Page 12
smartphones, cars, and household devices. This has subtly enabled a transition over the past two decades. Data has now evolved from an operational tool to something that is collected and analyzed for less-defined objectives. A smartwatch is constantly collecting data on our heart rate, breathing, walking distance, and other markers. Then it uploads that data to a cloud to be analyzed alongside other users. Our driving habits are being collected by computerized cars and being used by manufacturers to collect data and enable self-driving vehicles. Even “smart toothbrushes” are finding their way into drugstores, which track brushing habits and store that data in a cloud. Whether smart toothbrush data is useful and essential is another discussion! All of this data collection is permeating every corner of our lives. It can be over‐ whelming, and a whole book can be written on privacy concerns and ethics. But this availability of data also creates opportunities to leverage math and statistics in new ways and create more exposure outside academic environments. We can learn more about the human experience, improve product design and application, and optimize commercial strategies. If you understand the ideas presented in this book, you will be able to unlock the value held in our data-hoarding infrastructure. This does not imply that data and statistical tools are a silver bullet to solve all the world’s problems, but they have given us new tools that we can use. Sometimes it is just as valuable to recognize certain data projects as rabbit holes and realize efforts are better spent elsewhere. This growing availability of data has made way for data science and machine learning to become in-demand professions. We define essential math as an exposure to proba‐ bility, linear algebra, statistics, and machine learning. If you are seeking a career in data science, machine learning, or engineering, these topics are necessary. I will throw in just enough college math, calculus, and statistics necessary to better understand what goes in the black box libraries you will encounter. With this book, I aim to expose readers to different mathematical, statistical, and machine learning areas that will be applicable to real-world problems. The first four chapters cover foundational math concepts including practical calculus, probability, linear algebra, and statistics. The last three chapters will segue into machine learning. The ultimate purpose of teaching machine learning is to integrate everything we learn and demonstrate practical insights in using machine learning and statistical libraries beyond a black box understanding. The only tool needed to follow examples is a Windows/Mac/Linux computer and a Python 3 environment of your choice. The primary Python libraries we will need are numpy, scipy, sympy, and sklearn. If you are unfamiliar with Python, it is a friendly and easy-to-use programming language with massive learning resources behind it. Here are some I recommend: x | Preface
📄 Page 13
Data Science from Scratch, 2nd Edition by Joel Grus (O’Reilly) The second chapter of this book has the best crash course in Python I have encountered. Even if you have never written code before, Joel does a fantastic job getting you up and running with Python effectively in the shortest time possible. It is also a great book to have on your shelf and to apply your mathematical knowledge! Python for the Busy Java Developer by Deepak Sarda (Apress) If you are a software engineer coming from a statically-typed, object-oriented programming background, this is the book to grab. As someone who started programming with Java, I have a deep appreciation for how Deepak shares Python features and relates them to Java developers. If you have done .NET, C++, or other C-like languages you will probably learn Python effectively from this book as well. This book will not make you an expert or give you PhD knowledge. I do my best to avoid mathematical expressions full of Greek symbols and instead strive to use plain English in its place. But what this book will do is make you more comfortable talking about math and statistics, giving you essential knowledge to navigate these areas successfully. I believe the widest path to success is not having deep, specialized knowledge in one topic, but instead having exposure and practical knowledge across several topics. That is the goal of this book, and you will learn just enough to be dangerous and ask those once-elusive critical questions. So let’s get started! Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. Preface | xi
📄 Page 14
This element signifies a tip or suggestion. This element signifies a general note. This element indicates a warning or caution. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/thomasnield/machine-learning-demo-data. If you have a technical question or a problem using the code examples, please send email to bookquestions@oreilly.com. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Essential Math for Data Science by Thomas Nield (O’Reilly). Copyright 2022 Thomas Nield, 978-1-098-10293-7.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. xii | Preface
📄 Page 15
O’Reilly Online Learning For more than 40 years, O’Reilly Media has provided technol‐ ogy and business training, knowledge, and insight to help companies succeed. Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit https://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/essentialMathDataSci. Email bookquestions@oreilly.com to comment or ask technical questions about this book. For news and information about our books and courses, visit https://oreilly.com. Find us on LinkedIn: https://linkedin.com/company/oreilly-media Follow us on Twitter: https://twitter.com/oreillymedia Watch us on YouTube: https://youtube.com/oreillymedia Acknowledgments This book was over a year’s worth of efforts from many people. First, I want to thank my wife Kimberly for her support while I wrote this book, especially as we raised our son, Wyatt, to his first birthday. Kimberly is an amazing wife and mother, and everything I do now is for my son and our family’s better future. Preface | xiii
📄 Page 16
I want to thank my parents for teaching me to struggle past my limits and to never throw in the towel. Given this book’s topic, I’m glad they encouraged me to take calculus seriously in high school and college, and nobody can write a book without regularly exiting their comfort zone. I want to thank the amazing team of editors and staff at O’Reilly who have continued to open doors since I wrote my first book on SQL in 2015. Jill and Jess have been amazing to work with in getting this book written and published, and I’m grateful that Jess thought of me when this topic came up. I want to thank my colleagues at University of Southern California in the Aviation Safety and Security program. To have been given the opportunity to pioneer concepts in artificial intelligence system safety has taught me insights few people have, and I look forward to seeing what we continue to accomplish in the years to come. Arch, you continue to amaze me and I worry the world will stop functioning the day you retire. Lastly, I want to thank my brother Dwight Nield and my friend Jon Ostrower, who are partners in my venture, Yawman Flight. Bootstrapping a startup is hard, and their help has allowed precious bandwidth to write this book. Jon brought me onboard at USC and his tireless accomplishments in the aviation journalism world are nothing short of remarkable (look him up!). It is an honor that they are as passionate as I am about an invention I started in my garage, and I don’t think I could bring it to the world without them. To anybody I have missed, thank you for the big and small things you have done. More often than not, I’ve been rewarded for being curious and asking questions. I do not take that for granted. As Ted Lasso said, “Be curious, not judgmental.” xiv | Preface
📄 Page 17
CHAPTER 1 Basic Math and Calculus Review We will kick off the first chapter covering what numbers are and how variables and functions work on a Cartesian system. We will then cover exponents and logarithms. After that, we will learn the two basic operations of calculus: derivatives and integrals. Before we dive into the applied areas of essential math such as probability, linear algebra, statistics, and machine learning, we should probably review a few basic math and calculus concepts. Before you drop this book and run screaming, do not worry! I will present how to calculate derivatives and integrals for a function in a way you were probably not taught in college. We have Python on our side, not a pencil and paper. Even if you are not familiar with derivatives and integrals, you still do not need to worry. I will make these topics as tight and practical as possible, focusing only on what will help us in later chapters and what falls under the “essential math” umbrella. This Is Not a Full Math Crash Course! This is by no means a comprehensive review of high school and college math. If you want that, a great book to check out is No Bull‐ shit Guide to Math and Physics by Ivan Savov (pardon my French). The first few chapters contain the best crash course on high school and college math I have ever seen. The book Mathematics 1001 by Dr. Richard Elwes has some great content as well, and in bite-sized explanations. 1
📄 Page 18
Number Theory What are numbers? I promise to not be too philosophical in this book, but are numbers not a construct we have defined? Why do we have the digits 0 through 9, and not have more digits than that? Why do we have fractions and decimals and not just whole numbers? This area of math where we muse about numbers and why we designed them a certain way is known as number theory. Number theory goes all the way back to ancient times, when mathematicians studied different number systems, and it explains why we have accepted them the way we do today. Here are different number systems that you may recognize: Natural numbers These are the numbers 1, 2, 3, 4, 5…and so on. Only positive numbers are included here, and they are the earliest known system. Natural numbers are so ancient cavemen scratched tally marks on bones and cave walls to keep records. Whole numbers Adding to natural numbers, the concept of “0” was later accepted; we call these “whole numbers.” The Babylonians also developed the useful idea for place-holding notation for empty “columns” on numbers greater than 9, such as “10,” “1,000,” or “1,090.” Those zeros indicate no value occupying that column. Integers Integers include positive and negative natural numbers as well as 0. We may take them for granted, but ancient mathematicians deeply distrusted the idea of negative numbers. But when you subtract 5 from 3, you get –2. This is useful especially when it comes to finances where we measure profits and losses. In 628 AD, an Indian mathematician named Brahmagupta showed why negative numbers were necessary for arithmetic to progress with the quadratic formula, and therefore integers became accepted. Rational numbers Any number that you can express as a fraction, such as 2/3, is a rational number. This includes all finite decimals and integers since they can be expressed as fractions, too, such as 687/100 = 6.87 and 2/1 = 2, respectively. They are called rational because they are ratios. Rational numbers were quickly deemed neces‐ sary because time, resources, and other quantities could not always be measured in discrete units. Milk does not always come in gallons. We may have to measure it as parts of a gallon. If I run for 12 minutes, I cannot be forced to measure in whole miles when in actuality I ran 9/10 of a mile. Irrational numbers Irrational numbers cannot be expressed as a fraction. This includes the famous π, square roots of certain numbers like 2, and Euler’s number e, which we will 2 | Chapter 1: Basic Math and Calculus Review
📄 Page 19
learn about later. These numbers have an infinite number of decimal digits, such as 3.141592653589793238462… There is an interesting history behind irrational numbers. The Greek mathemati‐ cian Pythagoras believed all numbers are rational. He believed this so fervently, he made a religion that prayed to the number 10. “Bless us, divine number, thou who generated gods and men!” he and his followers would pray (why “10” was so special, I do not know). There is a legend that one of his followers, Hippasus, proved not all numbers are rational simply by demonstrating the square root of 2. This severely messed with Pythagoras’s belief system, and he responded by drowning Hippasus at sea. Regardless, we now know not all numbers are rational. Real numbers Real numbers include rational as well as irrational numbers. In practicality, when you are doing any data science work you can treat any decimals you work with as real numbers. Complex and imaginary numbers You encounter this number type when you take the square root of a negative number. While imaginary and complex numbers have relevance in certain types of problems, we will mostly steer clear of them. In data science, you will find most (if not all) of your work will be using whole numbers, natural numbers, integers, and real numbers. Imaginary numbers may be encountered in more advanced use cases such as matrix decomposition, which we will touch on in Chapter 4. Complex and Imaginary Numbers If you do want to learn about imaginary numbers, there is a great playlist Imaginary Numbers are Real on YouTube. Order of Operations Hopefully, you are familiar with order of operations, which is the order you solve each part of a mathematical expression. As a brief refresher, recall that you evaluate com‐ ponents in parentheses, followed by exponents, then multiplication, division, addi‐ tion, and subtraction. You can remember the order of operations by the mnemonic device PEMDAS (Please Excuse My Dear Aunt Sally), which corresponds to the ordering parentheses, exponents, multiplication, division, addition, and subtraction. Order of Operations | 3
📄 Page 20
Take for example this expression: 2 × 3 + 2 2 5 − 4 First we evaluate the parentheses (3 + 2), which equals 5: 2 × 5 2 5 − 4 Next we solve the exponent, which we can see is squaring that 5 we just summed. That is 25: 2 × 255 − 4 Next up we have multiplication and division. The ordering of these two is swappable since division is also multiplication (using fractions). Let’s go ahead and multiply the 2 with the 25 5 , yielding 50 5 : 50 5 − 4 Next we will perform the division, dividing 50 by 5, which will yield 10: 10 − 4 And finally, we perform any addition and subtraction. Of course, 10 − 4 is going to give us 6: 10 − 4 = 6 Sure enough, if we were to express this in Python we would print a value of 6.0 as shown in Example 1-1. Example 1-1. Solving an expression in Python my_value = 2 * (3 + 2)**2 / 5 - 4 print(my_value) # prints 6.0 4 | Chapter 1: Basic Math and Calculus Review
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now
Back to List