0% found this document useful (0 votes)
28 views6 pages

Session 1 - Introduction (Updated)

The document provides an introduction to a course on Python and mathematics for machine learning. It outlines that students will learn basic Python programming, key mathematical concepts for machine learning like statistics, linear algebra, and calculus. It will cover probability, random variables, descriptive statistics, and how to use Jupyter Notebook. Students will learn mathematics and Python hands-on with interleaved lectures and practices.

Uploaded by

KRIS LAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views6 pages

Session 1 - Introduction (Updated)

The document provides an introduction to a course on Python and mathematics for machine learning. It outlines that students will learn basic Python programming, key mathematical concepts for machine learning like statistics, linear algebra, and calculus. It will cover probability, random variables, descriptive statistics, and how to use Jupyter Notebook. Students will learn mathematics and Python hands-on with interleaved lectures and practices.

Uploaded by

KRIS LAM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

A Brief Introduction to Python &

Session 1 – Basic statistics and Python


Mathematics for Machine Learning
• Lecture plan – you would learn the following:
Week 1 • The objectives and organization of this course
Part 1 - Python & Statistics • What mathematical tools are needed for Machine Learning
(5 & 8 January 2022) • How to read mathematical equations
• Some basic concepts in Statistics relevant to ML and Data Science
• Probability and Baye’s Theorem
Pre-Course for ECOM6022 • Random variables and Distribuiton
By • Descriptive Statistics
Professor Paul Y S CHEUNG • How to use Jupyter Notebook under Colaboratory (Colab)
environment
• Basic Python including data types, operations, variables, and starting
writing simple Python programs
2

Introduction to the course What is Mathematics?


• OBJECTIVE • Mathematics is a tool - to solve problems (e.g. 1, 2, 3….)
• Introduction to Python – sufficient to read and understand python programs, • Mathematics is a language – to communicate (e.g. equations)
and write simple python codes to use common packages for Machine • Mathematics is a framework (e.g. graphs, cryptography)
Learning
• Mathematics is a transformation (e.g. take an input, product an output)
• Cover the essential mathematics – Statistics, Linear Algebra and Calculus to
understand the theory and algorithms in Machine Learning • Mathematics is an art (e.g. pure maths, fractals)
• Mathematics is a model (e.g. machine learning, algo trading)
• COURSE PLAN
• Interleave lectures and real-time online hands-on practices on python. You • Mathematics is a science (e.g. computer science - processing of numbers)
will be learning mathematics and python together! • Mathematics is nature (e.g. we find maths in nature, natural constants)
• Total 6 sessions will be conducted via Zoom, each session is 3-hours. • Mathematics is …….
• EXERCISES but no assignment, no exam, no credit, no fees!
• Instructor – Professor Paul Y S CHEUNG (paul.cheung@hku.hk) • Key to learning mathematics – enjoy it, appreciate it, NOT to fear it!
• Teaching Assistant – Mr. Ivan Law (rusher@connect.hku.hk)
3 4
Maths for ML Let us Start from Basic
1. STATISTICS
• Numbers are tools – we create to represent quantities (and use simple to
• Sta$s$cs is a mathema$cal body of science that pertains to the collec%on, analysis,
interpreta%on or explana%on, and presenta%on of data, or as a branch of represent) e.g. 0, 1, 2….9, the decimal system due to human having 10
mathema$cs. While many scien$fic inves$ga$ons make use of data, sta$s$cs is fingers, and 0 and 1 for computers (because of logic gates). Numbers are
concerned with the use of data in the context of uncertainty and decision making in also symbols, part of the ”vocabulary” of the language called maths!
the face of uncertainty.
2. LINEAR ALGEBRA
• Linear algebra is the branch of mathema$cs concerning linear equa%ons such as:

or linear maps such as:

Linear algebra o9en uses vectors and matrices as an efficient way to


organize and process data.
1. CALCULUS
• Calculus, originally called infinitesimal calculus or "the calculus of infinitesimals", is
the mathema$cal study of con%nuous change, in the same way that geometry is the
study of shape and algebra is the study of generaliza$ons of arithme$c opera$ons.
(Source: Wikipedia)
5 6

Mathematical Operations - Arithmetic Concept of Variables in Algebraic EquaFons


