Commit 367807d1 authored by Imène Lajili's avatar Imène Lajili

fix isotonic calibration

parent 248893a4
......@@ -152,14 +152,16 @@ def scikitAlgorithms_buildcalibration(input_dict):
o=[]
cal_scrs=[]
data=input_dict['scores_non_calibrated']
print data
#print data
sample=[]
print sample
#print sample
data[0].pop(0)
data[1].pop(0)
print data[1]
print data[0]
#print data[1]
X=np.array(data[0]).tolist()
Y=np.array(data[1]).tolist()
print X
Y=map(float,Y)
for i in X:
o.append(map(float,i))
......@@ -174,7 +176,7 @@ def scikitAlgorithms_buildcalibration(input_dict):
Z.append(f[0])
else:
Z.append(f[1])
print cal_scrs
#print cal_scrs
if k==2:
......@@ -198,6 +200,7 @@ def scikitAlgorithms_buildcalibration(input_dict):
def scikitAlgorithms_applycalibration(input_dict):
from sklearn.isotonic import IsotonicRegression
import numpy as np
import math
data=input_dict['scores']
X1= data['calibrated_scr']
X2=data['noncalibrated_scr']
......@@ -206,18 +209,8 @@ def scikitAlgorithms_applycalibration(input_dict):
list_scr=[]
Z=[]
k=data['num']
probs=[]
if k==1:
'''g=[]
X3=np.array(test_data)
for i in X3:
l=np.array([i])
g.append([i])
#print X3
z=np.array(g)
print z
e=[[ 0.894716 ],[ 0.98022386],[ 0.98973195],[ 0.96723734],[ 0.9863104 ],[ 0.99200249],[ 0.95255941]]
for u in e:
print model.predict_proba(0.894716)'''
test_data=input_dict['test_scores']
test_data[0].pop(0)
test_data[1].pop(0)
......@@ -230,8 +223,8 @@ def scikitAlgorithms_applycalibration(input_dict):
Y=map(float,Y)
for i in X:
o.append(map(float,i))
print o
print Y
#print o
#print Y
m=model.fit(o,Y)
for n in o:
a= model.predict_proba(n)
......@@ -244,7 +237,7 @@ def scikitAlgorithms_applycalibration(input_dict):
test_cls=Y
for h in o:
list_scr.append(h[0])
print type(list_scr)
if k==2:
test_scr=input_dict['test_scores']
......@@ -263,8 +256,6 @@ def scikitAlgorithms_applycalibration(input_dict):
end_score.append(X2[i])
i+=1
end_score.append(X2[size(X2)-1])
#print begin_score
#print end_score
max=0
i=0
aux =True
......@@ -274,29 +265,31 @@ def scikitAlgorithms_applycalibration(input_dict):
if (j>max):
list_max.append(j)
max=j
#print list_max
srrr=0.9261
for i in range(len(list_max)-1):
if srrr>=list_max[i] and srrr<=list_max[i+1]:
print list_max[i]
print list_max[i+1]
print begin_score[i]
print end_score[i]
scr1=(srrr-begin_score[i])/(end_score[i]-begin_score[i])
scr22=list_max[i]+((list_max[i+1]-list_max[i])*scr1)
print scr22
for scr in test_scr['predicted']:
for i in range(len(list_max)-1):
if scr >=list_max[i] and scr<=list_max[i+1]:
#print scr
#print list_max[i]
#print list_max[i+1]
val1=((end_score[i]-begin_score[i])/scr-begin_score[i])
scr2=list_max[i]+((list_max[i+1]-list_max[i])*val1)
list_scr.append(scr2)
print list_scr
for i in range(len(begin_score)):
if (scr >=begin_score[i] and scr<=end_score[i])or(scr==begin_score[i])or(scr==end_score[i]):
scr2=list_max[i]
if scr2==0:
scr2=0.1
elif scr2==1:
scr2=0.98
list_scr.append(scr2)
elif scr>end_score[i]and scr<begin_score[i+1]:
val1=(scr-begin_score[i])/(end_score[i]-begin_score[i])
scr2 = list_max[i]+((list_max[i+1]-list_max[i])*val1)
if scr2==0:
scr2=0.1
elif scr2==1.0:
scr2=0.98
list_scr.append(scr2)
for j in list_scr:
probs.append(math.log10(j/(1-j)))
output_dict={}
output_dict['calibrated_scores']= {'actual':test_cls , 'predicted':list_scr}
output_dict['calibrated_scores']= {'actual':test_cls , 'predicted':probs}
return output_dict
#
# CLUSTERING
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment