Introduction to Machine Learning

Similar documents
ST 371 (IV): Discrete Random Variables

BNG 202 Biomechanics Lab. Descriptive statistics and probability distributions I

Summary of Formulas and Concepts. Descriptive Statistics (Ch. 1-4)

Chapter 4. Probability and Probability Distributions

STATS8: Introduction to Biostatistics. Data Exploration. Babak Shahbaba Department of Statistics, UCI

Descriptive statistics Statistical inference statistical inference, statistical induction and inferential statistics

Lecture 1: Review and Exploratory Data Analysis (EDA)

Probability and Statistics Vocabulary List (Definitions for Middle School Teachers)

Exploratory Data Analysis

Statistics I for QBIC. Contents and Objectives. Chapters 1 7. Revised: August 2013

E3: PROBABILITY AND STATISTICS lecture notes

An Introduction to Basic Statistics and Probability

Fairfield Public Schools

Characteristics of Binomial Distributions

5/31/ Normal Distributions. Normal Distributions. Chapter 6. Distribution. The Normal Distribution. Outline. Objectives.

MBA 611 STATISTICS AND QUANTITATIVE METHODS

You flip a fair coin four times, what is the probability that you obtain three heads.

MATH 140 Lab 4: Probability and the Standard Normal Distribution

Exploratory data analysis (Chapter 2) Fall 2011

Why Taking This Course? Course Introduction, Descriptive Statistics and Data Visualization. Learning Goals. GENOME 560, Spring 2012

Elementary Statistics

Introduction to Statistics for Psychology. Quantitative Methods for Human Sciences

A Correlation of. to the. South Carolina Data Analysis and Probability Standards

How To Write A Data Analysis

4. Continuous Random Variables, the Pareto and Normal Distributions

Chapter 5. Random variables

Probability & Probability Distributions

THE BINOMIAL DISTRIBUTION & PROBABILITY

Lecture 2. Summarizing the Sample

II. DISTRIBUTIONS distribution normal distribution. standard scores

6.4 Normal Distribution

Probability and statistics; Rehearsal for pattern recognition

Without data, all you are is just another person with an opinion.

Lecture 5 : The Poisson Distribution

CA200 Quantitative Analysis for Business Decisions. File name: CA200_Section_04A_StatisticsIntroduction

Descriptive Statistics. Purpose of descriptive statistics Frequency distributions Measures of central tendency Measures of dispersion

Normal distribution. ) 2 /2σ. 2π σ

AP STATISTICS REVIEW (YMS Chapters 1-8)

WEEK #22: PDFs and CDFs, Measures of Center and Spread

Center: Finding the Median. Median. Spread: Home on the Range. Center: Finding the Median (cont.)

Geostatistics Exploratory Analysis

Math/Stats 425 Introduction to Probability. 1. Uncertainty and the axioms of probability

Descriptive Statistics

3.4. The Binomial Probability Distribution. Copyright Cengage Learning. All rights reserved.

Probability Distributions

Institute of Actuaries of India Subject CT3 Probability and Mathematical Statistics

Lecture 2: Descriptive Statistics and Exploratory Data Analysis

Chapter 1: Looking at Data Section 1.1: Displaying Distributions with Graphs

The sample space for a pair of die rolls is the set. The sample space for a random number between 0 and 1 is the interval [0, 1].

The right edge of the box is the third quartile, Q 3, which is the median of the data values above the median. Maximum Median

Chapter 3: DISCRETE RANDOM VARIABLES AND PROBABILITY DISTRIBUTIONS. Part 3: Discrete Uniform Distribution Binomial Distribution

Descriptive Statistics

Lecture 14. Chapter 7: Probability. Rule 1: Rule 2: Rule 3: Nancy Pfenning Stats 1000

Graphs. Exploratory data analysis. Graphs. Standard forms. A graph is a suitable way of representing data if:

For a partition B 1,..., B n, where B i B j = for i. A = (A B 1 ) (A B 2 ),..., (A B n ) and thus. P (A) = P (A B i ) = P (A B i )P (B i )

Statistics 2014 Scoring Guidelines

IEOR 6711: Stochastic Models I Fall 2012, Professor Whitt, Tuesday, September 11 Normal Approximations and the Central Limit Theorem

