cjlin1 / libsvm

LIBSVM -- A Library for Support Vector Machines
https://www.csie.ntu.edu.tw/~cjlin/libsvm/
BSD 3-Clause "New" or "Revised" License
4.54k stars 1.64k forks source link

AttributeError: 'float' object has no attribute 'get_svm_type' #131

Closed YHSot976 closed 5 years ago

YHSot976 commented 5 years ago

I'm having problems running k-fold cross validation in python. It gave me an error like in the title. I have no issue running without cross validation. I'm not sure why -v could influence -s parameter. And even if I'm not assigning -s and using the default value, I'm still getting get_svm_type() error. So I don't know what's wrong with my code. My model is like

prob = svm_problem(y, x)
m = svm_train(prob, '-s 0 -t 0 -c 1 -v 2')
svm_predict(y, x, m).

I didn't find any questions related to this issue. Maybe I totally missed something. Any help would be appreciated.

YHSot976 commented 5 years ago

I think I find the problem. Just like what is said in the comment:

If '-v' is specified in 'options' (i.e., cross validation) either accuracy (ACC) or mean-squared error (MSE) is returned.

So if -v is in svm_train(), then you won't get a model but ACC or MSE. That's why it's float and there is nothing about svm_type. So don't pass m to svm_predict() if you have -v in the options.

I'll just leave it here if anyone has this problem.