Lec 1. Intro
Mean, Std and Var
Mean (np.mean()
)
\mathrm{mean}(\{x_i\}) = \frac{1}{N} \sum_{i=1}^N x_i$
Standard deviation (np.std()
)
std({xi})=N−11i=1∑N(xi−mean({xi}))2
Variance
var({xi})=N−11i=1∑N(xi−mean({xi}))2=std({xi})2
Standardizing data: 使平均数为0,标准差为1
Median: 50th percentile 中位数
Interquartile range: 中间50%的值范围,即 (75th percentile) - (25th percentile)
Correlation coefficient 相关系数
给定数据集 {(x,y)}, 先将 {x} 和 {y} 分别标准化,则
corr({(x,y})=N−11i=1∑Nxi^yi^
np.corrcoef()
, pd.corr()
相关系数取值范围为 [−1,1]
positive correlation, negative correlation, zero correlation
Lec 2. Probability
Outcome: a possible result of a random experiment
Sample space Ω: the set of all possible outcomes
Event: an event E is a subset of the sample space Ω
Probability function: any function P that maps events to real numbers and satisfies:
- P(E)≥0
- P(Ω)=1
- Probability of disjoint events is additive: P(E1∪E2∪⋯∪EN)=∑i=1NP(Ei) if Ei∩Ej=∅ for all i=j
Independence: 当且仅当以下条件时,两个event独立
Conditional Probability 条件概率
Bayes Rule 贝叶斯公式
P(E2∣E1)=P(E1)P(E1∣E2)P(E2)
Total Probability 全概率公式
P(E1)=P(E1∩E2)+P(E1∩E2c)=P(E1∣E2)P(E2)+P(E1∣E2c)P(E2c)
Conditional Independence 条件独立
P(E1∩E2∣A)=P(E1∣A)P(E2∣A)
Random Variable: a random variable is a function that maps outcomes to real numbers.
Probability distribution: P(X=x) is called the probability distribution of X. Also denoted as P(x) or p(x).
Joint probability distribution: P({X=x}∩{Y=y}), also denoted as P(x,y) or p(x,y)
Independence of random variables: 如果随机变量 X, Y 满足以下条件,则独立: P(x,y)=P(x)P(y) for all x and y
Conditional probability distribution:
P(x∣y)=P(y)P(x,y)
Bayes rule
P(x∣y)=P(y)P(y∣x)P(x)=∑xP(y∣x)P(x)P(y∣x)P(x)
Expected value of a random variable 期望
E[X]=x∑xP(x)
Variance of a random variable
var[X]=E[(X−E[X])2]
Standard deviation of a random variable
std[X]=var[X]
Useful probability distributions
Bernoulli distribution
- P(X=1)=p, P(X=0)=1−p
- E[X]=p
- var[X]=p(1−p)
Dinomial distribution
- P(X=k)=(kN)pk(1−p)N−k for integer 0≤k≤N
- E[X]=Np
- var[X]=Np(1−p)
Multinomial distribution
P(X1=n1,X2=n2,…,Xk=nk)=n1!n2!…nk!N!p1n1p2n2…pknk
where N=n1+n2+⋯+nk
Poisson distribution
A discrete random variable X is poisson with intensity λ if
P(X=k)=k!e−λλk
for integer k≥0
E[X]=λ
var[X]=λ
Lec 3. Classification and Naive Bayes
Binary classifier
Multiclass classifier
Nearest neighbors classifier
- variants: k-nearest neighbors, (k,l)-nearest neighbors (找k个最近的点的label,如果至少l个同意则给label)
Performance of a binary classifier
- false positive (truth is negative, but classifier assigns positive), false negative (the other way)
- class confusion matrix: 2x2的矩阵,True Positive (TP), FN, FP, TN
Cross-validation: 分成训练集和测试集
Naive Bayes classifier: a probabilistic method:
- Training: 使用训练数据 {(xi,yi)} 估计概率模型 P(y∣x)
- Classification: 给定feature vector x, 预测 label = argmaxyP(y∣x)
- Naive bayes assumption: 给定 class label y 时 x 条件独立
Lec 4. Adversarial Spam Filtering