在进行svm训练的时候,会有一个参数 svm_scaling scaling,该参数实现对数据的归一化操作,在A Practical Guide to Support Vector Classification一文中有介绍,https://www.csie.ntu.edu.tw/~cjlin/papers/guide/guide.pdf,下面是对数据缩放以及加载(训练数据和测试数据进行同样的缩放)的源码实现进行汇总
//svm_wrapper.cpp
//生成缩放因子
void
pcl::SVMTrain::scaleFactors (std::vector<SVMData> training_set, svm_scaling &scaling)
{
int max = 0;
for (size_t i = 0; i < training_set.size() ; i++)
for (size_t j = 0; j < training_set[i].SV.size() ; j++)
if (training_set[i].SV[j].idx > max)
max = training_set[i].SV[j].idx; // max number of features
max += 1;
scaling.obj = Malloc (struct svm_node, max + 1);
scaling.max = max;
scaling.obj[max].index = -1; // last index is -1
for (int i &#