Opgaven Onderzoeksmethoden, Onderdeel Statistiek

Statistics E100 Fall 2013 Practice Midterm I - A Solutions

Data Exploration Data Visualization

COMMON CORE STATE STANDARDS FOR

Random variables, probability distributions, binomial random variable

Probability and Statistics Prof. Dr. Somesh Kumar Department of Mathematics Indian Institute of Technology, Kharagpur

CALCULATIONS & STATISTICS

Pie Charts. proportion of ice-cream flavors sold annually by a given brand. AMS-5: Statistics. Cherry. Cherry. Blueberry. Blueberry. Apple.

Foundation of Quantitative Data Analysis

MTH 140 Statistics Videos

PROBABILITY AND SAMPLING DISTRIBUTIONS

Review for Test 2. Chapters 4, 5 and 6

Dongfeng Li. Autumn 2010

Didacticiel Études de cas

Random variables P(X = 3) = P(X = 3) = 1 8, P(X = 1) = P(X = 1) = 3 8.

Stats on the TI 83 and TI 84 Calculator

Week 3&4: Z tables and the Sampling Distribution of X

BASIC STATISTICAL METHODS FOR GENOMIC DATA ANALYSIS

Chapter 4 Lecture Notes

Chapter 4 - Lecture 1 Probability Density Functions and Cumul. Distribution Functions

MAS108 Probability I

Random Variables. Chapter 2. Random Variables 1

Curriculum Map Statistics and Probability Honors (348) Saugus High School Saugus Public Schools

A Few Basics of Probability

Lecture 1 Introduction Properties of Probability Methods of Enumeration Asrat Temesgen Stockholm University

2 Describing, Exploring, and

AP * Statistics Review. Descriptive Statistics

SOLUTIONS: 4.1 Probability Distributions and 4.2 Binomial Distributions

Diagrams and Graphs of Statistical Data

Course Syllabus MATH 110 Introduction to Statistics 3 credits

Density Curve. A density curve is the graph of a continuous probability distribution. It must satisfy the following properties:

DESCRIPTIVE STATISTICS - CHAPTERS 1 & 2 1

The Big Picture. Describing Data: Categorical and Quantitative Variables Population. Descriptive Statistics. Community Coalitions (n = 175)

Statistics in Geophysics: Introduction and Probability Theory

Bayesian Updating with Discrete Priors Class 11, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

Chapter 4. Probability Distributions

MAS131: Introduction to Probability and Statistics Semester 1: Introduction to Probability Lecturer: Dr D J Wilkinson

Point and Interval Estimates

STATISTICS 8: CHAPTERS 7 TO 10, SAMPLE MULTIPLE CHOICE QUESTIONS

Statistics 104: Section 6!

Lecture 9: Introduction to Pattern Analysis

Probability Distributions

Section 5 Part 2. Probability Distributions for Discrete Random Variables

Transcription:

Introduction to Machine Learning Practical sessions Barbora Hladká, Martin Holub Institute of Formal and Applied Linguistics Charles University in Prague 2013/14 1 / 57

Machine Learning Lab Sessions Goals of the lab sessions to learn how to practically analyse example data and ML tasks to learn how to practically implement some ML methods to solve a particular task practical experience with R system for statistical computing and graphics http://www.r-project.org/ 2 / 57

Gentle introduction to R R is a library of statistical tools an interactive environment for statistical analyses and graphics a programming language a public free software derived from the commercial system S R is becoming more and more popular especially for its effective data handling and storage facility large, coherent, integrated collection of tools for data analysis well-developed, simple and effective programming language Recommended reading An Introduction to R by W. N. Venables, D. M. Smith and the R core team also, an introduction available on the web: http://cran.r-project.org/doc/manuals/r-intro.html R for Beginners by Emmanuel Paradis 3 / 57

Gentle introduction to R R is a library of statistical tools an interactive environment for statistical analyses and graphics a programming language a public free software derived from the commercial system S R is becoming more and more popular especially for its effective data handling and storage facility large, coherent, integrated collection of tools for data analysis well-developed, simple and effective programming language Recommended reading An Introduction to R by W. N. Venables, D. M. Smith and the R core team also, an introduction available on the web: http://cran.r-project.org/doc/manuals/r-intro.html R for Beginners by Emmanuel Paradis 4 / 57

Gentle introduction to R R is a library of statistical tools an interactive environment for statistical analyses and graphics a programming language a public free software derived from the commercial system S R is becoming more and more popular especially for its effective data handling and storage facility large, coherent, integrated collection of tools for data analysis well-developed, simple and effective programming language Recommended reading An Introduction to R by W. N. Venables, D. M. Smith and the R core team also, an introduction available on the web: http://cran.r-project.org/doc/manuals/r-intro.html R for Beginners by Emmanuel Paradis 5 / 57

To get your credits you have to to attend the lab sessions (more or less regularly) to do homework exercises to work on your term project (will be assigned in November) to submit your short presentation in December to present your short presentation (at the lab sessions) to submit your final project solution in February to defend your project solution (individually) 6 / 57

Outline 1 Overview of mathematial foundations Why statistics? Probability basics Warming exercises Conditional probability and the Bayes rule Random variables and probability distributions Examples of probability distributions Measures of location and spread 2 Homework 3 Literature 4 More easy exercises 7 / 57

Why statistics and probability theory? Motivation In machine learning, models come from data and provide insights for understanding data (unsupervised classification) or making prediction (supervised learning). A good model is often a model which not only fits the data but gives good predictions, even if it is not interpretable. Statistics is the science of the collection, organization, and interpretation of data uses the probability theory 8 / 57

Two purposes of statistical analysis Statistics is the study of the collection, organization, analysis, and interpretation of data. It deals with all aspects of this, including the planning of data collection in terms of the design of surveys and experiments. Description describing what was observed in sample data numerically or graphically Inference drawing inferences about the population represented by the sample data 9 / 57

Populations and statistics (plural) In statistics, a population is any finite or infinite collection of items under consideration. Usually the population is an entire set of all entities or events of a given type/kind. The word statistics (the scientific discipline) should not be confused with the word statistic, referring to a quantity calculated from a data sample. Statistics are calculated by applying a function (or a statistical algorithm) to the values of the items comprising the sample. More formally, statistical theory defines a statistic as a function of a sample where the function itself is independent of the sample s distribution; that is, the function can be stated before realisation of the data. The term statistic is used both for the function and for the value of the function on a given sample. 10 / 57

Statistical parameters, and estimators Statistical parameter is a value that describes a property of a statistical population. Statistical parameters are distinct from statistics. They are generally not computable because often the population is too large to examine and measure all its items. Parameters statistically characterize populations, while statistics characterize samples. A statistic, when used to estimate a population parameter, is called an estimator. For instance, the sample mean is a statistic which estimates the population mean, which is a parameter. Observability A statistic is an observable random variable, which differentiates it from a parameter that is a generally unobservable quantity. A parameter can only be computed exactly if the entire population can be observed without error. 11 / 57

Descriptive statistics Descriptive statistics describes the main characteristics of a collection of data. It summarizes the population data by describing what was observed in the sample numerically (quantitatively) or graphically. Numerical descriptors include e.g. mean and standard deviation for continuous data types (like heights or weights), while frequency and percentage are more useful in terms of describing categorical data (like race). A histogram is an example of a graphical representation showing a visual impression of the distribution of data. It is an estimate of the probability distribution. 12 / 57

Inferential statistics Inferential statistics uses patterns in the sample data to draw inferences about the population represented, accounting for randomness. These inferences may take the form of: answering yes/no questions about the data (hypothesis testing) estimating numerical characteristics of the data (estimation) describing associations within the data (correlation) modeling relationships within the data (for example, using regression analysis) Inference can extend to forecasting, prediction and estimation of unobserved values either in or associated with the population being studied; it can include extrapolation and interpolation of time series or spatial data, and can also include data mining. 13 / 57

Two approaches to probability classical based on the knowledge of probability of elementary events statistical based on empirical observation and relative frequencies 14 / 57

Probability theory basic terms random experiment elementary outcomes ω i sample space Ω = {ω i } event A Ω complement of an event A c = Ω \ A probability of any event is a non-negative value P(A) 0 total probability of all elementary outcomes is one P(ω) = 1 ω Ω if two events A, B are mutually exclusive (i.e. A B = ), then P(A B) = P(A) + P(B) 15 / 57

Basic formulas to calculate probabilities Generally, probability of an event A is P(A) = P(ω) ω A Probability of an complement event is P(A c ) = 1 P(A) IF all elementary outcomes have the same probability, THEN probability of an event is given by the proportion of number of desired outcomes total number of outcomes possible 16 / 57

What is P(A or B)? P(A or B) = P(A B) For mutually exclusive events: otherwise (generally): P(A or B) = P(A) + P(B) P(A or B) = P(A) + P(B) P(A B) 17 / 57

What is P(A and B)? P(A and B) = P(A B) Two events A and B are independent of each other if the occurrence of one has no influence on the probability of the other. For independent events: otherwise (generally): P(A and B) = P(A) P(B) P(A and B) = P(A B) P(B) = P(B A) P(A) 18 / 57

Warming exercises Rolling two dice, observing the sum. What is likelier? a) the sum is even b) the sum is greater than 8 c) the sum is 5 or 7 What is likelier: a) rolling at least one six in four throws of a single die, OR b) rolling at least one double six in 24 throws of a pair of dice? When we roll 3 dice, which sum is likelier, 11 or 12? Note that there are only 6 options how to get the sum 11: 4+4+3 4+5+2 4+6+1 5+5+1 5+3+3 6+3+2 And also, there are only 6 options how to get the sum 12: 4+4+4 4+5+3 4+6+2 5+5+2 5+6+1 6+3+3 19 / 57

Definition of conditional probability Conditional probability of the event A given the event B is P(A B) = P(A B) P(B) = P(A, B) P(B) Or, in other words, P(A, B) = P(A B)P(B) 20 / 57

Statistically independent events Definition: The random event B is independent of the random event A, if the following holds true at the same time: P(B) = P(B A), P(B) = P(B A c ). An equivalent definition is that B is independent of A if P(A) P(B) = P(A B). 21 / 57

Computing conditional probability Exercise The probability that it is Friday and that a student is absent is 3 %. Since there are 5 school days in a week, the probability that it is Friday is 20 %. What is the probability that a student is absent given that today is Friday? 22 / 57

Solution Random experiment: Events: At a random moment we observe the day in working week and the fact if a student is absent. A... it is Friday B... a student is absent Probabilities: P(A, B) = 0.03 P(A) = 0.2 P(B A) = P(A, B)/P(A) = 0.15 Correct answer: The probability that a student is absent given that today is Friday is 15 %. 23 / 57

Bayes rule Because of the symmetry P(A, B) = P(B, A), we have And thus P(A, B) = P(A B)P(B) = P(B A)P(A) = P(B, A) P(B A) = P(A B)P(B) P(A) 24 / 57