BASIC OPERATIONS In its most general form, algebra is the study of mathematical symbols and
• Addition a+b the rules for manipulating these symbols; it is a unifying thread of almost
• Subtraction a-b all of mathematics. The symbols (e.g. !, ") are called variables in maths
to represent the unknown to be solved.
• Multiplication a * b
Elementary algebra is generally considered to be essential for any study of
• Division a/b
mathematics, science, or engineering, as well as such applications as
medicine and economics.
ADVANCED OPERATIONS In algebra, real life problems are formulated (modeled) by an equation,
• Power (e.g. ab ) thereby providing a method to obtain find the solution to similar problems
• Exponentials (e.g. ex) in general.
• Log (e.g. log2 x, log10 x, or ln x) For example, this is the solution of a general quadratics equation
• Factorial (e.g. 5! = 5 * 4 * 3 * 2 * 1) #$ ! + &$ + ' = 0
• Modulus (e.g. 5 mod 3 = 2)

7 8
Reading Algebraic Equations Basic Concepts in Statistics
As mathematics is a “language”, we can express complex mathematical relationships by Statistics is a form of mathematical analysis that uses quantified models and
mathematical notations. Here are some commonly used forms of equations: representations for a given set of experimental data or real-life studies. The main
advantage of statistics is that information is presented in an easy way. Here are 8
"! + $ ! = & ! basic concepts used in machine learning and data science [Ref: Shirley Chen].
' = () !
• Type of Statistical Analytics
,+ , , − 1 + !
1++ " =1+ + +⋯ • Probability
1! 2!
• Central Tendency
&
,(+ ,(+ • Variability
1 + = "# + 2 "" cos + $" sin
6 6
"$% • Relationship Between Variables
+ +! +( • Probability Distribution
9' = 1 + + + +⋯ , −∞ < + < ∞
1! 2! 3! • Hypothesis Testing and Statistical Significance
" • Regression
"
, ) "*)
++" =2 + "
>
)$# (ref: https://www.kdnuggets.com/2020/06/8-basic-statistics-concepts.html)
9 10

Types of Statistical Analytics Probability and relationship between events


1. Descriptive Analytics tells us what happened in the past and helps a Probability is the measure of the likelihood that an event will occur in a
business understand how it is performing by providing context to help either Random Experiment or analysis of data collected from a “Random
stakeholders interpret information. Process”.
Complement: P(A) + P(A’) = 1
2. Diagnostic Analytics takes descriptive data a step further and helps
you understand why something happened in the past. Intersection: P(A∩B) = P(A)P(B) (assuming A not same as B)
Union: P(A∪B) = P(A) + P(B) − P(A∩B)
3. Predictive Analytics predicts what is most likely to happen in the
future and provides companies with actionable insights based on the
information.

4. Prescriptive Analytics provides recommendations regarding actions


that will take advantage of the predictions and guide the possible
actions toward a solution.

11 12
Probability of multiple events Probability (Baye’s Theorem)
CondiKonal Probability: P(A|B) is a measure of the probability of one Bayes’ Theorem describes the probability of an event based on prior
event occurring with some relaeonship to one or more other events. knowledge of conditions that might be related to the event.
P(A|B)=P(A∩B)/P(B), when P(B)>0. Prior probability of a random event is the unconditional probability that is
assigned before any relevant evidence is taken into account.
Independent Events: Two events are independent if the occurrence of one Assume: P(A) and P(B) are the probabilities of observing A and B
does not affect the probability of occurrence of the other. P(A∩B)=P(A)P(B) respectively without any given conditions, they are known as prior
where P(A) != 0 and P(B) != 0 , P(A|B)=P(A), P(B|A)=P(B) probability
P(A∣B) is a conditional probability = the probability of event A occurring
Mutually Exclusive Events: Two events are mutually exclusive if they given that B is true. It is also called the posterior probability of A given B.
cannot both occur at the same eme. P(A∩B)=0 and P(A∪B)=P(A)+P(B). Similarly, P(B∣A) = the probability of event B occurring given that A is true.
It is also called the posterior probability of A given B.
Baye’s Theorem:

13 14

Proof of Baye’s Theorem Example use of Bayes’ Theorem


A cannabis test has a True PosiOve Rate (TPR or SensiOvity) of 90% and a True NegaOve
Rate (TNR or Specificity) of 80%. Assume 5% of the populaOon is known to use
cannabis (called Prevalence), the following summarizes the scenario:
A = (cannabis) user, B = tested posiOve, A’ = non-user, B’= test negaOve
P(A) = prevalence = 0.05 and (P(A’)) = 0.95; P(B|A) = 0.9 and P(B|A’) = 0.2

What is the probability that a person test posiOve in this test is a true cannabis user, or
in equaOon form, find P(A∣B)?
! #" !(#)
Using Baye’s Theorem: ! " # =
!(%)

But P(B) = P(B|A) P(A) + P(B|A’)P(A’) = 0.9 x 0.05 + 0.2 x 0.95 = 0.235

Interpreta(on: TP = True Posi(ve, FP = False Posi(ve, TN = True Nega(ve, FN = False Nega(ve


Assume you test ALL people, then TP + FN = All drug users; TN + FP = All non-suers
The above equa(on is : P(B) = P(Test Posi(ve) = P(TP) x P(user) + P(FN) x P(non-user)

Hence: P(A|B) = 0.9 x 0.05⁄0.235 ≈ 19%


15 16
What happens when 1,000 People are tested Random Variables and Probability Distributions
In probability and statistics, a random variable, random quantity, or
stochastic variable is described informally as a variable whose values
depend on outcomes of a random phenomenon or process. A particular
value of measurement or occurrence of a random event is called a sample.
A probability distribution is the mathematical function that gives the
probabilities of occurrence of different possible outcomes for an
experiment, measurement or random process. It is a mathematical
description of a random phenomenon in terms of its sample space and the
probabilities of events (subsets of the sample space).

Assuming 1,000 random people were tested using this cannabis test:
• About 950 are non-users and 190 of them will test false positive (0.2 x
950); 50 of them are users (5%) and 45 of them will test true positive (0.9
x 50); 1,000 people will yield 235 positive results (45 + 190), of which only
45 are genuine drug users, or you are only 19% confident that they are a
true drug user!!
17 Probability Density CumulaIve DistribuIon 18
Function FuncIon

Descriptive Statistics of Random Variables Quantifications of Random Variables


Mean: The average of the dataset. Median: The middle value of an ordered dataset.
Arithme6c Mean: Mode: The most frequent value in the dataset. If the data have multiple
values that occurred the most frequently, we have a multimodal
distribution.
Geometric Mean:
Skewness: It is the degree of distortion from the symmetrical bell curve or
the normal distribution. It measures the lack of symmetry in data
Weighted Mean: distribution.

Sample Mean : Arithmeec mean of random sample values drawn from the
populaeon - x̄ (pronounced as x bar).

Popula6on Mean : Actual mean of the whole populaeon - μ (Greek term


mu).
19 20
QuanFficaFons of Random Variables Python
Range: The difference between the highest and lowest value
in the dataset. Python is an interpreted high-level general-purpose programming language. Its
design philosophy emphasizes code readability with its use of significant
Percentiles, Quartiles and Interquartile Range (IQR) indentation. Its language constructs as well as its object-oriented approach aim to
• Percentiles — A measure that indicates the value below help programmers write clear, logical code for small and large-scale projects.
which a given percentage of observations in a group of Together with R, it is one of the two most used programming languages in
observations falls. Machine Learning and Data Science.
• Quantiles — Values that divide the number of data points There are many packages, mostly open-source, available to support Python. We
into four more or less equal parts, or quarters. shall be using Python throughout our ML course. After learning Python, learning
R will be simple!
• Interquartile Range (IQR) — A measure of statistical
Python is pre-installed in both Windows OS and Mac OS. However, it is best to use an
dispersion and variability based on dividing a data set into Integrated Development Environment (IDE) to write, debug, test and execute Python
quartiles. IQR = Q3 − Q1 programs.
The IDE we shall be using is Google CoLaboratory (CoLab), which is an online IDE, with
support of processor farms and GPUs. It has the advantage of being able to run anywhere
with Internet Access on multiple machines, easy team collaboration and free use of GPU
(most useful when you have limited computer resources), but you would need a Google
Drive account to store your files.
Alternatively, another popular choice is Anaconda, which is an IDE including many packages
and resources, which can be installed locally and execute using your own computer.
21 22

Jupyter Notebook and Colab


Jupyter Notebook (formerly IPython Notebooks) is a web-based interacBve computaBonal
environment for creaLng notebook documents. Colab is Google’s “improvement” based on
Jupyter Notebook and provide an even easier environment to work with for Data Science
and Machine Learning.
Requirements for using Colab:
1. A reasonably powerful computer (notebook or desktop), with sufficient RAM
(recommend 16GB main memory) and large enough available storage on disk
(recommend SSD instead of harddisk).
2. You would need a Google Account (if you have Gmail, you would already have a Google
account), and have a Google Drive. Check the free disk space you have on your Google
Drive and get more if needed.
3. You would need broadband Internet of sufficiently high bandwdth. I recommend at
least 100Mbps or higher. You may find running off mobile network frustraLng!
Those who do not have sufficiently fast Internet, you may consider loading Anaconda
package and use it instead of Colab. But you may need to do more setup, configuraLon and
run everything locally instead of using the servers, GPU and TPU in Google.

Goto Colab 23

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy