Basics Statistics For Data Analysis

Download as pdf or txt
Download as pdf or txt
You are on page 1of 75

2.

Basic Statistics
Essential tools for data analysis

4
Outline
Theory:
• Probabilities:
– Probability measures, events, random variables, conditional
probabilities, dependence, expectations, etc
• Bayes rule
• Parameter estimation:
– Maximum Likelihood Estimation (MLE)
– Maximum a Posteriori (MAP)

Application:
Naive Bayes Classifier for
• Spam filtering
• “Mind reading” = fMRI data processing
5
What is the probability?

Probabilities

Bayes Kolmogorov 6
Probability
• Sample space, Events, σ-Algebras
• Axioms of probability, probability measures
– What defines a reasonable theory of uncertainty?
•Random variables:
– discrete, continuous random variables
• Joint probability distribution
• Conditional probabilities
• Expectations
• Independence, Conditional independence

7
Sample space
Def: A sample space Ω is the set of all possible
outcomes of a (conceptual or physical) random
experiment. (Ω can be finite or infinite.)
Examples:
−Ω may be the set of all possible outcomes of a dice roll
(1,2,3,4,5,6)

-Pages of a book opened randomly. (1-157)

-Real numbers for temperature, location, time, etc


8
Events
We will ask the question:
What is the probability of a particular event?

Def: Event A is a subset of the sample space Ω

Examples:
What is the probability of
− the book is open at an odd number
− rolling a dice the number <4
− a random person’s height X : a<X<b

9
Probability
Def: Probability P(A), the probability that event
(subset) A happens, is a function that maps the
event A onto the interval [0, 1]. P(A) is also called
the probability measure of A.

outcomes in which A is false

sample space Ω 1,3,5,6 outcomes in


which A is
true
2,4
Example: What is the probability that
the number on the dice is 2 or 4? P(A) is the volume of the area.
10
What defines a reasonable
theory of uncertainty?

11
Kolmogorov Axioms

Consequences:

12
Venn Diagram

B
A

P(A U B) = P(A) + P(B) - P(A ∩ B) 13
Random Variables
Def: Real valued random variable is a function of the
outcome of a randomized experiment

Examples:

• D iscrete random variable examples (Ω is discrete):


• X(ω) = True if a randomly draw n person (ω) from our
class (Ω) is female
• X(ω) = The hometow n X(ω) of a randomly draw n person
(ω) from our class (Ω)
14
Random Variables
Sometimes Ω can be quite abstract

Continuous random variable:


Let X(ω1,ω2)= ω1 be the heart rate of a randomly drawn person (ω=ω1,ω2) in
our class Ω

15
What discrete distributions do we
know?

16
Discrete Distributions
• Bernoulli distribution: Ber(p)

• Binomial distribution: Bin(n,p)


Suppose a coin with head prob. p is tossed n times. What is the
probability of getting k heads and n-k tails?

17
This image cannot currently be displayed.

Continuous Distribution
Def: continuous probability distribution: its cumulative distribution function is
absolutely continuous.

Def: cumulative distribution function

USA:

Hungary:

Def :

Def :

Properties :
18
Cumulative Distribution
Function (cdf)

From top to bottom:


• the cumulative distribution function of a discrete probability distribution
• continuous probability distribution,
• a distribution which has both a continuous part and a discrete part. 19
Cumulative Distribution
Function (cdf)
If the CDF is absolute continuous, then the distribution has density function.

Why do we need absolute continuity?


Continuity of the CDF is not enough to have density function???

Cantor function: F continuous everywhere, has zero derivative (f=0) almost


everywhere, F goes from 0 to 1 as x goes from 0 to 1, and takes on every
value in between. ) there is no density for the Cantor function CDF.
20
Probability Density Function
(pdf)
Pdf properties:

Intuitively, one can think of f(x)dx as being the probability of X falling within
the infinitesimal interval [x, x + dx].
21
Moments
Expectation: average value, mean, 1st moment:

Variance: the spread, 2nd moment:

22
Warning!
Moments may not always exist!

Cauchy distribution

For the mean to exist the following integral would have to converge

23
Uniform Distribution

PDF CDF

24
This image cannot currently be displayed.

Normal (Gaussian) Distribution

PDF CDF

25
Multivariate (Joint) Distribution
We can generalize the above ideas from 1-dimension to any finite dimensions.

Discrete distribution:

Flu No Flu

1/80 7/80
Headache

1/80 71/80
No Headache
26
Multivariate Gaussian distribution

Multivariate CDF

http://www.moserware.com/2010/03/computing-your-skill.htm

27
Conditional Probability
P(X|Y) = Fraction of worlds in which X event is true given Y event is true.

Flu No Flu
Headache 1/80 7/80 Y

X∧Y
X
1/80 71/80
No Headache
28
Independence
Independent random variables:

Y and X don’t contain information about each other.


Observing Y doesn’t help predicting X.
Observing X doesn’t help predicting Y.
Examples:
Independent: Winning on roulette this week and next week.
Dependent: Russian roulette
29
Conditionally Independent
Conditionally independent:

Knowing Z makes X and Y independent


Examples:
Dependent: show size and reading skills
age
Conditionally independent: show size and reading skills given …?

Storks deliver babies:


Highly statistically significant correlation
exists between stork populations and
human birth rates across Europe

30
Conditionally Independent
London taxi drivers: A survey has pointed out a positive and
significant correlation between the number of accidents and wearing
coats. They concluded that coats could hinder movements of drivers and
be the cause of accidents. A new law was prepared to prohibit drivers
from wearing coats when driving.

Finally another study pointed out that people wear coats when it rains…

xkcd.com 31
Conditional Independence
Formally: X is conditionally independent of Y given Z:

Equivalent to:

32
Bayes Rule

33
Chain Rule & Bayes Rule
Chain rule:

Bayes rule:

Bayes rule is important for reverse conditioning.

34
AIDS test (Bayes rule)
Data
 Approximately 0.1% are infected
 Test detects all infections
 Test reports positive for 1% healthy people

Probability of having AIDS if test is positive:

Only 9%!...
35
Improving the diagnosis
Use a follow-up test!
•Test 2 reports positive for 90% infections
•Test 2 reports positive for 5% healthy people

Why can’t we use Test 1 twice?


Outcomes are not independent but tests 1 and 2
are conditionally independent
36
Application:
Document Classification, Spam filtering

37
Delivered-To: [email protected]

Data for spam filtering Received: by 10.216.47.73 with SMTP id s51cs361171web;


Tue, 3 Jan 2012 14:17:53 -0800 (PST)
Received: by 10.213.17.145 with SMTP id s17mr2519891eba.147.1325629071725;
Tue, 03 Jan 2012 14:17:51 -0800 (PST)
Return-Path: <[email protected]>
Received: from mail-ey0-f175.google.com (mail-ey0-f175.google.com [209.85.215.175])
by mx.google.com with ESMTPS id n4si29264232eef.57.2012.01.03.14.17.51
(version=TLSv1/SSLv3 cipher=OTHER);
Tue, 03 Jan 2012 14:17:51 -0800 (PST)
Received-SPF: neutral (google.com: 209.85.215.175 is neither permitted nor denied by best guess record for domain of
[email protected]) client-ip=209.85.215.175;

• date Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.215.175 is neither permitted nor denied by best
guess record for domain of [email protected])
[email protected]; dkim=pass (test mode) [email protected]
Received: by eaal1 with SMTP id l1so15092746eaa.6
for <[email protected]>; Tue, 03 Jan 2012 14:17:51 -0800 (PST)
Received: by 10.205.135.18 with SMTP id ie18mr5325064bkc.72.1325629071362;

• time Tue, 03 Jan 2012 14:17:51 -0800 (PST)


X-Forwarded-To: [email protected]
X-Forwarded-For: [email protected] [email protected]
Delivered-To: [email protected]
Received: by 10.204.65.198 with SMTP id k6cs206093bki;
Tue, 3 Jan 2012 14:17:50 -0800 (PST)

• recipient path
Received: by 10.52.88.179 with SMTP id bh19mr10729402vdb.38.1325629068795;
Tue, 03 Jan 2012 14:17:48 -0800 (PST)
Return-Path: <[email protected]>
Received: from mail-vx0-f179.google.com (mail-vx0-f179.google.com [209.85.220.179])
by mx.google.com with ESMTPS id dt4si11767074vdb.93.2012.01.03.14.17.48
(version=TLSv1/SSLv3 cipher=OTHER);
Tue, 03 Jan 2012 14:17:48 -0800 (PST)

• IP number Received-SPF: pass (google.com: domain of [email protected] designates 209.85.220.179 as permitted sender)
client-ip=209.85.220.179;
Received: by vcbf13 with SMTP id f13so11295098vcb.10
for <[email protected]>; Tue, 03 Jan 2012 14:17:48 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=googlemail.com; s=gamma;

• sender h=mime-version:sender:date:x-google-sender-auth:message-id:subject
:from:to:content-type;
bh=WCbdZ5sXac25dpH02XcRyDOdts993hKwsAVXpGrFh0w=;
b=WK2B2+ExWnf/gvTkw6uUvKuP4XeoKnlJq3USYTm0RARK8dSFjyOQsIHeAP9Yssxp6O
7ngGoTzYqd+ZsyJfvQcLAWp1PCJhG8AMcnqWkx0NMeoFvIp2HQooZwxSOCx5ZRgY+7qX
uIbbdna4lUDXj6UFe16SpLDCkptd8OZ3gr7+o=

