[Assignment Requirements]
Write a program to detect whether a person in a video speaks or not.
Features:
- S: Depicts the motion of mouth;
- V: Depicts the degree of mouth opening.
Feature vector:
- X = [Si-1 Si Si+1 Vi-1 Vi Vi+1]
So that, the input feature vector X is an N*6 matrix, where N is the number of feature vectors.
- X = [Si-1 Si Si+1 Vi-1 Vi Vi+1]
Label:
+1: Speaking
-1: Not-speaking
So that, the output label vector is an N*1 vector predY, predY(i)=-1 or 1.
[Solutions]
SVM
使用Scikit-learn,即sklearn,一个Python的机器学习包。
对于SVM问题,我们可以调用sklearn包中基于libsvm的svm模块。对于本次任务中的分类问题,我们调用其中的SVC函数(针对回归问题,可以调用SVR函数)。
任务实现的主要步骤为:
数据预处理-加载数据集-训练模型(网格搜索参数)-测试模型数据预处理
原数据集training.data格式为:
我们通过FormatDatalibsvm.xls,按照
http://blog.youkuaiyun.com/pangpang1239/article/details/7435842
中所说的方式将数据处理为libsvm要求的格式,得到training.txt:
加载数据集
获得特征向量xData和标签向量yData:
xData, yData = datasets.load_svmlight_file(“training.txt”)我们再在数据中留出一部分验证集:
traini