注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
Machine Learning:Computer learns from experience E task T and performance P; If P improves with E in task T
I. Linear Regression
1. Cost Function. .и
Sum of square error
Optimization method: gradient descent, repeat until it converges.. 1point3acres.com
It’s a convex function, local min value is global min value
Choose learning rate: too small, converge too slow; too large, it may not converge
Feature scaling can help converge faster. check 1point3acres for more.
2. L1 norm: absolute error – unstable solution, may have multiple solutions, built-in feature selection
L2 norm: square error – stable solution; has analytical solution
3. Assumption
1) Linearity; Check: scatter /residual plot; solution: Exponential/log transform
2) Constant variance for error; Check: residual plot; solution: log transform
3) No autocorrelation; Check: residual plot against time; solution: time series . 1point 3 acres
4) No multicollinearity; Check: correlation matrix(heatmap);solution: combine/PCA . Χ
II. Logistic regression
1. Function
H(x) = g(ΘX)
g(z) = 1/(1+e^(-z))
g(z) Graph:
2. Decision boundary. .и
Define y=1 if H(x)>0.5/z>0 and y=0 if H(x)<0.5/z<0
Decision boundary is 0.5
3. Cost function
Can’t use same cost function as linear regression; it’s not convex for logistic regression, it has multiple local minimums; hard to find the global minimum
-y*log(h(x)) – (1-y)*log(1-h(x))
Use maximum likelihood estimate to optimize the cost function
MLE:
Find the parameter by maximizing the likelihood to make the observations.
4. Confusion matrix
Table to measure results from logistic regression.
1) Accuracy
(TP + TN)/Total #
Not good for imbalance data-baidu 1point3acres
2) Type I error: FP; P-value is probability of type I error: probability of rejecting the null hypothesis while the null is actually true
Type II error: FN
3) Precision: TP/(FP + TP); Positive relation with threshold. .и
Recall: TP/(TP+FN); Negative relation with threshold. 1point3acres.com
We care about precision or recall for different test;
Eg: for cancer detection, we care more about recall rate, we don’t want to tell the patient that he doesn’t have cancer but actually he has cancer.
F score: 2*Precision*Recall/(Precision+Recall)
4) TP rate (Power/1-TypeII error): TP/(TP+FN)
FP rate(TypeI error): FP/(FP+TN).google и
ROC AUC: . ----
plotting TPR against the FPR at various threshold settings, find the curve maximize the AUC (area under curve). ----
III. Bias(underfit) & variance(overfit)
1. Fix variance
1) Try fewer parameters
Introduce regularization parameter in cost function.google и
Ridge: sum of square of parameters; Reduce the magnitude of parameters
Lasso: sum of absolute of parameters; can remove parameters. check 1point3acres for more.
2) Increase λ in regularization . 1point 3 acres
3) Increase training examples
4) Early stop for tree based model. Waral dи,
2. Fix bias.1point3acres
1) Increase model complexity: add more parameter, try polynomial features
2) Decrease λ in regularization
IV. SVM (support vector machine)
1. Find a hyperplane/gap that separates the classes by maximizing the margin
2. Use kernel for non-linear: transfer data into another dimension that has a clear margin between classes
3. SVM V.S. Logistic regression
SVM maximize the margin, LR maximize the likelihood function
SVM predict 0/1, LR predict a probability
V. Unsupervised learning
1. Clustering (K-means)
The process to find K clusters
1) Randomly pick K cluster centroids-baidu 1point3acres
2) Index each data to the closest cluster centroids
3) Reassign cluster centroids as the average of each cluster
4) Repeat 2) and 3) until the clusters centroids don’t change. From 1point 3acres bbs
May reach local optimal if the initial K cluster centroids chosen not good. Waral dи,
Use “Elbow method” to pick the best number of clusters
2. PCA (Principal component analysis)
Reduce the parameter dimension; project n-dimension to k-dimension; will lose information during the process
3. Anomaly detection
Assume all features following normal distribution
Anomaly detection V.S. surprised learning
Anomaly detection if unlabeled data, future anomaly data look nothing like current anomaly data;
Surprised learning if large # of data; enough historical anomaly data and covers most cases
VI. Other Algorithm
1. Naïve Bayes-baidu 1point3acres
Assumption: X are independent of each other for the given Y
2. Tree-based Method
1) Construct tree: top-down/greedy approach; at each step, minimize the RSS error rate; stop until criteria meet(eg: # of observation, node)
2) It will grow a big tree, possible overfit issue; Solution: select subset tree using cross-validation
3) Easy to explain BUT non-robust, overfitting issue: small data change leads to model change
3. Random Forest. .и
Fix the overfitting issue with basic tree method. 1point 3acres
Randomly with replacement pick data, instead of using all features, randomly use square root features at each step; Average results of all trees
4. Boosting
Each tree is fit on a modified version of the previous tree;
STEPS:. Χ
Randomly with replacement pick data, build a model, validate on the data and calculate the RSS error rate; for the next tree, put higher weight for the data with higher error in previous model.
To avoid overfitting: don’t construct too many trees, use small learning rate, use small node(less complex tree) ..
|