我有一个关于libsvm预测准确性的问题。我使用easy.py生成了svm模型文件。现在,当我试图在python中以编程方式预测测试向量时,它会显示错误预测的标签(全1),而使用easy.py我得到91%的准确度。
我的测试和训练数据的每一行都采用以下格式:
1 1:255 2:246 3:218 4:198 5:186 6:168 7:177 8:218 9:255 10:255 11:255 12:255 13:255 14:255 15:255 16:255 17:255 18:255 19:255 20:255 21:255 22:255 23:255 24:255 25:255 26:219 27:185 28:162 29:145 30:144 31:255 32:253 33:228 34:197
代码如下,我在这做错了吗?
wimn_model = svm.svm_model("newtraindata.txt.model")
#load model
wimn_f_test=open('newtestdata.txt','r');
#load test data and train data
wimn_f_train=open('newtraindata.txt','r');
ii=0
for eachline in wimn_f_test:
vec=eachline
v=vec.split()
vector={}
ii=ii+1
#print v[0]
wimn_test_labels.append(int(v[0]))
for i in range(1,len(v)):
s=v[i].split(":")
#print s[1]
vector[i]=int(s[1])
wimn_test_vectors.append(vector)
print "wimn test "+str(len(wimn_test_vectors))
# get the training and testing vectors and labels.
ii=0
for eachline in wimn_f_train:
vec=eachline
v=vec.split()
vector={}
ii=ii+1
wimn_train_labels.append(int(v[0]))
#print v[0]
for i in range(1,len(v)):
s=v[i].split(":")
#print s[1]
vector[i]=int(s[1])
wimn_train_vectors.append(vector)
print "wimn train "+str( len(wimn_train_vectors))
s=len(wimn_train_labels)
for i_s in range(0,s):
#print i_s
ww.append(wimn_model.predict(wimn_train_vectors[i_s]))
# wrongly predicted labels are in ww. correct labels are in wimn_train_labels, wimn_test_labels.
答案 0 :(得分:0)
需要加载缩放的输入值以获得预测值。问题解决了。
但是,easy.py生成的预测标签与我加载模型和预测标签时的标签之间似乎存在一些不相似之处。
网上没有关于libsvm的适当文档。