tutorial 1 - university of british columbiaschmidtm/courses/340-f16/t1.pdftutorial 1 1/21 overview...
TRANSCRIPT
![Page 1: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/1.jpg)
Tutorial 1
1 / 21
![Page 2: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/2.jpg)
Overview
Linear AlgebraNotation
MATLABData TypesData Visualization
ProbabilityReviewExercises
Asymptotics (Big-O)Review
2 / 21
![Page 3: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/3.jpg)
Linear Algebra Notation
Notation and Convention
I Vectors a =
123
are denoted by lower-case letters.
I Matrices X =
[1 2 34 5 6
]are denoted by upper-case letters.
I X above is a 2 by 3 matrix (“nrow by ncol”).
I Vectors are by default column vectors (ie. d× 1 matrices)
I One can sometimes save space by using transpose operatorand write a column vector on a single line.
b =
248
=[2 4 8
]T
3 / 21
![Page 4: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/4.jpg)
Linear Algebra Notation
Notation and Convention
I Vectors a =
123
are denoted by lower-case letters.
I Matrices X =
[1 2 34 5 6
]are denoted by upper-case letters.
I X above is a 2 by 3 matrix (“nrow by ncol”).
I Vectors are by default column vectors (ie. d× 1 matrices)
I One can sometimes save space by using transpose operatorand write a column vector on a single line.
b =
248
=[2 4 8
]T
3 / 21
![Page 5: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/5.jpg)
Linear Algebra Notation
Notation and Convention
I Vectors a =
123
are denoted by lower-case letters.
I Matrices X =
[1 2 34 5 6
]are denoted by upper-case letters.
I X above is a 2 by 3 matrix (“nrow by ncol”).
I Vectors are by default column vectors (ie. d× 1 matrices)
I One can sometimes save space by using transpose operatorand write a column vector on a single line.
b =
248
=[2 4 8
]T
3 / 21
![Page 6: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/6.jpg)
Linear Algebra Notation
Notation and Convention
I Vectors a =
123
are denoted by lower-case letters.
I Matrices X =
[1 2 34 5 6
]are denoted by upper-case letters.
I X above is a 2 by 3 matrix (“nrow by ncol”).
I Vectors are by default column vectors (ie. d× 1 matrices)
I One can sometimes save space by using transpose operatorand write a column vector on a single line.
b =
248
=[2 4 8
]T
3 / 21
![Page 7: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/7.jpg)
Linear Algebra Notation
Notation and Convention
I Vectors a =
123
are denoted by lower-case letters.
I Matrices X =
[1 2 34 5 6
]are denoted by upper-case letters.
I X above is a 2 by 3 matrix (“nrow by ncol”).
I Vectors are by default column vectors (ie. d× 1 matrices)
I One can sometimes save space by using transpose operatorand write a column vector on a single line.
b =
248
=[2 4 8
]T
3 / 21
![Page 8: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/8.jpg)
Linear Algebra Notation
Notation and Convention
I Vectors a =
123
are denoted by lower-case letters.
I Matrices X =
[1 2 34 5 6
]are denoted by upper-case letters.
I X above is a 2 by 3 matrix (“nrow by ncol”).
I Vectors are by default column vectors (ie. d× 1 matrices)
I One can sometimes save space by using transpose operatorand write a column vector on a single line.
b =
248
=[2 4 8
]T3 / 21
![Page 9: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/9.jpg)
MATLAB
Linear AlgebraNotation
MATLABData TypesData Visualization
ProbabilityReviewExercises
Asymptotics (Big-O)Review
4 / 21
![Page 10: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/10.jpg)
MATLAB Data Types
Data Types
matrices and vectors/arrays
I A = [ 1 2 3 ; 4 5 6 ; 7 8 9] % a 3x3 matrix
I b = [1 2 3] % a row vector
I c = [1; 2; 3] % a column vector
I d = [2] % this is a scalar, equivalent to ‘‘d = 2’’
multiplication operator is overloaded
I A*d matrix-scalar multiplication
I A*c matrix-vector multiplication
I A*A matrix-matrix multiplication
solving linear systems
I A\b solves the linear system Ax = b
5 / 21
![Page 11: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/11.jpg)
MATLAB Data Types
Data Types
matrices and vectors/arrays
I A = [ 1 2 3 ; 4 5 6 ; 7 8 9] % a 3x3 matrix
I b = [1 2 3] % a row vector
I c = [1; 2; 3] % a column vector
I d = [2] % this is a scalar, equivalent to ‘‘d = 2’’
multiplication operator is overloaded
I A*d matrix-scalar multiplication
I A*c matrix-vector multiplication
I A*A matrix-matrix multiplication
solving linear systems
I A\b solves the linear system Ax = b
5 / 21
![Page 12: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/12.jpg)
MATLAB Data Types
Data Types
matrices and vectors/arrays
I A = [ 1 2 3 ; 4 5 6 ; 7 8 9] % a 3x3 matrix
I b = [1 2 3] % a row vector
I c = [1; 2; 3] % a column vector
I d = [2] % this is a scalar, equivalent to ‘‘d = 2’’
multiplication operator is overloaded
I A*d matrix-scalar multiplication
I A*c matrix-vector multiplication
I A*A matrix-matrix multiplication
solving linear systems
I A\b solves the linear system Ax = b
5 / 21
![Page 13: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/13.jpg)
MATLAB Data Types
Data Types
accessing elements
I c(1) note the bracket type (parenthesis) and one-indexing
I A(1,2) gives a scalar
I A(1,:) gives a row vector (slicing)
I A(2:3,:) gives a size-2 row vector
I A(2:end,:) same as previous
I b=[1,3] ; A(b,:) in case you want a non-contiguous slice
“booleans”
I In MATLAB, true and false are almost synonymous with 1and 0. (ie. true == 1 and false == 0 both return 1)
I A([true, false, true],:) == A([1,3],:) (ie. a mask)
I true and false can be used as 1 and 0 (true * 10 == 10)
I caveat: A([1,0,1],:) fails. Nice try MATLAB.
6 / 21
![Page 14: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/14.jpg)
MATLAB Data Types
Data Types
accessing elements
I c(1) note the bracket type (parenthesis) and one-indexing
I A(1,2) gives a scalar
I A(1,:) gives a row vector (slicing)
I A(2:3,:) gives a size-2 row vector
I A(2:end,:) same as previous
I b=[1,3] ; A(b,:) in case you want a non-contiguous slice
“booleans”
I In MATLAB, true and false are almost synonymous with 1and 0. (ie. true == 1 and false == 0 both return 1)
I A([true, false, true],:) == A([1,3],:) (ie. a mask)
I true and false can be used as 1 and 0 (true * 10 == 10)
I caveat: A([1,0,1],:) fails. Nice try MATLAB.
6 / 21
![Page 15: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/15.jpg)
MATLAB Data Types
Data Types
accessing elements
I c(1) note the bracket type (parenthesis) and one-indexing
I A(1,2) gives a scalar
I A(1,:) gives a row vector (slicing)
I A(2:3,:) gives a size-2 row vector
I A(2:end,:) same as previous
I b=[1,3] ; A(b,:) in case you want a non-contiguous slice
“booleans”
I In MATLAB, true and false are almost synonymous with 1and 0. (ie. true == 1 and false == 0 both return 1)
I A([true, false, true],:) == A([1,3],:) (ie. a mask)
I true and false can be used as 1 and 0 (true * 10 == 10)
I caveat: A([1,0,1],:) fails. Nice try MATLAB.6 / 21
![Page 16: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/16.jpg)
MATLAB Data Visualization
Data Exploration Basics
I Use builtin functions to read data
data = csvread(’london2012.csv’);
I Each row is an athlete of the London 2012 summer Olympics.
I Check dataset size
size(data)
I This dataset has the following 7 descriptive features:(Age, Height, Weight, Gender(1==female)
# Bronze, # Silver, # Gold Medals
)
7 / 21
![Page 17: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/17.jpg)
MATLAB Data Visualization
Data Exploration Basics
I Use builtin functions to read data
data = csvread(’london2012.csv’);
I Each row is an athlete of the London 2012 summer Olympics.
I Check dataset size
size(data)
I This dataset has the following 7 descriptive features:(Age, Height, Weight, Gender(1==female)
# Bronze, # Silver, # Gold Medals
)
7 / 21
![Page 18: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/18.jpg)
MATLAB Data Visualization
Data Exploration Basics
I Use builtin functions to read data
data = csvread(’london2012.csv’);
I Each row is an athlete of the London 2012 summer Olympics.
I Check dataset size
size(data)
I This dataset has the following 7 descriptive features:(Age, Height, Weight, Gender(1==female)
# Bronze, # Silver, # Gold Medals
)
7 / 21
![Page 19: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/19.jpg)
MATLAB Data Visualization
Histogram
I Let’s visualize some information.I What was the distribution of age?
I Plot a histogram with 20 binsage = data(:,1); hist(age,20)
I Add some axis labels and a title
xlabel(’Age’); ylabel(’Number of Athletes’)
title(’Age Distribution of Athletes’)
Age10 20 30 40 50 60 70 80
Num
ber
of A
thle
tes
0
500
1000
1500
2000
2500Age Distribution of Athletes
8 / 21
![Page 20: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/20.jpg)
MATLAB Data Visualization
Histogram
I Let’s visualize some information.I What was the distribution of age?I Plot a histogram with 20 bins
age = data(:,1); hist(age,20)
I Add some axis labels and a title
xlabel(’Age’); ylabel(’Number of Athletes’)
title(’Age Distribution of Athletes’)
Age10 20 30 40 50 60 70 80
Num
ber
of A
thle
tes
0
500
1000
1500
2000
2500Age Distribution of Athletes
8 / 21
![Page 21: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/21.jpg)
MATLAB Data Visualization
Histogram
I Let’s visualize some information.I What was the distribution of age?I Plot a histogram with 20 bins
age = data(:,1); hist(age,20)I Add some axis labels and a title
xlabel(’Age’); ylabel(’Number of Athletes’)
title(’Age Distribution of Athletes’)
Age10 20 30 40 50 60 70 80
Num
ber
of A
thle
tes
0
500
1000
1500
2000
2500Age Distribution of Athletes
8 / 21
![Page 22: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/22.jpg)
MATLAB Data Visualization
Scatterplot
I Plot a scatterplot of height vs. weight
height = data(:,2); weight = data(:,3)
scatter(height, weight)
Height120 140 160 180 200 220 240
Wei
ght
20
40
60
80
100
120
140
160
180
200
220Athlete Weight vs. Height
9 / 21
![Page 23: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/23.jpg)
MATLAB Data Visualization
Scatterplot
I Plot a scatterplot of height vs. weight
height = data(:,2); weight = data(:,3)
scatter(height, weight)
Height120 140 160 180 200 220 240
Wei
ght
20
40
60
80
100
120
140
160
180
200
220Athlete Weight vs. Height
9 / 21
![Page 24: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/24.jpg)
MATLAB Data Visualization
Scatterplot
I scatter has options for marker size and color.
gender = data(:,4)
scatter(height, weight, [], gender)
Height120 140 160 180 200 220 240
Wei
ght
20
40
60
80
100
120
140
160
180
200
220Athlete Weight vs. Height
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
10 / 21
![Page 25: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/25.jpg)
MATLAB Data Visualization
Scatterplot
I scatter has options for marker size and color.
gender = data(:,4)
scatter(height, weight, [], gender)
Height120 140 160 180 200 220 240
Wei
ght
20
40
60
80
100
120
140
160
180
200
220Athlete Weight vs. Height
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
10 / 21
![Page 26: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/26.jpg)
MATLAB Data Visualization
Boxplot
I Plots the first, second, and third quartiles.I A boxplot of weight for each age:
boxplot(weight, age)
Age1314151617181920212223242526272829303132333435363738394041424344454647484950515253545657586571
Wei
ght
40
60
80
100
120
140
160
180
200
220
Boxplot of Athlete Weight
11 / 21
![Page 27: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/27.jpg)
MATLAB Data Visualization
Boxplot
I Plots the first, second, and third quartiles.I A boxplot of weight for each age:
boxplot(weight, age)
Age1314151617181920212223242526272829303132333435363738394041424344454647484950515253545657586571
Wei
ght
40
60
80
100
120
140
160
180
200
220
Boxplot of Athlete Weight
11 / 21
![Page 28: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/28.jpg)
MATLAB Data Visualization
Boxplot
I Okay that was messy. Let’s first discretize age (ie.bin/bucket) into groups of 5.
I This rounds everybody’s age down to nearest fifth:
dage = discretize(age, 10:5:80)*5;
boxplot(weight, dage)
Age10 15 20 25 30 35 40 45 50 55 65 70
Wei
ght
50
100
150
200
Boxplot of Athlete Weight
12 / 21
![Page 29: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/29.jpg)
MATLAB Data Visualization
Boxplot
I Okay that was messy. Let’s first discretize age (ie.bin/bucket) into groups of 5.
I This rounds everybody’s age down to nearest fifth:
dage = discretize(age, 10:5:80)*5;
boxplot(weight, dage)
Age10 15 20 25 30 35 40 45 50 55 65 70
Wei
ght
50
100
150
200
Boxplot of Athlete Weight
12 / 21
![Page 30: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/30.jpg)
MATLAB Docs and Sources of Info
When In Doubt
I If you know what function to use but don’t know how to useit, check the help command. e.g.
>> help plot
I Otherwise, use online resources (Google, Piazza, etc.)
13 / 21
![Page 31: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/31.jpg)
Probability
Linear AlgebraNotation
MATLABData TypesData Visualization
ProbabilityReviewExercises
Asymptotics (Big-O)Review
14 / 21
![Page 32: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/32.jpg)
Probability Review
Probability Notation
I Events - “Let A be the event that the coin lands on heads”
I Random variables - “Let X be the result of the coin flip,where 1 and 0 would represent heads and tails respectively”
I Assigning probabilities to events - e.g. P (A), P (X = 1)
I P (X = ·) (or PX(·)) is a function that, when given a value x,returns the probability of the event (X = x)
P (X = x) = PX(x) = 0.5x(1− 0.5)1−x
or
PX(x) =
{0.5 x = 0
0.5 x = 1
15 / 21
![Page 33: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/33.jpg)
Probability Review
Probability Notation
I Events - “Let A be the event that the coin lands on heads”
I Random variables - “Let X be the result of the coin flip,where 1 and 0 would represent heads and tails respectively”
I Assigning probabilities to events - e.g. P (A), P (X = 1)
I P (X = ·) (or PX(·)) is a function that, when given a value x,returns the probability of the event (X = x)
P (X = x) = PX(x) = 0.5x(1− 0.5)1−x
or
PX(x) =
{0.5 x = 0
0.5 x = 1
15 / 21
![Page 34: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/34.jpg)
Probability Review
Probability Notation
I Events - “Let A be the event that the coin lands on heads”
I Random variables - “Let X be the result of the coin flip,where 1 and 0 would represent heads and tails respectively”
I Assigning probabilities to events - e.g. P (A), P (X = 1)
I P (X = ·) (or PX(·)) is a function that, when given a value x,returns the probability of the event (X = x)
P (X = x) = PX(x) = 0.5x(1− 0.5)1−x
or
PX(x) =
{0.5 x = 0
0.5 x = 1
15 / 21
![Page 35: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/35.jpg)
Probability Review
Probability Notation
I Events - “Let A be the event that the coin lands on heads”
I Random variables - “Let X be the result of the coin flip,where 1 and 0 would represent heads and tails respectively”
I Assigning probabilities to events - e.g. P (A), P (X = 1)
I P (X = ·) (or PX(·)) is a function that, when given a value x,returns the probability of the event (X = x)
P (X = x) = PX(x) = 0.5x(1− 0.5)1−x
or
PX(x) =
{0.5 x = 0
0.5 x = 1
15 / 21
![Page 36: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/36.jpg)
Probability Review
Probability Notation
I Events - “Let A be the event that the coin lands on heads”
I Random variables - “Let X be the result of the coin flip,where 1 and 0 would represent heads and tails respectively”
I Assigning probabilities to events - e.g. P (A), P (X = 1)
I P (X = ·) (or PX(·)) is a function that, when given a value x,returns the probability of the event (X = x)
P (X = x) = PX(x) = 0.5x(1− 0.5)1−x
or
PX(x) =
{0.5 x = 0
0.5 x = 1
15 / 21
![Page 37: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/37.jpg)
Probability Review
Probability Notation
I Events - “Let A be the event that the coin lands on heads”
I Random variables - “Let X be the result of the coin flip,where 1 and 0 would represent heads and tails respectively”
I Assigning probabilities to events - e.g. P (A), P (X = 1)
I P (X = ·) (or PX(·)) is a function that, when given a value x,returns the probability of the event (X = x)
P (X = x) = PX(x) = 0.5x(1− 0.5)1−x
or
PX(x) =
{0.5 x = 0
0.5 x = 1
15 / 21
![Page 38: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/38.jpg)
Probability Exercises
Exercise 1: Conditional Probability Review
I Flip 2 coins. If I tell you that the first coin landed heads,what is the probability that the second coin landed heads?
I If I instead tell you that at least one coin landed heads, whatis the probability that both coins land heads?
16 / 21
![Page 39: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/39.jpg)
Probability Exercises
Exercise 2: Why You Should Go To Tutorials
Suppose 80% of students who get above A goes to all tutorials,and 80% of students who get below A do not go to all tutorials.Suppose only 20% of students get above A.What is the probability of a student who goes to all tutorialsgetting an A in the course? (Hint: much higher than 0.2)
Reminder - Bayes’ Rule:
P (A|B) =P (B|A)P (A)
P (B)
(A and B can be either events or random variables.)
17 / 21
![Page 40: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/40.jpg)
Asymptotics (Big-O)
Linear AlgebraNotation
MATLABData TypesData Visualization
ProbabilityReviewExercises
Asymptotics (Big-O)Review
18 / 21
![Page 41: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/41.jpg)
Asymptotics (Big-O) Review
Definition
The notationg(n) = O(f(n))
means “for all large n, g(n) ≤ cf(n) for some constant c > 0”.
Examples:
I 20n + 5 = O(n)
I n2 + 200n = O(n2)
I 1/n + 10 = O(1)
I log(n) + n = O(n)
I n log(n) + n = O(n log(n))
I 1.01n + n1000 = O(1.01n)
I 1.011.01n + 1.01n = O(1.011.01n)
19 / 21
![Page 42: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/42.jpg)
Asymptotics (Big-O) Review
Definition
The notationg(n) = O(f(n))
means “for all large n, g(n) ≤ cf(n) for some constant c > 0”.
Examples:
I 20n + 5 = O(n)
I n2 + 200n = O(n2)
I 1/n + 10 = O(1)
I log(n) + n = O(n)
I n log(n) + n = O(n log(n))
I 1.01n + n1000 = O(1.01n)
I 1.011.01n + 1.01n = O(1.011.01n)
19 / 21
![Page 43: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/43.jpg)
Asymptotics (Big-O) Review
Use Case in Computer Science
I “Runtime of algorithm is O(n)” means that: “in worst case,algorithm requires O(n) operations.”
I In this course, n is typically the size of a dataset.
Why is this important?
I It’s an indicator for the scalability of an algorithm.
I We can only apply O(2n) algorithms to tiny datasets.
I We can apply O(n2) algorithms to medium-sized dataset.
I We can apply O(nd) algorithms if one of n or d ismedium-sized.
I We can apply O(n) algorithms to huge datasets.
20 / 21
![Page 44: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/44.jpg)
Asymptotics (Big-O) Review
Use Case in Computer Science
I “Runtime of algorithm is O(n)” means that: “in worst case,algorithm requires O(n) operations.”
I In this course, n is typically the size of a dataset.
Why is this important?
I It’s an indicator for the scalability of an algorithm.
I We can only apply O(2n) algorithms to tiny datasets.
I We can apply O(n2) algorithms to medium-sized dataset.
I We can apply O(nd) algorithms if one of n or d ismedium-sized.
I We can apply O(n) algorithms to huge datasets.
20 / 21
![Page 45: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/45.jpg)
Asymptotics (Big-O) Review
Decision Tree Example
Suppose we have a dataset of n samples and d features.
I Classifying a single sample in depth-m decision tree: O(m)– You do a constant number of operations at each depth.– Note: no dependence on dimension d.
I Fitting a decision stump with n objects and d features:– O(n2d) if computing each score costs O(n).
I Fitting a decision tree of depth m:– Nave analysis: O(2m) stumps, so O(2mn2d).– But each object appears once at each depth: O(mn2d).
I Finding optimal decision tree:– NP-Complete.– Hence why we approximate by using a greedy fitting algorithm.
21 / 21
![Page 46: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/46.jpg)
Asymptotics (Big-O) Review
Decision Tree Example
Suppose we have a dataset of n samples and d features.
I Classifying a single sample in depth-m decision tree: O(m)– You do a constant number of operations at each depth.– Note: no dependence on dimension d.
I Fitting a decision stump with n objects and d features:– O(n2d) if computing each score costs O(n).
I Fitting a decision tree of depth m:– Nave analysis: O(2m) stumps, so O(2mn2d).– But each object appears once at each depth: O(mn2d).
I Finding optimal decision tree:– NP-Complete.– Hence why we approximate by using a greedy fitting algorithm.
21 / 21
![Page 47: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/47.jpg)
Asymptotics (Big-O) Review
Decision Tree Example
Suppose we have a dataset of n samples and d features.
I Classifying a single sample in depth-m decision tree: O(m)– You do a constant number of operations at each depth.– Note: no dependence on dimension d.
I Fitting a decision stump with n objects and d features:– O(n2d) if computing each score costs O(n).
I Fitting a decision tree of depth m:– Nave analysis: O(2m) stumps, so O(2mn2d).– But each object appears once at each depth: O(mn2d).
I Finding optimal decision tree:– NP-Complete.– Hence why we approximate by using a greedy fitting algorithm.
21 / 21
![Page 48: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/48.jpg)
Asymptotics (Big-O) Review
Decision Tree Example
Suppose we have a dataset of n samples and d features.
I Classifying a single sample in depth-m decision tree: O(m)– You do a constant number of operations at each depth.– Note: no dependence on dimension d.
I Fitting a decision stump with n objects and d features:– O(n2d) if computing each score costs O(n).
I Fitting a decision tree of depth m:– Nave analysis: O(2m) stumps, so O(2mn2d).– But each object appears once at each depth: O(mn2d).
I Finding optimal decision tree:– NP-Complete.– Hence why we approximate by using a greedy fitting algorithm.
21 / 21
![Page 49: Tutorial 1 - University of British Columbiaschmidtm/Courses/340-F16/T1.pdfTutorial 1 1/21 Overview Linear Algebra Notation MATLAB Data Types Data Visualization Probability Review Exercises](https://reader034.vdocuments.net/reader034/viewer/2022042417/5f328e0168aca31a4023dad4/html5/thumbnails/49.jpg)
Asymptotics (Big-O) Review
Decision Tree Example
Suppose we have a dataset of n samples and d features.
I Classifying a single sample in depth-m decision tree: O(m)– You do a constant number of operations at each depth.– Note: no dependence on dimension d.
I Fitting a decision stump with n objects and d features:– O(n2d) if computing each score costs O(n).
I Fitting a decision tree of depth m:– Nave analysis: O(2m) stumps, so O(2mn2d).– But each object appears once at each depth: O(mn2d).
I Finding optimal decision tree:– NP-Complete.– Hence why we approximate by using a greedy fitting algorithm.
21 / 21