• encoding MIME-Version: 1.0


Received: by 10.220.108.81 with SMTP id e17mr24104004vcp.67.1325629067787;
Tue, 03 Jan 2012 14:17:47 -0800 (PST)
Sender: [email protected]
Received: by 10.220.17.129 with HTTP; Tue, 3 Jan 2012 14:17:47 -0800 (PST)
Date: Tue, 3 Jan 2012 14:17:47 -0800

• many more features X-Google-Sender-Auth: 6bwi6D17HjZIkxOEol38NZzyeHs


Message-ID: <CAFJJHDGPBW+SdZg0MdAABiAKydDk9tpeMoDijYGjoGO-WC7osg@mail.gmail.com>
Subject: CS 281B. Advanced Topics in Learning and Decision Making
From: Tim Althoff <[email protected]>
To: [email protected]
Content-Type: multipart/alternative; boundary=f46d043c7af4b07e8d04b5a7113a

--f46d043c7af4b07e8d04b5a7113a
Content-Type: text/plain; charset=ISO-8859-1 38
Naïve Bayes Assumption
Naïve Bayes assumption: Features X1 and X2 are conditionally
independent given the class label Y:

More generally:

How many parameters to estimate?


(X is composed of d binary features, e.g. presence of “earn”
Y has K possible class labels)
(2d-1)K vs (2-1)dK
39
Naïve Bayes Classifier
Given:
– Class prior P(Y)
– d conditionally independent features X1,…Xd given the
class label Y
– For each Xi, we have the conditional likelihood P(Xi|Y)

Decision rule:

40
A Graphical Model

spam spam

x1 x2 ... xn xi

i=1..n

41
Naïve Bayes Algorithm for
discrete features
Training Data:
n d dimensional features + class labels

We need to estimate these probabilities!

Estimate them with Relative Frequencies!


For Class Prior

For Likelihood

NB Prediction for test data:

42
Subtlety: Insufficient training
data

For example,

What now??? 43
Parameter estimation:
MLE, MAP
Estimating Probabilities

44
Flipping a Coin
I have a coin, if I flip it, what’s the probability it will fall with the head up?

Let us flip it a few times to estimate the probability:

The estimated probability is: 3/5 “Frequency of heads”

Why???... and How good is this estimation???


45
MLE for Bernoulli distribution
Data, D =

P(Heads) = θ, P(Tails) = 1-θ

Flips are i.i.d.:


– Independent events
– Identically distributed according to Bernoulli distribution

MLE: Choose θ that maximizes the probability of observed data


46
Maximum Likelihood
Estimation
MLE: Choose θ that maximizes the probability of observed data

Independent draws

Identically
distributed

47
Maximum Likelihood
Estimation
MLE: Choose θ that maximizes the probability of observed data

48
What about prior knowledge?
We know the coin is “close” to 50-50. What can we do now?

The Bayesian way…


Rather than estimating a single θ, we obtain a distribution over possible
values of θ

Before data After data

50-50
49
Bayesian Learning
• Use Bayes rule:

• Or equivalently:

posterior likelihood prior

50
MAP estimation for Binomial
distribution
Coin flip problem
Likelihood is Binomial
If the prior is Beta distribution,

) posterior is Beta distribution

P(θ) and P(θ| D) have the same form! [Conjugate prior]

51
MLE vs. MAP
 Maximum Likelihood estimation (MLE)
Choose value that maximizes the probability of observed data

 Maximum a posteriori (MAP) estimation


Choose value that is most probable given observed data and
prior belief

When is MAP same as MLE?


52
Bayesians vs.Frequentists
You are no
good when
sample is
small You give a
different
answer for
different
priors

53
What about continuous
features?

3 4 5 6 7 8 9

Let us try Gaussians…

σ2
σ2

µ=0 µ=0 54
MLE for Gaussian mean and
variance
Choose θ= (µ,σ2) that maximizes the probability of observed data

Independent draws

Identically
distributed

55
MLE for Gaussian mean and
variance

Note: MLE for the variance of a Gaussian is biased


[Expected result of estimation is not the true parameter!]

Unbiased variance estimator:


56
Case Study: Text Classification

57
Case Study: Text Classification
• Classify e-mails
– Y = {Spam,NotSpam}
• Classify news articles
– Y = {what is the topic of the article?

What about the features X?


The text!

58
Xi represents i word
th in document

59
NB for Text Classification
P(X|Y) is huge!!!
– Article at least 1000 words, X={X1,…,X1000}
– Xi represents ith word in document, i.e., the domain of Xi is entire
vocabulary, e.g., Webster Dictionary (or more).
Xi 2 {1,…,50000} ) K100050000 parameters….

NB assumption helps a lot!!!


– P(Xi=xi|Y=y) is the probability of observing word xi at the ith position in a
document on topic y ) 1000K50000 parameters

60
Bag of words model
Typical additional assumption – Position in document doesn’t
matter: P(Xi=xi|Y=y) = P(Xk=xi|Y=y)
– “Bag of words” model – order of words on the page ignored
– Sounds really silly, but often works very well! ) K50000 parameters

When the lecture is over, remember to wake up the


person sitting next to you in the lecture room.

61
Bag of words model
Typical additional assumption – Position in document doesn’t
matter: P(Xi=xi|Y=y) = P(Xk=xi|Y=y)
– “Bag of words” model – order of words on the page ignored
– Sounds really silly, but often works very well!

in is lecture lecture next over person remember room


sitting the the the to to up wake when you

62
Bag of words approach
aardvark 0
about 2
all 2
Africa 1
apple 0
anxious 0
...
gas 1
...
oil 1

Zaire 0

63
Twenty news groups results

Naïve Bayes: 89% accuracy


64
What if features are
continuous?
Eg., character recognition: Xi is intensity at ith pixel

Gaussian Naïve Bayes (GNB):

Different mean and variance for each class k and each pixel i.
Sometimes assume variance
• is independent of Y (i.e., σi),
• or independent of Xi (i.e., σk)
• or both (i.e., σ)
65
Example: GNB for
classifying mental states

~1 mm resolution
~2 images per sec.
15,000 voxels/image
non-invasive, safe
measures Blood Oxygen
Level Dependent (BOLD)
response [Mitchell et al.] 66
Learned Naïve Bayes Models –
Means for P(BrainActivity | WordCategory)
Pairwise classification accuracy: [Mitchell et al.]
78-99%, 12 participants
Tool words Building words

67
What you should know…
Naïve Bayes classifier
• What’s the assumption
• Why we use it
• How do we learn it
• Why is Bayesian (MAP) estimation important
Text classification
• Bag of words model
Gaussian NB
• Features are still conditionally independent
• Each feature has a Gaussian distribution given class

68
Further reading
Manuscript (book chapters 1 and 2)
http://alex.smola.org/teaching/berkeley2012/slides/chapter1_2.pdf

ML Books

Statistics 101

69
A tiny bit of extra theory…

70
Feasible events = σ-algebra

Examples:
a. All subsets of Ω={1,2,3}: { ;, {1},{2},{3},{1,2},{1,3},{2,3}, {1,2,3}}
b.
(Borel sets)
71
Measure

σ−additivity

Consequences:

monotonity
72
Important measures
Counting measure:

Borel measure:
This is not a complete measure: There are Borel sets with zero
measure, whose subsets are not Borel measurable…

Lebesgue measure:
complete extension of the Borel measure, i.e. extension & every subset of every
null set is Lebesgue measurable (having measure zero).

Lebesgue measure construction:

73
Brain Teasers 
These might be surprising:
• Construct an uncountable Lebesgue set with measure
zero.
• Construct a Lebesgue but not Borel set.
• Prove that there are not Lebesgue measurable sets. We
can’t ask what is the probability of that event!
• Construct a Borel nullset who has a not measurable subset

All sets Lebesgue

Borel

74
The Banach-Tarski paradox
(1924)
Given a solid ball in 3-dimensional space, there exists a decomposition of the ball into a
finite number of non-overlapping pieces (i.e., subsets), which can then be put back together
in a different way to yield two identical copies of the original ball.

The reassembly process involves only moving the pieces around and rotating them,
without changing their shape. However, the pieces themselves are not "solids" in the usual
sense, but infinite scatterings of points.

A stronger form of the theorem implies that given any two "reasonable" solid objects (such as a
small ball and a huge ball), either one can be reassembled into the other.

This is often stated colloquially as "a pea can be chopped up and reassembled into the Sun."

75
Tarski's circle-squaring
problem (1925)
Is it possible to take a disc in the plane, cut it into finitely many
pieces, and reassemble the pieces so as to get a square of equal
area?

Miklós Laczkovich (1990): It is possible using translations only;


rotations are not required. It is not possible with scissors. The
decomposition is non-constructive and uses about 1050 different
pieces.
76
Thanks for your attention 
References
Many slides are recycled from
• Tom Mitchel
http://www.cs.cmu.edu/~tom/10701_sp11/slides
• Alex Smola
• Aarti Singh
• Eric Xing
• Xi Chen
• http://www.math.ntu.edu.tw/~hchen/teaching
/StatInference/notes/lecture2.pdf
• Wikipedia
78

You might also like