Computing P(B) when you know both P(A) and the two probabilities P(B A) and P(B A c ) Ω A A c B Ω = A [ A c B = (B A) [ (B A c ) P(B) = P(B, A) + P(B, A c ) P(B) = P(B A) P(A) + P(B A c ) P(A c ) 25 / 57

Generalized Bayes rule Generally, when the set of n events A 1, A 2,... A n form a mutually exclusive and exhaustive system, i.e. Ω = A i and A i A j = for i j, then for any event B Ω, P(B) 0 we have P(B) = n B = B A i, i=1 n n P(B A i ) = P(B A i )P(A i ). i=1 i=1 Generalized Bayes rule says P(A i B) = P(B A i) P(B) = P(B A i)p(a i ) n P(B A j )P(A j ) j=1 26 / 57

Using Bayes rule Exercise One coin in a collection of 65 has two heads. The rest are fair. If a coin, chosen at random from the lot and then tossed, turns up heads 6 times in a row, what is the probability that it is the two-headed coin? 27 / 57

Random variables A random variable (or sometimes stochastic variable) is, roughly speaking, a variable whose value results from a measurement/observation on some type of random process. Intuitively, a random variable is a numerical or categorical description of the outcome of a random experiment (or a random event). Random variables can be classified as either discrete = a random variable that may assume either a finite number of values or an infinite sequence of values (countably infinite) continuous = a variable that may assume any numerical value in an interval or collection of intervals. 28 / 57

Probability description Probability distributions are used to describe the probabilities of different values occurring. Discrete probability distributions are usually characterised by the probability mass function that assigns a probability to each possible value of the random variable (often it can be described by a table or by a histogram). Continuous probability distributions are usually characterised either by the cumulative distribution function or by the probability density function. 29 / 57

Probability distribution Probability distribution identifies either the probability of each value of a random variable (discrete case), or the probability of the value falling within a particular interval (continuous case) You should definitely know probability mass function (PMF) histograms cumulative distribution function (CDF) probability density function (PDF) quantile function 30 / 57

Example PMF When you roll two dice and add the result together, what will be the total? 31 / 57

Mean and variance Expected value or mean of a (numerical) random variable is given by E X = x P(X = x) all x Variance of a (numerical) random variable is defined as var X = E (X E X) 2 Variance is often computed using the equality var X = E X 2 (E X) 2 Standard deviation is often denoted by σ = var X 32 / 57

Binomial distribution The binomial distribution is a discrete distribution of values 1,..., n (n N). If a random variable X gets only values 1,..., n with probabilities ( ) n P(X = k) = p k (1 p) n k, k where p (0, 1), then X has binomial distribution X Bi(n, p). If q = 1 p, then E X = np and var X = npq. If n = 1, we call it Bernoulli distribution. 33 / 57

Examples/exercises When you roll a die 50 times, how many sixes will you get? How many times do you need to roll a die to get the first six? How many times do you need to roll a die to get just six sixes? When you roll six dice, how many different numbers will you get? 34 / 57

Examples/exercises When you roll a die 50 times, how many sixes will you get? How many times do you need to roll a die to get the first six? How many times do you need to roll a die to get just six sixes? When you roll six dice, how many different numbers will you get? 35 / 57

Examples/exercises When you roll a die 50 times, how many sixes will you get? How many times do you need to roll a die to get the first six? How many times do you need to roll a die to get just six sixes? When you roll six dice, how many different numbers will you get? 36 / 57

Examples/exercises When you roll a die 50 times, how many sixes will you get? How many times do you need to roll a die to get the first six? How many times do you need to roll a die to get just six sixes? When you roll six dice, how many different numbers will you get? 37 / 57

Normal distribution The normal distribution is a continuous distribution and has density f (x) = 1 2πσ e (x µ)2 2σ 2, where µ is the mean of the distribution and σ is the standard deviation. When a random variable X has normal distribution with parameters µ R and σ 2 > 0, we write X N(µ, σ 2 ). Then E X = µ and var X = σ 2. The distribution N(0, 1) is called standard normal distribution. It has density φ(x) = 1 e x 2 /2 2π and cumulative distribution Φ(x) = x φ(t) dt. 38 / 57

Normal approximation If n is large enough, then a reasonable approximation to Bi(n, p) is given by the normal distribution N(np, np(1 p)). 39 / 57

Normal distribution CDF and PDF 40 / 57

Example who is typical? Exercise In 2001 it was found that the average male height in the Czech Republic is 180.3 cm, while the average female height is 167.2 cm. We assume that both distributions are normal. Question: Who is more typical: a man with the height of 178 cm, or a woman with the height of 169 cm? 41 / 57

Normal distribution example Question: Having a normally distributed population with mean µ and variance σ 2, what is the probability that a randomly selected value will fall into the interval (µ σ, µ + σ)? Answer: about 68% of values drawn from a normal distribution are within one standard deviation σ away from the mean about 95% of the values lie within two standard deviations about 99.7% are within three standard deviations. This fact is known as the 68-95-99.7 rule, or the empirical rule, or the 3-sigma rule. Exercise Assume that the variance of men s height is 100, while the variance of women s height is only 50. Then answer the question from the previous page. 42 / 57

Normal distribution example Question: Having a normally distributed population with mean µ and variance σ 2, what is the probability that a randomly selected value will fall into the interval (µ σ, µ + σ)? Answer: about 68% of values drawn from a normal distribution are within one standard deviation σ away from the mean about 95% of the values lie within two standard deviations about 99.7% are within three standard deviations. This fact is known as the 68-95-99.7 rule, or the empirical rule, or the 3-sigma rule. Exercise Assume that the variance of men s height is 100, while the variance of women s height is only 50. Then answer the question from the previous page. 43 / 57

Normal distribution example Question: Having a normally distributed population with mean µ and variance σ 2, what is the probability that a randomly selected value will fall into the interval (µ σ, µ + σ)? Answer: about 68% of values drawn from a normal distribution are within one standard deviation σ away from the mean about 95% of the values lie within two standard deviations about 99.7% are within three standard deviations. This fact is known as the 68-95-99.7 rule, or the empirical rule, or the 3-sigma rule. Exercise Assume that the variance of men s height is 100, while the variance of women s height is only 50. Then answer the question from the previous page. 44 / 57

Normal distribution the area under the bell 45 / 57

Measures of location and spread To describe a set (or sample) of data x 1,..., x n we use several basic statistics that can characterize the location and the spread of the values. Measures of location Extreme values minimum, maximum Sample mean (average) is x = 1 n x i n i=1 Other measures of central tendency midrange, median, mode, quartiles Five number summary: Min, Q 1, Median, Q 3, Max Measures of spread Range Inter-quartile range is IQR = Q 3 Q 1 Sample variance is s 2 = 1 n (x i x) n 1 i=1 Sample standard deviation is s = s 2 46 / 57

Box plots In descriptive statistics, a boxplot (also known as a box-and-whisker diagram or plot) is a convenient way of graphically depicting groups of numerical data through their lower quartile (Q1), median (Q2), and upper quartile (Q3). A boxplot may also indicate which observations might be considered outliers. The ends of the whiskers can represent several possible alternative values: the minimum and maximum of all the data the lowest datum still within 1.5 IQR of the lower quartile, and the highest datum still within 1.5 IQR of the upper quartile one standard deviation above and below the mean of the data 47 / 57

Homework Go through all exercises carefully and make sure that you are clear about their correct solution! So that you get ready for the tests. Install the R system on your home computer (freely available for both Linux or Windows). 48 / 57

Recommended literature Larry Gonick & Woollcott Smith: The Cartoon Guide to Statistics 49 / 57

Some easy exercises Exercise In a certain population, 30% of the persons smoke and 8% have a certain type of heart disease. Moreover, 12% of the persons who smoke have the disease. a) What percentage of the population smoke and have the disease? b) What percentage of the population with the disease also smoke? Formulate this task and its solution in the terms of probability and conditional probability! 50 / 57

Some easy exercises Exercise Consider the experiment that consists of rolling 2 fair dice. Let X denote the first die score, and S denote sum of the scores. Now consider the following random events A, B, C, and D: A... X = 3 B... X = 2 C... S = 5 D... S = 7 a) Find the probability of each event. b) Find the conditional probabilities P(A C), P(C A), P(A D), P(D A), P(B C), P(C B). c) Are some of the events A, B, C, D independent? 51 / 57

Some easy exercises Exercise In a town, 48% of all teenagers own a skateboard and 39% of all teenagers own a skateboard and roller blades. What is the probability that a teenager owns roller blades given that the teenager owns a skateboard? 52 / 57

Some easy exercises Exercise In a certain population, the probability a woman lives to at least seventy years is 0.70 and is 0.55 that she will live to at least eighty years. If a woman is seventy years old, what is the conditional probability she will survive to eighty years? 53 / 57

Some easy exercises Exercise In a survey, 85 percent of the employees say they favor a certain company policy. Previous experience indicates that 20 percent of those who do not favor the policy say that they do, out of fear of reprisal. What is the probability that an employee picked at random really does favor the company policy? It is reasonable to assume that all who favor say so. 54 / 57

Some easy exercises Exercise Two fair dice are rolled. a) What is the (conditional) probability that one turns up two spots, given they show different numbers? b) What is the (conditional) probability that the first turns up six, given that the sum is 10? c) What is the (conditional) probability that at least one turns up six, given that the sum is 10? 55 / 57

Some easy exercises Exercise Four persons are to be selected from a group of 12 people, 7 of whom are women. What is the probability that the first and third selected are women? 56 / 57

Some easy exercises Exercise A doctor assumes that a patient has one of three diseases d1, d2, or d3. Before any test, he assumes an equal probability for each disease. He carries out a test that will be positive with probability 0.8 if the patient has d1, 0.6 if he has disease d2, and 0.4 if he has disease d3. Given that the outcome of the test was positive, what probabilities should the doctor now assign to the three possible diseases? 57 / 57