svc预测概率_为什么预测概率函数sklearn.svm.svc给出概率是否大于1?

我有一个sklearn.svm.svc(RBF核)模型训练在两个类上,每个类包含140个样本。当我试图预测时,概率设置为true,这两个类的预测概率是不同的。在对于某些测试样本,它给出的概率大于1

其他不到一个

例如:“样品1”:1.55478334,“样品2”:

0.999984)。

在某些情况下,它给出的两个概率都小于1

例如

(“样品-1”:0.418229494776875,“样品-2”:

0.58177035052223113)。

我的代码如下:#Training code

tcdf512_d1=np.empty(280,(18)),dtype=float)

lables=np.empty((0))

model512_d1=SVC(probability=True)

for img,img2 in map(None,catA,catB):

if img!=None:

tcdf512_d1[k]=img(18 features i.e. skewness,variance, standard deviation etc)

k+=1

lables=np.append(lables,'Cat-VI')

pass

if img2!=None:

tcdf512_d1[k]=img2(18 features i.e. skewness,variance, standard deviation etc)

k+=1

lables=np.append(lables,'Cat-VII')

pass

if k%50==0:

print (k)

print ("LBP Calculated")

print (time.strftime('%d/%m/%Y %H:%M:%S'))

model512_d1.fit(tcdf512_d1,lables)

tcdf512_d1=None

lables=None

k=None

print ("Model Trained")

print (time.strftime('%d/%m/%Y %H:%M:%S'))

joblib.dump(model512_d1,"Cat/momentsCat_6-7_128_d1.pkl",compress=3)

print ("Model Saved")

print (time.strftime('%d/%m/%Y %H:%M:%S'))

model512_d1=None

#Testing Code

size=128

Cat_I_II = joblib.load("Cat/momentsCat_6-7_128_d1.pkl")

name1="VII"

print (name1)

images_address="Catagory/Testbg/"+name1+"/"

name1="Cat-"+str(name1)

test_images = cvutils.imlist(images_address)

count =images_address.rfind("/")+1

results1=[]

print (len(test_images))

print ("Start Time ")

print (time.strftime('%d/%m/%Y %H:%M:%S'))

j=float(len(test_images))

k=0

# testdata=[]

for img3 in test_images:

results1.append("Image : "+str(img3[count:]))

results1.append("\n")

varientarray=[]

array=[]

array.append(img3(18 features i.e. skewness,variance, standard deviation etc))

print array

prediction = Cat_I_II.predict(array)[0]

prob=Cat_I_II.predict_proba(array)[0]

prob_per_class_dictionary = dict(zip(Cat_I_II.classes_, prob))

print(prediction,prob_per_class_dictionary)

results1.append("Result of Cat_I_II is : "+str(prediction) +"\t"+str(prob_per_class_dictionary))

varientarray.append(prediction)

print (k)

print ("Final Result of image "+str(i[count:]) + " is : "+str(collections.Counter(varientarray).most_common(1)[0][0]))

results1.append("Final Result of image "+str(i[count:]) + " is : "+str(collections.Counter(varientarray).most_common(1)[0][0]))

if str(i[count:i.index('0')])==collections.Counter(varientarray).most_common(1)[0][0]:

j-=1

gc.collect()

k+=1

k=float(j*100/len(test_images))

Accuracy=float((len(test_images)-j)*100/len(test_images))

print (j)

print (k)

print (Accuracy)

with open("CatResults/_Finalresults.txt", 'a') as f:

f.write(str("The accuracy for "+str(name1)+" is :"+str(Accuracy)) +"\n")

results1.append("Incorrect Results are :"+str(j))

results1.append("The percentage of incorrect result is :"+str(k))

results1.append("The accuracy is :"+str(Accuracy))

with open("CatResults/Cat-"+str(name1)+"resultsp2.txt", 'w') as f:

for s in results1:

f.write(str(s) +"\n")

print ("End Time")

print(time.strftime('%d/%m/%Y %H:%M:%S'))

我的结果片段如下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值