In [6]:
#Note Remove This Line to Get the Figure in Seperate Window\n",
#%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import itertools
from math import sqrt,pow
np.random.seed(4)

In [7]:
class AllNeeded:
    def __init__(self,value):
        self.f11=float(value[0])
        self.f10=float(value[1])
        self.f01=float(value[2])
        self.f00=float(value[3])
        self.f1plus= self.f11+self.f10
        self.f0plus= self.f01+self.f00
        self.fplus1= self.f11+self.f01
        self.fplus0=self.f10+self.f00
        self.N =float(sum(value))
        self.all_confidence = min(self.f11/self.f1plus,self.f11/self.fplus1)
        self.kappa = (self.N*self.f11+ self.N*self.f00-self.f1plus*self.fplus1-self.f0plus*self.fplus0)/(pow(self.N,2)-self.f1plus*self.fplus1-self.f0plus*self.fplus0)
        self.interest =(self.N*self.f11)/(self.f1plus*self.fplus1)
        self.cosine= (self.f11)/(sqrt(self.f1plus*self.fplus1))
        self.Jaccard = self.f11/(self.f1plus+self.fplus1-self.f11)
        #Upgrade for Question Three (5 more measurements )
        self.laplace = (self.f11+1)/(self.f1plus+2)
        self.conviction = (self.f1plus*self.fplus0)/self.isZero(self.N*self.f10)
        self.certinfactor=(self.f11/self.N - self.fplus1/self.N)/(1-(self.fplus1/self.N))
    
    def isZero(self,value):
        return 1 if value==0 else value
    def __str__(self):
        return 'f11:{},f10:{},f01:{},f00:{},f1+:{},f0+:{},f+1:{},f+0:{}'.format(self.f11,self.f10,self.f01,
                                                                        self.f00,self.f1plus,self.f0plus,
                                                                        self.fplus1,self.fplus0)

To generate 4 numbers sum to 10000 I used

Create the array

#result =np.random.dirichlet(np.ones(4),size=1)

multilply with 10,000 (so The sum is 10,000)

#result = result *10000

Convert the array to type int

result =np.array( result,dtype=int)

add 2 to one of the array elements to recover the loset precesion

result[0,np.random.randint(4)]+=2

In [8]:
lst = []
total =np.array(np.random.dirichlet(np.ones(4),size=10000)*10000,dtype=int)
for result in total:
    result[np.random.randint(4,size=1)]+=(10000-np.sum(result))
    lst.append(AllNeeded(result))

In [9]:
allconf = sorted(lst,key=lambda x:x.all_confidence,reverse=True)[:10]
print '=========All Confidence=============='
for element in allconf:
    print element,',all_confidence :',element.all_confidence

print '========= kappa =============='
allconf = sorted(lst,key=lambda x:x.kappa,reverse=True)[:10]
for element in allconf:
    print element,',kappa :',element.kappa
print '========= interest =============='
allconf = sorted(lst,key=lambda x:x.interest,reverse=True)[:10]
for element in allconf:
    print element,',interest :',element.interest
print '========= cosine =============='
allconf = sorted(lst,key=lambda x:x.cosine,reverse=True)[:10]
for element in allconf:
    print element,',cosine :',element.cosine
print '========= Jaccard =============='
allconf = sorted(lst,key=lambda x:x.Jaccard,reverse=True)[:10]
for element in allconf:
    print element,',Jaccard :',element.Jaccard


