Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The best parameter for prob outputs may be different from the setting #153

Open
pango99 opened this issue Sep 27, 2019 · 0 comments
Open

Comments

@pango99
Copy link

pango99 commented Sep 27, 2019

The best parameter for prob outputs may be different from the setting
without..
See also the following faq

Q: Why using svm-predict -b 0 and -b 1 gives different accuracy values?

Let's just consider two-class classification here. After probability
information is obtained in training, we do not have

prob > = 0.5 if and only if decision value >= 0.

So predictions may be different with -b 0 and 1.

On 2019-09-27 01:22, Zheng Li wrote:

Hi, I use libSVM to develop my face recognition system,I use the
libSVM to find the closet face feature and identify target person,but
I found when I call svm_predict_probability() to do the prediction,the
accuracy is very low,and when I call svm_predict(), the accuracy is
high,because I need the probability param to check similarity , so I
want to know why svm_predict_probability()'s accuracy is so low?

below is my code to create the svm_model:

inline void fillLibSvmNodes(std::vector &fea, std::vector<svm_node>
&line_x_space)
{
size_t featuresNb = fea.size();
assert((fea.size() + 1) == line_x_space.size());
for (int i = 0; i < featuresNb; i++)
{
line_x_space[i].index = i + 1;
line_x_space[i].value = (double)fea[i];
}
line_x_space[featuresNb].index = -1;
}

void testLibSVM()
{
// dbFaceFeatures is a global variable to store the load face
features, it is vector<pair<string,vector>> type,the face feature is
512D;
assert(dbFaceFeatures.size() > 0);
int featuresNb = (int)dbFaceFeatures[0].second.size(); //
featuresNb=512

memset(&param, 0, sizeof(svm_parameter));
param.svm_type = C_SVC;
param.kernel_type = LINEAR;
param.cache_size = 512;
param.eps = cv::TermCriteria(cv::TermCriteria::MAX_ITER, 20000,
1e-06).epsilon;
param.degree = 0;
param.gamma = 1.0;
param.coef0 = 0;
param.nu = 0;
param.C = 1.0;
param.p = 0;
param.probability = 1; // do probability estimate
param.shrinking = 0;
param.nr_weight = 0;
param.weight = nullptr;
param.weight_label = nullptr;

memset(&prob, 0, sizeof(svm_problem));
prob.l = (int)dbFaceFeatures.size();

y_space.resize(dbFaceFeatures.size()); // y_space is vector
type
prob.y = y_space.data();
for (size_t i = 0; i < y_space.size(); i++)
y_space.at(i) = (double)(i + 1);

prob.x = (svm_node **)malloc(sizeof(svm_node
*)*dbFaceFeatures.size());
x_space.resize(dbFaceFeatures.size()); // x_space is
vector<vector<svm_node>> type
for(int n=0;n<(int)dbFaceFeatures.size();n++)
{
std::vector<svm_node> &line_x_space = x_space.at(n);
line_x_space.resize(featuresNb + 1);
prob.x[n] = line_x_space.data();
fillLibSvmNodes(dbFaceFeatures.at(n).second, line_x_space);
}

const char * err_msg = svm_check_parameter(&prob, &param);
if (err_msg)
{
std::cerr << "svm_check_parameter() fail " << err_msg <<
std::endl;
assert(false);
return;
}
lib_svm = svm_train(&prob, &param);
assert(lib_svm);
int chkRet = svm_check_probability_model(lib_svm);
if(chkRet == 0)
{
std::cerr << "svm_check_probability_model() fail" << std::endl;
assert(false);
return;
}

}

--
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub [1], or mute the
thread [2]. [ { "@context": "http://schema.org", "@type":
"EmailMessage", "potentialAction": { "@type": "ViewAction", "target":
"https://github.com//issues/152?email_source=notifications\u0026email_token=ABI3BHWM3YKIZAE6BTHHJCTQLW7DTA5CNFSM4I3DKNV2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HOC2G3A",
"url":
"https://github.com//issues/152?email_source=notifications\u0026email_token=ABI3BHWM3YKIZAE6BTHHJCTQLW7DTA5CNFSM4I3DKNV2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HOC2G3A",
"name": "View Issue" }, "description": "View this Issue on GitHub",
"publisher": { "@type": "Organization", "name": "GitHub", "url":
"https://github.com" } } ]

Links:

[1]
https://github.com/cjlin1/libsvm/issues/152?email_source=notifications&amp;email_token=ABI3BHWM3YKIZAE6BTHHJCTQLW7DTA5CNFSM4I3DKNV2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HOC2G3A
[2]
https://github.com/notifications/unsubscribe-auth/ABI3BHUFUBG3VCMXEIEHU2DQLW7DTANCNFSM4I3DKNVQ

Originally posted by @cjlin1 in #152 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant