在CvSVM中获取权重,这是OpenCV的SVM实现

我在iOS上使用OpenCV(基于LibSVM)的SVM实现。 训练后可以获得重量矢量吗?

谢谢!

处理完之后我就能获得重量。 为了获得权重,首先必须获得支持向量,然后将它们乘以α值。

// get the svm weights by multiplying the support vectors by the alpha values int numSupportVectors = SVM.get_support_vector_count(); const float *supportVector; const CvSVMDecisionFunc *dec = SVM.decision_func; svmWeights = (float *) calloc((numOfFeatures+1),sizeof(float)); for (int i = 0; i < numSupportVectors; ++i) { float alpha = *(dec[0].alpha + i); supportVector = SVM.get_support_vector(i); for(int j=0;j 

这里唯一的技巧是实例变量float *decision_function在opencv框架上受到保护,所以我必须更改它才能访问它。

粗略地浏览文档和源代码( https://github.com/Itseez/opencv/blob/master/modules/ml/src/svm.cpp )告诉我,表面上答案是“否”。 超平面参数似乎隐藏在CvSVMSolver类中。 CvSVM包含一个名为“solver”的类的对象。 看看你是否可以找到它的成员。

Interesting Posts