第七周 支持向量机SVM - Lecture 12
- 逻辑回归(logistic regression)的优化:
逻辑回归代价函数(Cost Function)
Alternative view of logistic regression
- 支持向量机SVM
- 逻辑回归(Logistic regression)
其中: - 支持向量机(Support vector machine)
image.png
if y = 1, we want逻辑回归是>0
if y = 0, we want逻辑回归是<0
决策边界(Decision Boundary)
whenever:
whenever:
Large margin classifier
Large margin classifier
- SVM with kernels
给定一组训练集:
选择:
根据给定的训练集x,计算
...
是一个m+1的向量;
算法描述:给定一个训练集x, 计算出f特征向量
如果 预测"y=1"
训练以下:
5.支持向量机的参数(SVM parameters):
-
.
-- 更大的C: 低偏差(lower bias), 过拟合(hight variance).
-- 更小的C: 高偏差(Higher bias),欠拟合 (low variance).
-
-- 更大的:
更平滑(vary more smoothly). 高偏差(Higher bias),欠拟合 (low variance)..
-- 更小的:
更陡峭(vary less smoothly). 低偏差(lower bias), 过拟合(hight variance).
如下图所示:
image.png
- 如何使用支持向量机(Using an SVM)
不需要要向前面说的自己实现算法,已经有成熟的软件包(例如liblinear, libsvm, ...)直接计算出.
软件包需要确定以下参数:
- 选择参数C.
- 选择核函数(Choice of kernel(similarity function))
例如:无核函数l("linear kernel")
当时,预测"y=1"
高斯核函数(Gaussian kernel):
Need to choose
核函数Kernel(simliarity) functions:
Kernel(similarity) functions:
function f = kernel(x1, x2)
f = exp(-(||x1-x2||^2/(2*sigma^2))
return
\\ Do perform feature scaling before using the Gaussian kernel
\\使用 Gaussian kernel前必须归一化
- 逻辑回归vs.支持向量机(Logistic regression vs. SVMs)
n为特性个数(,m为训练集的数量
n = number of features(m = number of training examples
- 如果n相对m来说很大: (例如. n>m . n = 10,000 m=10...,000)
使用逻辑回归或支持无核的向量机
Use logistic regression, or SVM without a kernel("linear kernel") - 如果n很小,m中等: (例如 n = 10,000 m=10-10,000)
使用 SVM with Gaussian kernel - 如果n很小,m很大: (例如. n = 1,000 m=50,000)
创建新的特性,再使用逻辑回归
Create/add more features, then use logistic regression or SVM without a kernel - Neural network likely to work well for most of these settings, but may be slower to train.
网友评论