=========All Confidence==============
f11:9726.0,f10:15.0,f01:26.0,f00:233.0,f1+:9741.0,f0+:259.0,f+1:9752.0,f+0:248.0 ,all_confidence : 0.99733388023
f11:8966.0,f10:51.0,f01:38.0,f00:945.0,f1+:9017.0,f0+:983.0,f+1:9004.0,f+0:996.0 ,all_confidence : 0.994344016857
f11:8078.0,f10:52.0,f01:39.0,f00:1831.0,f1+:8130.0,f0+:1870.0,f+1:8117.0,f+0:1883.0 ,all_confidence : 0.993603936039
f11:5919.0,f10:43.0,f01:23.0,f00:4015.0,f1+:5962.0,f0+:4038.0,f+1:5942.0,f+0:4058.0 ,all_confidence : 0.992787655149
f11:8589.0,f10:56.0,f01:73.0,f00:1282.0,f1+:8645.0,f0+:1355.0,f+1:8662.0,f+0:1338.0 ,all_confidence : 0.99157238513
f11:8738.0,f10:7.0,f01:79.0,f00:1176.0,f1+:8745.0,f0+:1255.0,f+1:8817.0,f+0:1183.0 ,all_confidence : 0.991040036294
f11:6254.0,f10:68.0,f01:62.0,f00:3616.0,f1+:6322.0,f0+:3678.0,f+1:6316.0,f+0:3684.0 ,all_confidence : 0.989243910155
f11:8116.0,f10:92.0,f01:36.0,f00:1756.0,f1+:8208.0,f0+:1792.0,f+1:8152.0,f+0:1848.0 ,all_confidence : 0.988791423002
f11:5230.0,f10:67.0,f01:6.0,f00:4697.0,f1+:5297.0,f0+:4703.0,f+1:5236.0,f+0:4764.0 ,all_confidence : 0.987351330942
f11:1834.0,f10:5.0,f01:25.0,f00:8136.0,f1+:1839.0,f0+:8161.0,f+1:1859.0,f+0:8141.0 ,all_confidence : 0.986551909629
========= kappa ==============
f11:1834.0,f10:5.0,f01:25.0,f00:8136.0,f1+:1839.0,f0+:8161.0,f+1:1859.0,f+0:8141.0 ,kappa : 0.9900473078
f11:5919.0,f10:43.0,f01:23.0,f00:4015.0,f1+:5962.0,f0+:4038.0,f+1:5942.0,f+0:4058.0 ,kappa : 0.986303528095
f11:5230.0,f10:67.0,f01:6.0,f00:4697.0,f1+:5297.0,f0+:4703.0,f+1:5236.0,f+0:4764.0 ,kappa : 0.985358951184
f11:3737.0,f10:13.0,f01:70.0,f00:6180.0,f1+:3750.0,f0+:6250.0,f+1:3807.0,f+0:6193.0 ,kappa : 0.982346998458
f11:6519.0,f10:2.0,f01:96.0,f00:3383.0,f1+:6521.0,f0+:3479.0,f+1:6615.0,f+0:3385.0 ,kappa : 0.978264326637
f11:1491.0,f10:20.0,f01:47.0,f00:8442.0,f1+:1511.0,f0+:8489.0,f+1:1538.0,f+0:8462.0 ,kappa : 0.974073378685
f11:6254.0,f10:68.0,f01:62.0,f00:3616.0,f1+:6322.0,f0+:3678.0,f+1:6316.0,f+0:3684.0 ,kappa : 0.972055328043
f11:8078.0,f10:52.0,f01:39.0,f00:1831.0,f1+:8130.0,f0+:1870.0,f+1:8117.0,f+0:1883.0 ,kappa : 0.97015177984
f11:3402.0,f10:46.0,f01:122.0,f00:6430.0,f1+:3448.0,f0+:6552.0,f+1:3524.0,f+0:6476.0 ,kappa : 0.963010664202
f11:3473.0,f10:163.0,f01:9.0,f00:6355.0,f1+:3636.0,f0+:6364.0,f+1:3482.0,f+0:6518.0 ,kappa : 0.962493645726
========= interest ==============
f11:29.0,f10:4.0,f01:396.0,f00:9571.0,f1+:33.0,f0+:9967.0,f+1:425.0,f+0:9575.0 ,interest : 20.6773618538
f11:698.0,f10:32.0,f01:157.0,f00:9113.0,f1+:730.0,f0+:9270.0,f+1:855.0,f+0:9145.0 ,interest : 11.1832091645
f11:80.0,f10:327.0,f01:145.0,f00:9448.0,f1+:407.0,f0+:9593.0,f+1:225.0,f+0:9775.0 ,interest : 8.73600873601
f11:819.0,f10:13.0,f01:316.0,f00:8852.0,f1+:832.0,f0+:9168.0,f+1:1135.0,f+0:8865.0 ,interest : 8.67290748899
f11:1086.0,f10:113.0,f01:13.0,f00:8788.0,f1+:1199.0,f0+:8801.0,f+1:1099.0,f+0:8901.0 ,interest : 8.24162689411
f11:137.0,f10:430.0,f01:159.0,f00:9274.0,f1+:567.0,f0+:9433.0,f+1:296.0,f+0:9704.0 ,interest : 8.16292482959
f11:994.0,f10:135.0,f01:118.0,f00:8753.0,f1+:1129.0,f0+:8871.0,f+1:1112.0,f+0:8888.0 ,interest : 7.91749240112
f11:1051.0,f10:32.0,f01:187.0,f00:8730.0,f1+:1083.0,f0+:8917.0,f+1:1238.0,f+0:8762.0 ,interest : 7.83887275369
f11:447.0,f10:576.0,f01:125.0,f00:8852.0,f1+:1023.0,f0+:8977.0,f+1:572.0,f+0:9428.0 ,interest : 7.6389885774
f11:962.0,f10:129.0,f01:238.0,f00:8671.0,f1+:1091.0,f0+:8909.0,f+1:1200.0,f+0:8800.0 ,interest : 7.34799877788
========= cosine ==============
f11:9726.0,f10:15.0,f01:26.0,f00:233.0,f1+:9741.0,f0+:259.0,f+1:9752.0,f+0:248.0 ,cosine : 0.997896839745
f11:8738.0,f10:7.0,f01:79.0,f00:1176.0,f1+:8745.0,f0+:1255.0,f+1:8817.0,f+0:1183.0 ,cosine : 0.995111426403
f11:8966.0,f10:51.0,f01:38.0,f00:945.0,f1+:9017.0,f0+:983.0,f+1:9004.0,f+0:996.0 ,cosine : 0.995061576262
f11:5919.0,f10:43.0,f01:23.0,f00:4015.0,f1+:5962.0,f0+:4038.0,f+1:5942.0,f+0:4058.0 ,cosine : 0.99445704872
f11:8078.0,f10:52.0,f01:39.0,f00:1831.0,f1+:8130.0,f0+:1870.0,f+1:8117.0,f+0:1883.0 ,cosine : 0.994399284288
f11:5230.0,f10:67.0,f01:6.0,f00:4697.0,f1+:5297.0,f0+:4703.0,f+1:5236.0,f+0:4764.0 ,cosine : 0.993086054833
f11:6519.0,f10:2.0,f01:96.0,f00:3383.0,f1+:6521.0,f0+:3479.0,f+1:6615.0,f+0:3385.0 ,cosine : 0.99256499934
f11:8589.0,f10:56.0,f01:73.0,f00:1282.0,f1+:8645.0,f0+:1355.0,f+1:8662.0,f+0:1338.0 ,cosine : 0.992546847345
f11:8116.0,f10:92.0,f01:36.0,f00:1756.0,f1+:8208.0,f0+:1792.0,f+1:8152.0,f+0:1848.0 ,cosine : 0.992181851741
f11:1834.0,f10:5.0,f01:25.0,f00:8136.0,f1+:1839.0,f0+:8161.0,f+1:1859.0,f+0:8141.0 ,cosine : 0.991902013444
========= Jaccard ==============
f11:9726.0,f10:15.0,f01:26.0,f00:233.0,f1+:9741.0,f0+:259.0,f+1:9752.0,f+0:248.0 ,Jaccard : 0.995802191051
f11:8738.0,f10:7.0,f01:79.0,f00:1176.0,f1+:8745.0,f0+:1255.0,f+1:8817.0,f+0:1183.0 ,Jaccard : 0.990253853128
f11:8966.0,f10:51.0,f01:38.0,f00:945.0,f1+:9017.0,f0+:983.0,f+1:9004.0,f+0:996.0 ,Jaccard : 0.990171176146
f11:5919.0,f10:43.0,f01:23.0,f00:4015.0,f1+:5962.0,f0+:4038.0,f+1:5942.0,f+0:4058.0 ,Jaccard : 0.988972431078
f11:8078.0,f10:52.0,f01:39.0,f00:1831.0,f1+:8130.0,f0+:1870.0,f+1:8117.0,f+0:1883.0 ,Jaccard : 0.988860325621
f11:5230.0,f10:67.0,f01:6.0,f00:4697.0,f1+:5297.0,f0+:4703.0,f+1:5236.0,f+0:4764.0 ,Jaccard : 0.986234207053
f11:8589.0,f10:56.0,f01:73.0,f00:1282.0,f1+:8645.0,f0+:1355.0,f+1:8662.0,f+0:1338.0 ,Jaccard : 0.985203028217
f11:6519.0,f10:2.0,f01:96.0,f00:3383.0,f1+:6521.0,f0+:3479.0,f+1:6615.0,f+0:3385.0 ,Jaccard : 0.985189662989
f11:8116.0,f10:92.0,f01:36.0,f00:1756.0,f1+:8208.0,f0+:1792.0,f+1:8152.0,f+0:1848.0 ,Jaccard : 0.984473556526
f11:1834.0,f10:5.0,f01:25.0,f00:8136.0,f1+:1839.0,f0+:8161.0,f+1:1859.0,f+0:8141.0 ,Jaccard : 0.983905579399

In [10]:
x = range(1000)
y1 = [AllNeeded((i,250,250,250)) for i in x]

In [13]:
labels = []
plotHandles = []
#for i in range(1, num_plots + 1):
t, = plt.plot(x, [y.all_confidence for y in y1]) #need the ',' per ** below
plotHandles.append(t)
labels.append('All Confidence')
t, = plt.plot(x, [y.kappa for y in y1]) #need the ',' per ** below
plotHandles.append(t)
labels.append('kappa')
t, = plt.plot(x, [y.interest for y in y1]) #need the ',' per ** below
plotHandles.append(t)
labels.append('interest')
t, = plt.plot(x, [y.cosine+0.1 for y in y1]) #need the ',' per ** below
plotHandles.append(t)
labels.append('cosine + 0.1')
t, = plt.plot(x, [y.Jaccard for y in y1]) #need the ',' per ** below
plotHandles.append(t)
labels.append('Jaccard')
plt.legend(plotHandles, labels, 'upper left',loc=1)
plt.show()
plt.savefig('f11.png')


<matplotlib.figure.Figure at 0x7f49eaa99590>

In [ ]: