Classification¶

In [1]:
import numpy
import urllib
import scipy.optimize
import random
from sklearn import svm # Library for SVM classification
from sklearn import linear_model # Logistic Regression (among other things)
import ast

In [2]:
def parseData(fname):
for l in urllib.urlopen(fname):
yield eval(l)

In [3]:
def parseDataFromFile(fname):
for l in open(fname):
yield eval(l)

In [4]:
data1 = list(parseDataFromFile("C:/Users/Julian McAuley/Documents/class_files/book_descriptions_50000.json"))

In [5]:
data2 = list(parseDataFromFile("C:/Users/Julian McAuley/Documents/class_files/book_images_5000.json"))

In [6]:
data = data1

In [ ]:


In [7]:
data[2]

Out[7]:
{'asin/ID': '157120315X',
'url': 'http://www.amazon.com/dp/157120315X',
'description': 'quiltmaker magazine one of americas most prestigious quilting publications also created the books paper piecing picnic and paper piecing potpourri',
'categories': ["Children's Books", 'Crafts']}

Priors...

p(label)

In [8]:
prior = ["Children's Books" in d['categories'] for d in data]
prior = sum(prior) / len(prior)

In [9]:
prior

Out[9]:
0.08288
In [10]:
prior_neg = 1 - prior

In [11]:
prior_neg

Out[11]:
0.91712

p(wizard in description | Children's Book)

In [12]:
p1 = ["wizard" in b['description'] for b in data
if "Children's Books" in b['categories']]
p1 = sum(p1) / len(p1)

In [13]:
p1

Out[13]:
0.01085907335907336
In [14]:
p1_neg = ["wizard" in b['description'] for b in data
if not ("Children's Books" in b['categories'])]
p1_neg = sum(p1_neg) / len(p1_neg)

In [15]:
p1_neg

Out[15]:
0.004012561060711794

p(witch in description | Children's Book)

In [16]:
p2 = ["witch" in b['description'] for b in data if "Children's Books" in b['categories']]
p2 = sum(p2) * 1.0 / len(p2)

In [17]:
p2

Out[17]:
0.02895752895752896
In [18]:
p2_neg = ["witch" in b['description'] for b in data if not "Children's Books" in b['categories']]
p2_neg = sum(p2_neg) * 1.0 / len(p2_neg)

In [19]:
p2_neg

Out[19]:
0.018667131891137473
In [20]:
score = prior * p1 * p2
score_neg = prior_neg * p1_neg * p2_neg

In [21]:
score / score_neg

Out[21]:
0.3793836356818883
In [22]:
p = ["Children's Books" in b['categories'] for b in data if
'witch' in b['description'] and 'wizard' in b['description']]
p = sum(p) * 1.0 / len(p)

In [23]:
p / (1 - p)

Out[23]:
0.4615384615384615

Classification - Judging a book by its cover

In [24]:
data = data2

In [25]:
data[0]

Out[25]:
{'asin/ID': '1573110639',
'url': 'http://www.amazon.com/dp/1573110639',
'description': 'one of the worlds great reference books newsweek',
'categories': ['New',
'Politics & Social Sciences',
'Science & Math',
'Education & Reference'],
'image_feature': [1.1288000345230103,
0.0,
0.0,
5.031199932098389,
0.0,
0.0,
0.5083000063896179,
0.0,
0.0,
1.666200041770935,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.7147998809814453,
0.0,
0.3750999867916107,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.5286999940872192,
0.0,
2.8366000652313232,
0.07240000367164612,
0.0,
1.7832000255584717,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.4688000679016113,
0.0,
0.0,
0.0,
0.7116000056266785,
0.25369998812675476,
0.0,
0.0,
0.0,
0.0,
0.8133999705314636,
0.0,
2.268699884414673,
0.8822000026702881,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.3970999717712402,
0.0,
0.11129999905824661,
0.0,
0.0,
0.0,
0.0,
0.0,
4.669000148773193,
0.0,
0.0,
0.0,
0.6687999963760376,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.6171998977661133,
5.061500072479248,
2.614300012588501,
0.9009000062942505,
4.316400051116943,
0.0,
0.996399998664856,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
3.3631999492645264,
0.15369999408721924,
0.0,
0.0,
0.0,
0.0,
4.521200180053711,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
3.031100034713745,
2.316699981689453,
0.0,
1.6821999549865723,
0.042500000447034836,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.4887000024318695,
0.4077000021934509,
0.0,
0.0,
0.0,
0.0,
1.610700011253357,
5.457600116729736,
0.0,
3.180299997329712,
3.7537999153137207,
0.0,
0.0,
0.0,
0.0,
1.2355999946594238,
0.0,
0.0,
0.0,
0.44859999418258667,
0.0,
2.481800079345703,
0.0,
3.6438000202178955,
3.4014999866485596,
0.0,
0.0,
1.3844000101089478,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.1526999473571777,
3.9235000610351562,
0.0,
0.6601999998092651,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.409600019454956,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.3059000074863434,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.9603000283241272,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.582099974155426,
3.8956000804901123,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.2973999977111816,
0.0,
0.7268000245094299,
0.0,
0.0,
0.0,
0.0,
0.0,
2.1744000911712646,
1.6971999406814575,
1.5746999979019165,
0.0,
0.0,
0.0,
2.025599956512451,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.2720000147819519,
3.092099905014038,
0.0,
0.0,
0.0,
3.6623001098632812,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.22300000488758087,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.048799991607666,
0.5090000033378601,
0.0,
0.0012000000569969416,
0.9927999973297119,
0.0,
1.7107000350952148,
0.0,
0.0,
2.1045000553131104,
0.0,
0.298799991607666,
2.625499963760376,
0.2711000144481659,
0.0,
0.0,
0.0,
0.0,
0.0,
1.9378999471664429,
0.0,
0.20640000700950623,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.06289999932050705,
0.4715999960899353,
0.0,
0.0,
0.0,
0.0,
3.073899984359741,
0.0,
1.062399983406067,
0.0,
0.0,
0.0,
0.0,
0.0,
0.4388999938964844,
0.0,
0.0,
0.0,
0.0,
0.0,
2.7385001182556152,
0.0,
0.0,
0.0,
1.5520000457763672,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.2581000030040741,
0.0,
0.0,
0.0,
0.0,
0.0,
0.21289999783039093,
6.52269983291626,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.7409000396728516,
0.0,
0.0,
0.0,
0.0,
2.4853999614715576,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.456399917602539,
1.3860000371932983,
0.0,
0.0,
0.0,
0.0,
3.748800039291382,
5.037700176239014,
3.2139999866485596,
0.0,
0.09889999777078629,
0.0,
0.0,
5.586699962615967,
6.66349983215332,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.944100022315979,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
4.027200222015381,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
3.1944000720977783,
0.0,
0.0,
0.0,
0.0,
0.0,
0.20479999482631683,
0.4846000075340271,
1.4106999635696411,
0.0,
0.0,
0.0,
0.0,
0.0,
1.2418999671936035,
0.0,
0.4961000084877014,
1.2853000164031982,
0.0,
0.0,
0.0,
0.0,
0.0,
3.320199966430664,
0.0,
2.3278000354766846,
1.0742000341415405,
2.198899984359741,
0.0,
0.0,
0.35519999265670776,
0.6432999968528748,
0.0,
1.4128999710083008,
0.0,
0.0,
0.0,
0.0,
0.007000000216066837,
0.0,
0.0,
0.0,
0.0,
0.0,
0.7901999950408936,
0.0,
2.1017000675201416,
0.0,
0.0,
0.0,
2.0957999229431152,
0.0,
3.3468000888824463,
0.0,
0.0,
0.0,
0.0,
1.5295000076293945,
4.02810001373291,
3.1191000938415527,
0.0,
0.04450000077486038,
1.5097999572753906,
0.0,
0.0,
3.227799892425537,
1.2000000476837158,
0.0,
0.0,
1.465399980545044,
0.8173999786376953,
0.0,
3.112499952316284,
0.0,
0.0,
0.680899977684021,
3.5350000858306885,
0.21170000731945038,
0.0,
0.0,
2.6598000526428223,
0.0,
0.0,
3.114799976348877,
0.0,
3.694700002670288,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
6.7677998542785645,
0.0,
0.0,
0.0,
3.4700000286102295,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.7547000050544739,
0.0,
0.0,
1.0044000148773193,
0.0,
0.0,
0.0,
0.1500999927520752,
0.0,
0.0,
0.19750000536441803,
2.855600118637085,
0.0,
4.5167999267578125,
0.0,
0.0,
0.0,
0.0,
0.0,
1.430899977684021,
0.0,
0.0,
0.0,
0.10279999673366547,
2.448199987411499,
0.0,
0.0,
2.6019999980926514,
0.0,
1.4150999784469604,
0.0,
3.308000087738037,
0.0,
0.0,
0.0,
3.300299882888794,
0.0,
0.0,
0.0,
0.0,
3.321899890899658,
6.156599998474121,
2.5129001140594482,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.00930000003427267,
0.0,
0.0,
0.0,
2.0820000171661377,
0.0,
0.0,
1.568600058555603,
0.0,
0.0,
2.359499931335449,
0.0,
0.0,
0.33180001378059387,
0.0,
0.0,
1.4678000211715698,
0.0,
0.7188000082969666,
0.0,
0.0,
0.0,
0.0,
0.9185000061988831,
0.0,
1.6998000144958496,
0.0,
0.0,
0.0,
4.110599994659424,
0.0,
0.0,
0.0,
0.0,
0.13359999656677246,
0.0,
1.2720999717712402,
3.387500047683716,
0.0,
0.0,
0.0,
0.0,
0.2224999964237213,
0.0,
0.0,
3.6600000858306885,
2.0469000339508057,
0.0,
0.0,
0.0,
0.0,
0.8659999966621399,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
4.730599880218506,
0.0,
0.0,
0.0,
0.0,
0.0,
0.3425999879837036,
1.0614999532699585,
0.0,
0.0,
1.767300009727478,
0.0,
2.3326001167297363,
0.0,
3.6435999870300293,
3.4238998889923096,
0.0,
0.0,
0.3750999867916107,
0.0,
0.0,
0.0,
3.2486000061035156,
0.0,
5.17549991607666,
5.763700008392334,
0.0,
3.9030001163482666,
0.0,
0.0,
5.33650016784668,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.2144999504089355,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.22210000455379486,
1.229699969291687,
3.7121999263763428,
0.0,
0.0,
0.0,
2.0841000080108643,
0.0,
0.0,
0.0,
0.0,
3.2351999282836914,
0.3991999924182892,
3.004499912261963,
1.90339994430542,
1.6711000204086304,
0.0,
0.0,
6.048799991607666,
0.0,
0.0,
0.0,
0.0,
0.0,
2.1566998958587646,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.9495999813079834,
0.0,
0.0,
0.0,
3.436300039291382,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.3694000244140625,
0.0,
1.9491000175476074,
0.9994000196456909,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.017100000753998756,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.902600049972534,
1.9157999753952026,
0.0,
0.0,
0.0,
2.4844000339508057,
0.0,
0.7396000027656555,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
9.982600212097168,
0.0,
0.0,
5.115200042724609,
3.1465001106262207,
0.12839999794960022,
0.0,
0.0,
0.0,
0.0,
0.0,
0.1655000001192093,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.16580000519752502,
0.0,
0.0,
0.0,
0.0,
0.0,
3.0162999629974365,
0.0,
0.0,
0.0,
0.0,
0.0,
0.06780000030994415,
0.7382000088691711,
0.0,
0.5608000159263611,
0.3246000111103058,
0.0,
0.0,
0.9391999840736389,
0.0,
1.1324000358581543,
0.0,
0.0,
0.0,
0.0,
0.0,
1.409600019454956,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.12790000438690186,
0.0,
0.0,
0.0,
0.0,
0.0,
0.34769999980926514,
0.0,
0.0,
0.3230000138282776,
0.9639000296592712,
3.115000009536743,
0.0,
0.0,
0.0,
0.5748000144958496,
0.0,
0.0,
0.0,
0.0,
0.0,
1.5753999948501587,
4.771900177001953,
0.0,
3.355600118637085,
0.0,
0.0,
0.5684999823570251,
0.0,
0.0,
0.0,
0.0,
0.0,
1.323699951171875,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.54339998960495,
0.0,
4.92519998550415,
0.0013000000035390258,
0.0,
0.12030000239610672,
3.781100034713745,
2.0141000747680664,
1.104200005531311,
0.21050000190734863,
0.0,
2.376199960708618,
0.0,
0.0,
0.6455000042915344,
0.6747000217437744,
0.26330000162124634,
0.0,
1.3583999872207642,
0.0,
0.0,
2.6345999240875244,
0.0,
0.0,
0.0,
0.0,
0.10320000350475311,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.4263999462127686,
0.0,
0.062300000339746475,
0.0,
0.0,
1.2417999505996704,
0.0,
2.250200033187866,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.5915000438690186,
0.0,
0.0,
0.0,
0.0,
2.482100009918213,
1.0356999635696411,
0.0,
0.3091000020503998,
3.4881999492645264,
0.0,
0.0,
0.0,
1.5706000328063965,
0.0,
0.0,
0.0,
0.0,
4.341400146484375,
0.0,
0.0,
0.0,
0.0,
0.0,
1.1411000490188599,
0.0,
0.7858999967575073,
3.214200019836426,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.7221999764442444,
0.0,
0.0,
2.1303000450134277,
2.6951000690460205,
0.0,
0.0,
0.0,
0.0,
1.4142999649047852,
2.0550999641418457,
3.257999897003174,
0.0,
0.0,
0.0,
0.0,
0.0,
0.049400001764297485,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.5530999898910522,
0.0,
0.0,
0.08510000258684158,
1.2936999797821045,
3.5964999198913574,
0.6341000199317932,
0.0,
0.82669997215271,
0.0,
0.5914999842643738,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
...]}
In [26]:
data[0]['image_feature']

Out[26]:
[1.1288000345230103,
0.0,
0.0,
5.031199932098389,
0.0,
0.0,
0.5083000063896179,
0.0,
0.0,
1.666200041770935,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.7147998809814453,
0.0,
0.3750999867916107,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.5286999940872192,
0.0,
2.8366000652313232,
0.07240000367164612,
0.0,
1.7832000255584717,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.4688000679016113,
0.0,
0.0,
0.0,
0.7116000056266785,
0.25369998812675476,
0.0,
0.0,
0.0,
0.0,
0.8133999705314636,
0.0,
2.268699884414673,
0.8822000026702881,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.3970999717712402,
0.0,
0.11129999905824661,
0.0,
0.0,
0.0,
0.0,
0.0,
4.669000148773193,
0.0,
0.0,
0.0,
0.6687999963760376,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.6171998977661133,
5.061500072479248,
2.614300012588501,
0.9009000062942505,
4.316400051116943,
0.0,
0.996399998664856,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
3.3631999492645264,
0.15369999408721924,
0.0,
0.0,
0.0,
0.0,
4.521200180053711,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
3.031100034713745,
2.316699981689453,
0.0,
1.6821999549865723,
0.042500000447034836,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.4887000024318695,
0.4077000021934509,
0.0,
0.0,
0.0,
0.0,
1.610700011253357,
5.457600116729736,
0.0,
3.180299997329712,
3.7537999153137207,
0.0,
0.0,
0.0,
0.0,
1.2355999946594238,
0.0,
0.0,
0.0,
0.44859999418258667,
0.0,
2.481800079345703,
0.0,
3.6438000202178955,
3.4014999866485596,
0.0,
0.0,
1.3844000101089478,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.1526999473571777,
3.9235000610351562,
0.0,
0.6601999998092651,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.409600019454956,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.3059000074863434,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.9603000283241272,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.582099974155426,
3.8956000804901123,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.2973999977111816,
0.0,
0.7268000245094299,
0.0,
0.0,
0.0,
0.0,
0.0,
2.1744000911712646,
1.6971999406814575,
1.5746999979019165,
0.0,
0.0,
0.0,
2.025599956512451,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.2720000147819519,
3.092099905014038,
0.0,
0.0,
0.0,
3.6623001098632812,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.22300000488758087,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.048799991607666,
0.5090000033378601,
0.0,
0.0012000000569969416,
0.9927999973297119,
0.0,
1.7107000350952148,
0.0,
0.0,
2.1045000553131104,
0.0,
0.298799991607666,
2.625499963760376,
0.2711000144481659,
0.0,
0.0,
0.0,
0.0,
0.0,
1.9378999471664429,
0.0,
0.20640000700950623,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.06289999932050705,
0.4715999960899353,
0.0,
0.0,
0.0,
0.0,
3.073899984359741,
0.0,
1.062399983406067,
0.0,
0.0,
0.0,
0.0,
0.0,
0.4388999938964844,
0.0,
0.0,
0.0,
0.0,
0.0,
2.7385001182556152,
0.0,
0.0,
0.0,
1.5520000457763672,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.2581000030040741,
0.0,
0.0,
0.0,
0.0,
0.0,
0.21289999783039093,
6.52269983291626,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.7409000396728516,
0.0,
0.0,
0.0,
0.0,
2.4853999614715576,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.456399917602539,
1.3860000371932983,
0.0,
0.0,
0.0,
0.0,
3.748800039291382,
5.037700176239014,
3.2139999866485596,
0.0,
0.09889999777078629,
0.0,
0.0,
5.586699962615967,
6.66349983215332,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.944100022315979,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
4.027200222015381,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
3.1944000720977783,
0.0,
0.0,
0.0,
0.0,
0.0,
0.20479999482631683,
0.4846000075340271,
1.4106999635696411,
0.0,
0.0,
0.0,
0.0,
0.0,
1.2418999671936035,
0.0,
0.4961000084877014,
1.2853000164031982,
0.0,
0.0,
0.0,
0.0,
0.0,
3.320199966430664,
0.0,
2.3278000354766846,
1.0742000341415405,
2.198899984359741,
0.0,
0.0,
0.35519999265670776,
0.6432999968528748,
0.0,
1.4128999710083008,
0.0,
0.0,
0.0,
0.0,
0.007000000216066837,
0.0,
0.0,
0.0,
0.0,
0.0,
0.7901999950408936,
0.0,
2.1017000675201416,
0.0,
0.0,
0.0,
2.0957999229431152,
0.0,
3.3468000888824463,
0.0,
0.0,
0.0,
0.0,
1.5295000076293945,
4.02810001373291,
3.1191000938415527,
0.0,
0.04450000077486038,
1.5097999572753906,
0.0,
0.0,
3.227799892425537,
1.2000000476837158,
0.0,
0.0,
1.465399980545044,
0.8173999786376953,
0.0,
3.112499952316284,
0.0,
0.0,
0.680899977684021,
3.5350000858306885,
0.21170000731945038,
0.0,
0.0,
2.6598000526428223,
0.0,
0.0,
3.114799976348877,
0.0,
3.694700002670288,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
6.7677998542785645,
0.0,
0.0,
0.0,
3.4700000286102295,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.7547000050544739,
0.0,
0.0,
1.0044000148773193,
0.0,
0.0,
0.0,
0.1500999927520752,
0.0,
0.0,
0.19750000536441803,
2.855600118637085,
0.0,
4.5167999267578125,
0.0,
0.0,
0.0,
0.0,
0.0,
1.430899977684021,
0.0,
0.0,
0.0,
0.10279999673366547,
2.448199987411499,
0.0,
0.0,
2.6019999980926514,
0.0,
1.4150999784469604,
0.0,
3.308000087738037,
0.0,
0.0,
0.0,
3.300299882888794,
0.0,
0.0,
0.0,
0.0,
3.321899890899658,
6.156599998474121,
2.5129001140594482,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.00930000003427267,
0.0,
0.0,
0.0,
2.0820000171661377,
0.0,
0.0,
1.568600058555603,
0.0,
0.0,
2.359499931335449,
0.0,
0.0,
0.33180001378059387,
0.0,
0.0,
1.4678000211715698,
0.0,
0.7188000082969666,
0.0,
0.0,
0.0,
0.0,
0.9185000061988831,
0.0,
1.6998000144958496,
0.0,
0.0,
0.0,
4.110599994659424,
0.0,
0.0,
0.0,
0.0,
0.13359999656677246,
0.0,
1.2720999717712402,
3.387500047683716,
0.0,
0.0,
0.0,
0.0,
0.2224999964237213,
0.0,
0.0,
3.6600000858306885,
2.0469000339508057,
0.0,
0.0,
0.0,
0.0,
0.8659999966621399,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
4.730599880218506,
0.0,
0.0,
0.0,
0.0,
0.0,
0.3425999879837036,
1.0614999532699585,
0.0,
0.0,
1.767300009727478,
0.0,
2.3326001167297363,
0.0,
3.6435999870300293,
3.4238998889923096,
0.0,
0.0,
0.3750999867916107,
0.0,
0.0,
0.0,
3.2486000061035156,
0.0,
5.17549991607666,
5.763700008392334,
0.0,
3.9030001163482666,
0.0,
0.0,
5.33650016784668,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.2144999504089355,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.22210000455379486,
1.229699969291687,
3.7121999263763428,
0.0,
0.0,
0.0,
2.0841000080108643,
0.0,
0.0,
0.0,
0.0,
3.2351999282836914,
0.3991999924182892,
3.004499912261963,
1.90339994430542,
1.6711000204086304,
0.0,
0.0,
6.048799991607666,
0.0,
0.0,
0.0,
0.0,
0.0,
2.1566998958587646,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.9495999813079834,
0.0,
0.0,
0.0,
3.436300039291382,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.3694000244140625,
0.0,
1.9491000175476074,
0.9994000196456909,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.017100000753998756,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.902600049972534,
1.9157999753952026,
0.0,
0.0,
0.0,
2.4844000339508057,
0.0,
0.7396000027656555,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
9.982600212097168,
0.0,
0.0,
5.115200042724609,
3.1465001106262207,
0.12839999794960022,
0.0,
0.0,
0.0,
0.0,
0.0,
0.1655000001192093,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.16580000519752502,
0.0,
0.0,
0.0,
0.0,
0.0,
3.0162999629974365,
0.0,
0.0,
0.0,
0.0,
0.0,
0.06780000030994415,
0.7382000088691711,
0.0,
0.5608000159263611,
0.3246000111103058,
0.0,
0.0,
0.9391999840736389,
0.0,
1.1324000358581543,
0.0,
0.0,
0.0,
0.0,
0.0,
1.409600019454956,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.12790000438690186,
0.0,
0.0,
0.0,
0.0,
0.0,
0.34769999980926514,
0.0,
0.0,
0.3230000138282776,
0.9639000296592712,
3.115000009536743,
0.0,
0.0,
0.0,
0.5748000144958496,
0.0,
0.0,
0.0,
0.0,
0.0,
1.5753999948501587,
4.771900177001953,
0.0,
3.355600118637085,
0.0,
0.0,
0.5684999823570251,
0.0,
0.0,
0.0,
0.0,
0.0,
1.323699951171875,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.54339998960495,
0.0,
4.92519998550415,
0.0013000000035390258,
0.0,
0.12030000239610672,
3.781100034713745,
2.0141000747680664,
1.104200005531311,
0.21050000190734863,
0.0,
2.376199960708618,
0.0,
0.0,
0.6455000042915344,
0.6747000217437744,
0.26330000162124634,
0.0,
1.3583999872207642,
0.0,
0.0,
2.6345999240875244,
0.0,
0.0,
0.0,
0.0,
0.10320000350475311,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.4263999462127686,
0.0,
0.062300000339746475,
0.0,
0.0,
1.2417999505996704,
0.0,
2.250200033187866,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
2.5915000438690186,
0.0,
0.0,
0.0,
0.0,
2.482100009918213,
1.0356999635696411,
0.0,
0.3091000020503998,
3.4881999492645264,
0.0,
0.0,
0.0,
1.5706000328063965,
0.0,
0.0,
0.0,
0.0,
4.341400146484375,
0.0,
0.0,
0.0,
0.0,
0.0,
1.1411000490188599,
0.0,
0.7858999967575073,
3.214200019836426,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.7221999764442444,
0.0,
0.0,
2.1303000450134277,
2.6951000690460205,
0.0,
0.0,
0.0,
0.0,
1.4142999649047852,
2.0550999641418457,
3.257999897003174,
0.0,
0.0,
0.0,
0.0,
0.0,
0.049400001764297485,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.5530999898910522,
0.0,
0.0,
0.08510000258684158,
1.2936999797821045,
3.5964999198913574,
0.6341000199317932,
0.0,
0.82669997215271,
0.0,
0.5914999842643738,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
...]
In [ ]:


In [27]:
X = [b['image_feature'] for b in data]
y = ["Children's Books" in b['categories'] for b in data]

In [28]:
X_train = X[:len(X)//2]
y_train = y[:len(y)//2]

X_test = X[len(X)//2:]
y_test = y[len(y)//2:]

In [29]:
mod = linear_model.LogisticRegression(C=1.0)
mod.fit(X_train, y_train)

C:\Users\Julian McAuley\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
FutureWarning)

Out[29]:
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, l1_ratio=None, max_iter=100,
multi_class='warn', n_jobs=None, penalty='l2',
random_state=None, solver='warn', tol=0.0001, verbose=0,
warm_start=False)
In [30]:
train_predictions = mod.predict(X_train)
test_predictions = mod.predict(X_test)

In [31]:
# accuracy
sum(test_predictions == y_test) / len(y_test)

Out[31]:
0.9456
In [32]:
y_false = numpy.array([False for b in y_test])

In [33]:
# accuracy when predicting "false" always
sum(y_false == y_test) / len(y_test)

Out[33]:
0.962

Diagnostics¶

In [34]:
f = open("C:/users/Julian McAuley/Documents/class_files/bankruptcy.arff", 'r')

In [35]:
while not '@data' in f.readline():
pass

In [36]:
dataset = []
for l in f:
if '?' in l: # Missing entry
continue
l = l.split(',')
values = [1] + [float(x) for x in l]
values[-1] = values[-1] > 0 # Convert to bool
dataset.append(values)

In [37]:
dataset[0]

Out[37]:
[1,
0.088238,
0.55472,
0.01134,
1.0205,
-66.52,
0.34204,
0.10949,
0.57752,
1.0881,
0.32036,
0.10949,
0.1976,
0.096885,
0.10949,
1475.2,
0.24742,
1.8027,
0.10949,
0.077287,
50.199,
1.1574,
0.13523,
0.062287,
0.41949,
0.32036,
0.20912,
1.0387,
0.026093,
6.1267,
0.37788,
0.077287,
155.33,
2.3498,
0.24377,
0.13523,
1.4493,
571.37,
0.32101,
0.095457,
0.12879,
0.11189,
0.095457,
127.3,
77.096,
0.45289,
0.66883,
54.621,
0.10746,
0.075859,
1.0193,
0.55407,
0.42557,
0.73717,
0.73866,
15182.0,
0.080955,
0.27543,
0.91905,
0.002024,
7.2711,
4.7343,
142.76,
2.5568,
3.2597,
False]

Data setup

In [38]:
X = [d[:-1] for d in dataset]
y = [d[-1] for d in dataset]


Fit model

In [39]:
mod = linear_model.LogisticRegression(C=1.0)
mod.fit(X,y)

C:\Users\Julian McAuley\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
FutureWarning)
C:\Users\Julian McAuley\Anaconda3\lib\site-packages\sklearn\svm\base.py:929: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
"the number of iterations.", ConvergenceWarning)

Out[39]:
LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, l1_ratio=None, max_iter=100,
multi_class='warn', n_jobs=None, penalty='l2',
random_state=None, solver='warn', tol=0.0001, verbose=0,
warm_start=False)
In [40]:
pred = mod.predict(X)

In [41]:
sum(pred == y) / len(y)

Out[41]:
0.9663477400197954
In [42]:
sum(y)

Out[42]:
102
In [43]:
len(y)

Out[43]:
3031
In [44]:
1 - 102/3031

Out[44]:
0.9663477400197954
In [45]:
sum(pred)

Out[45]:
6

Balanced model

In [46]:
mod = linear_model.LogisticRegression(C=1.0, class_weight = 'balanced')

In [47]:
mod.fit(X,y)

C:\Users\Julian McAuley\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
FutureWarning)
C:\Users\Julian McAuley\Anaconda3\lib\site-packages\sklearn\svm\base.py:929: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
"the number of iterations.", ConvergenceWarning)

Out[47]:
LogisticRegression(C=1.0, class_weight='balanced', dual=False,
fit_intercept=True, intercept_scaling=1, l1_ratio=None,
max_iter=100, multi_class='warn', n_jobs=None, penalty='l2',
random_state=None, solver='warn', tol=0.0001, verbose=0,
warm_start=False)
In [48]:
pred = mod.predict(X)

In [49]:
sum(pred == y) / len(y)

Out[49]:
0.7832398548333883
In [50]:
# How many positive predictions?
sum(pred)

Out[50]:
717

Train/validation/test splits

In [51]:
Xy = list(zip(X,y))

In [52]:
random.shuffle(Xy)

In [53]:
X = [d[0] for d in Xy]
y = [d[1] for d in Xy]

In [54]:
N = len(y)

In [55]:
Ntrain = 1000
Nvalid = 1000
Ntest = 1031

In [56]:
Xtrain = X[:Ntrain]
Xvalid = X[Ntrain:Ntrain+Nvalid]
Xtest = X[Ntrain+Nvalid:]

In [57]:
ytrain = y[:Ntrain]
yvalid = y[Ntrain:Ntrain+Nvalid]
ytest = y[Ntrain+Nvalid:]

In [58]:
mod.fit(Xtrain, ytrain)

C:\Users\Julian McAuley\Anaconda3\lib\site-packages\sklearn\linear_model\logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
FutureWarning)
C:\Users\Julian McAuley\Anaconda3\lib\site-packages\sklearn\svm\base.py:929: ConvergenceWarning: Liblinear failed to converge, increase the number of iterations.
"the number of iterations.", ConvergenceWarning)

Out[58]:
LogisticRegression(C=1.0, class_weight='balanced', dual=False,
fit_intercept=True, intercept_scaling=1, l1_ratio=None,
max_iter=100, multi_class='warn', n_jobs=None, penalty='l2',
random_state=None, solver='warn', tol=0.0001, verbose=0,
warm_start=False)

TP, TN, FP, FN, Accuracy, BER

In [59]:
pred = mod.predict(Xtest)

In [60]:
correct = pred == ytest

In [61]:
TP_ = numpy.logical_and(pred, ytest)
FP_ = numpy.logical_and(pred, numpy.logical_not(ytest))
TN_ = numpy.logical_and(numpy.logical_not(pred), numpy.logical_not(ytest))
FN_ = numpy.logical_and(numpy.logical_not(pred), ytest)

In [62]:
TP = sum(TP_)
FP = sum(FP_)
TN = sum(TN_)
FN = sum(FN_)

In [63]:
# accuracy
(TP + TN) / (TP + FP + TN + FN)

Out[63]:
0.8166828322017459
In [64]:
sum(correct) / len(correct)

Out[64]:
0.8166828322017459
In [65]:
# BER
1 - 0.5*(TP / (TP + FN) + TN / (TN + FP))

Out[65]:
0.23573540280857364

Ranking

In [66]:
scores = mod.decision_function(Xtest)

In [67]:
scores

Out[67]:
array([-1.02150932, -0.45331484,  0.76035815, ..., -0.41931955,
-7.00631971, -2.79365971])
In [68]:
scoreslabels = list(zip(scores, ytest))

In [69]:
scoreslabels.sort(reverse=True)

In [70]:
scoreslabels

Out[70]:
[(527.8725660931519, False),
(63.46037259398749, False),
(42.894084664091544, False),
(18.075448965401257, False),
(9.862404792631793, False),
(4.962546802911222, True),
(4.736654914817238, True),
(4.556887182570365, False),
(3.7005977151259297, False),
(3.656068253347717, True),
(3.5752739898497103, False),
(3.485720505397986, True),
(3.22927354147234, True),
(2.9869406854160876, False),
(2.8418252607535397, False),
(2.829119426804683, False),
(2.7724588389607034, False),
(2.6450186687607498, False),
(2.626672780978226, False),
(2.3538843658647832, True),
(2.3223766578217693, False),
(2.2560144193854814, False),
(2.2518054962119076, False),
(2.219166837960687, False),
(2.210914176639149, True),
(2.1281404406473197, False),
(2.0591352963429634, False),
(2.038433062211443, True),
(1.9742254030934807, False),
(1.9209753783111947, False),
(1.8787713262731547, True),
(1.8785302730267772, False),
(1.8315873705719867, False),
(1.7828836400176038, False),
(1.7792188904634094, False),
(1.693598086424246, False),
(1.6232160143556382, False),
(1.5760783433704435, False),
(1.5691693037647996, False),
(1.5459522059539448, False),
(1.5341521243735587, False),
(1.5123354564503138, True),
(1.4764200641769984, False),
(1.4740836003457103, False),
(1.4597947885042133, False),
(1.372284371105292, True),
(1.3230330691978889, False),
(1.3054412847622898, False),
(1.2970315359608393, False),
(1.2853506619426085, False),
(1.282268229638567, False),
(1.214986700862486, True),
(1.2114957689513508, False),
(1.2012041996887883, False),
(1.197659763488359, True),
(1.19562139512699, False),
(1.1648985241759953, False),
(1.1522592480872338, True),
(1.1241030940644716, False),
(1.120644401517721, False),
(1.1006026755449343, True),
(1.0829604801782926, False),
(1.0250731801319242, False),
(1.0169947941639692, False),
(0.9931404526637403, False),
(0.972305213223842, True),
(0.9667936642413674, False),
(0.9541579843991822, False),
(0.9161994213112409, False),
(0.9134619926610511, False),
(0.8879680548654793, False),
(0.8787911183988576, False),
(0.8759060246867431, False),
(0.8619014172025745, True),
(0.8562682383207642, False),
(0.8525878477299799, False),
(0.8302055564744096, False),
(0.8212156246087717, True),
(0.80742304366995, False),
(0.8067664484809147, False),
(0.8051885161412234, False),
(0.7941796122962278, False),
(0.791136569022144, False),
(0.7844486614878085, False),
(0.7736108986876934, False),
(0.769308570244995, False),
(0.762546067260578, False),
(0.760358145987785, False),
(0.7553997570077361, True),
(0.7545046339926614, False),
(0.7445043612501682, False),
(0.739160452047226, False),
(0.7391283919105296, False),
(0.7329955260452116, False),
(0.7244293509647873, False),
(0.7113525124647949, False),
(0.7071614091571333, False),
(0.6701119537303117, False),
(0.6669792695846232, True),
(0.6599741096133441, True),
(0.6505268143542632, False),
(0.6336917430188682, False),
(0.6306289275283855, False),
(0.6262606328975947, False),
(0.6170170244330485, False),
(0.6107362776255895, False),
(0.6085950951377094, False),
(0.5927049516888335, False),
(0.584675115230378, False),
(0.5713417318049113, False),
(0.5705872159668323, False),
(0.5670325348780662, True),
(0.5667811340240149, False),
(0.5409013514943127, False),
(0.5325414738833728, False),
(0.5268383715349026, False),
(0.5216526609206024, False),
(0.4918967935688682, False),
(0.4779392595260147, False),
(0.4772763966035518, False),
(0.47384266326161417, False),
(0.47013071001212936, False),
(0.4615007587401442, False),
(0.45222742501264623, True),
(0.4459700149449065, False),
(0.44384646346724044, False),
(0.44318074271395214, False),
(0.4319261846641059, False),
(0.4245053972786129, False),
(0.4230890365972729, False),
(0.39014582259820996, False),
(0.3894587289189434, False),
(0.38193612853259384, False),
(0.34126665446310833, False),
(0.338390319354292, False),
(0.3213237980367184, False),
(0.320253453629905, False),
(0.3157541393716313, False),
(0.31076420405722927, False),
(0.31063971689784087, False),
(0.30306558703420583, False),
(0.28922911076024604, False),
(0.28575227664213376, False),
(0.28454311821416234, False),
(0.28292240728231344, True),
(0.2585225418941578, False),
(0.25437169399801196, False),
(0.2543164984190517, True),
(0.24347647731649, False),
(0.23609555212157315, False),
(0.2337855340441933, False),
(0.22697095403926024, False),
(0.22385200685794346, False),
(0.2129553051373144, False),
(0.21172151810887768, True),
(0.19757257283496407, False),
(0.19130989419653086, False),
(0.18973974451227602, False),
(0.17927855177581195, False),
(0.17170526488989232, False),
(0.1676796590487258, True),
(0.165096860110686, False),
(0.1512251377299539, False),
(0.14955060676551266, False),
(0.1455021587349151, False),
(0.14539126241432473, False),
(0.14148544713125175, False),
(0.13666677569370175, False),
(0.13609768705781597, False),
(0.13373204664011648, False),
(0.13129851427371939, False),
(0.1284651339185415, False),
(0.1207800145647646, False),
(0.11353440782963507, False),
(0.10274473117980408, False),
(0.10127692559731592, False),
(0.09804768609309587, False),
(0.09718591852530388, False),
(0.09602666522705626, False),
(0.09293382307061625, False),
(0.09074281743438493, False),
(0.0884536147506295, False),
(0.08755270713871198, False),
(0.07173702058668037, False),
(0.07032537890847311, False),
(0.06645279619410548, True),
(0.060600024430976326, False),
(0.05880739469465822, False),
(0.05539010290597922, False),
(0.0476002498667497, False),
(0.046823459052562896, False),
(0.04159528203735362, True),
(0.04056158793577157, False),
(0.03652301199543749, False),
(0.035063233811443204, False),
(0.03238656978471542, False),
(0.025407414103907327, False),
(0.023445716362086127, False),
(0.016920918688043556, False),
(0.014094365012372028, False),
(0.013446428903658308, False),
(0.01199611428729495, False),
(0.010378866477788722, False),
(0.009362333629613234, False),
(0.00501704906927412, False),
(0.003146981190101799, False),
(-0.0028703406023453844, False),
(-0.003983891171812987, False),
(-0.0072492683593751335, False),
(-0.017284088226712586, False),
(-0.03153564113466857, False),
(-0.032088329877906455, False),
(-0.047043458804256214, False),
(-0.04893890155255533, False),
(-0.04972969181353938, False),
(-0.05186588813602856, False),
(-0.05211410657825068, False),
(-0.05484337460101381, False),
(-0.055198315425659575, False),
(-0.055932826497332125, False),
(-0.056342417325787944, True),
(-0.0570526215735231, False),
(-0.061291856390061863, False),
(-0.062194454954932823, False),
(-0.06375927775946368, False),
(-0.06653243641308594, False),
(-0.08403410560915615, True),
(-0.09649889506496957, False),
(-0.10047330195006667, False),
(-0.10146617370525314, False),
(-0.10162677652908343, False),
(-0.10427618002976126, False),
(-0.12372917380643107, False),
(-0.1251357676316511, False),
(-0.1310340781140288, False),
(-0.13311158571265283, False),
(-0.14102736600191093, False),
(-0.14267068899939864, False),
(-0.1449250319776865, False),
(-0.14946700999625953, False),
(-0.15428256154706213, False),
(-0.16311449776764111, False),
(-0.1705149568422938, False),
(-0.17402136473183663, False),
(-0.17489120457059007, False),
(-0.17706007389254688, False),
(-0.18749957200527215, False),
(-0.18749957200527215, False),
(-0.19091139883907285, False),
(-0.19331184852433206, False),
(-0.19548429463822573, False),
(-0.1961891983781824, False),
(-0.1962638919610741, False),
(-0.197853461283669, False),
(-0.20205613645355217, False),
(-0.20311873712096687, True),
(-0.20946934463209335, False),
(-0.21997565755558282, False),
(-0.22224410627783805, False),
(-0.22464359213708632, False),
(-0.2248580399670045, False),
(-0.22964923505835624, False),
(-0.2312171264593971, False),
(-0.23310265736261507, False),
(-0.23433535841605793, True),
(-0.2345028498174271, False),
(-0.23596025648211835, False),
(-0.23721573696229595, False),
(-0.25348288654382406, False),
(-0.2667199515736677, False),
(-0.2680910527578598, False),
(-0.269611014039315, False),
(-0.2724144616319595, True),
(-0.2724870445349826, False),
(-0.27381549570505825, False),
(-0.27842574869505066, False),
(-0.27854973192697463, False),
(-0.2823742740192546, False),
(-0.2832400297014642, False),
(-0.28471739111368133, False),
(-0.2853659827816465, False),
(-0.28666454005354025, False),
(-0.2880323570328658, True),
(-0.29094326387549774, False),
(-0.2958748641977448, False),
(-0.29758824870323464, False),
(-0.2995647133571179, False),
(-0.3008857081488935, False),
(-0.3114895016938733, False),
(-0.3130887250117713, False),
(-0.31641521249226867, False),
(-0.3172675799094694, False),
(-0.3176687874350209, False),
(-0.320814364680044, False),
(-0.320814364680044, False),
(-0.32451991315124284, False),
(-0.32619990556723855, False),
(-0.32638693213312725, False),
(-0.33311073943479586, False),
(-0.3340333829487149, False),
(-0.33988254867295087, False),
(-0.34204507073838386, False),
(-0.34257195322777384, False),
(-0.34443403037477915, False),
(-0.34727946681193655, False),
(-0.3523186905650033, False),
(-0.36164185243983904, False),
(-0.36552862247532464, False),
(-0.3704135642219002, False),
(-0.37403613158441396, False),
(-0.37795207008325427, False),
(-0.38236074862604974, False),
(-0.3843743529161412, False),
(-0.386555206394569, False),
(-0.3917126557762589, False),
(-0.39287967966801796, False),
(-0.3947822323909086, False),
(-0.39478966649027136, False),
(-0.39800795108254133, False),
(-0.4048237245754408, False),
(-0.4071359684142426, False),
(-0.4084979101923166, False),
(-0.4154992719702202, False),
(-0.4154995894151229, False),
(-0.4168674473369899, False),
(-0.4193195519360934, False),
(-0.4212661662067856, False),
(-0.42258286088012464, False),
(-0.42315226985585175, False),
(-0.4330318220295387, False),
(-0.434947076366309, False),
(-0.43845730026732954, False),
(-0.4409054025394775, False),
(-0.4473731887719682, False),
(-0.45062953692084784, False),
(-0.45226846782210683, False),
(-0.45331484425741697, False),
(-0.4556433105656378, False),
(-0.4558784275295531, False),
(-0.457133095332974, False),
(-0.4576714435258935, False),
(-0.4593542241915418, False),
(-0.4633830196098554, False),
(-0.4638286048155573, False),
(-0.46708792012446465, False),
(-0.4671015844784131, False),
(-0.4700662034071881, False),
(-0.4716502853010651, True),
(-0.47194739937744945, False),
(-0.47555945415485656, False),
(-0.47559055897733665, False),
(-0.47829444152437217, False),
(-0.48206818722792166, False),
(-0.48333824649070933, False),
(-0.48389390333613513, False),
(-0.4878746081448483, False),
(-0.4920827138134628, False),
(-0.4929220580182557, False),
(-0.498289566330272, False),
(-0.49905260046965616, False),
(-0.49926623216939725, False),
(-0.5001798533685832, False),
(-0.5008050129831082, False),
(-0.5019605446024705, False),
(-0.503010225194968, False),
(-0.5036110379664442, False),
(-0.5060839716766361, True),
(-0.5099675841706239, False),
(-0.5102307529478337, False),
(-0.5137942445591323, False),
(-0.5140120385185056, False),
(-0.5179430302335404, False),
(-0.5204273466948129, False),
(-0.5319728256276314, False),
(-0.5353165473498905, False),
(-0.5355699838242772, False),
(-0.5404148077941634, False),
(-0.544023526050624, False),
(-0.5525021495143454, False),
(-0.5574042689114669, False),
(-0.5621615015612423, False),
(-0.5663450656062785, False),
(-0.5692663811956898, False),
(-0.572373565702505, False),
(-0.5822671669594929, False),
(-0.5864357320277294, False),
(-0.593768718456776, False),
(-0.5972843926997538, False),
(-0.5994430039459974, False),
(-0.6005063073626584, False),
(-0.6098031085064736, False),
(-0.6143941582179075, False),
(-0.6255020564921375, False),
(-0.6297253027006638, False),
(-0.6315476666043768, False),
(-0.6337669906370417, False),
(-0.6381988852057644, False),
(-0.6391235223943411, False),
(-0.6435701438498901, False),
(-0.6461359064495306, False),
(-0.6473947765316649, False),
(-0.6493109056375134, False),
(-0.6497412040859966, False),
(-0.6555439788796571, False),
(-0.6581364836883031, False),
(-0.6590512255829405, False),
(-0.660221581822208, False),
(-0.6618388381685524, False),
(-0.6643709659679985, False),
(-0.6659914640636394, False),
(-0.6670805983574105, False),
(-0.6771973299736674, False),
(-0.6781732616843544, False),
(-0.6786107764181668, False),
(-0.6800578391106155, False),
(-0.6821021897227068, False),
(-0.6908755164763701, False),
(-0.6950668063945734, False),
(-0.696222571698159, False),
(-0.6982030526274614, False),
(-0.702857743558127, False),
(-0.7043839695012394, False),
(-0.7079962827074543, False),
(-0.7083516894040478, False),
(-0.7090084689622612, False),
(-0.7099321392839615, False),
(-0.7103141030208502, False),
(-0.7105036233832297, False),
(-0.7106798940007412, False),
(-0.7173689192110999, False),
(-0.723931031677635, False),
(-0.7263510733018215, False),
(-0.7276158216749112, False),
(-0.733041095197661, False),
(-0.7392875417844504, False),
(-0.7396269262848295, False),
(-0.7401475882309517, False),
(-0.7424695203981019, False),
(-0.7425751875541755, False),
(-0.7461231680376373, False),
(-0.7462728848817147, False),
(-0.7485679133798199, False),
(-0.7486500288261259, False),
(-0.7498900223084822, False),
(-0.7501643864904713, False),
(-0.753524053417025, False),
(-0.7554137771661181, False),
(-0.76230776039502, False),
(-0.7628663218942945, False),
(-0.763770952899285, False),
(-0.7694818845535094, False),
(-0.7710608075425767, False),
(-0.7742392227108311, False),
(-0.7750849831123893, False),
(-0.7777303058997057, False),
(-0.7846339237145098, False),
(-0.7851321763975269, False),
(-0.7868545672042432, False),
(-0.7879825162664801, False),
(-0.7912476929057478, False),
(-0.7943679116113186, False),
(-0.8062623731987028, False),
(-0.8069944942603396, False),
(-0.8089404422347405, False),
(-0.8113005331998688, False),
(-0.8116658188676161, False),
(-0.8133913298968901, False),
(-0.8137648398175056, False),
(-0.8172596388803787, False),
(-0.8175049371301609, False),
(-0.8176231867679002, False),
(-0.8187096750242352, False),
(-0.8230358238493091, False),
(-0.8233668141673153, False),
(-0.823637970521162, False),
(-0.8268004408706077, False),
(-0.8300722160139281, False),
(-0.8309650487142465, False),
(-0.8449271996655032, False),
(-0.8473588615960589, False),
(-0.8500738201727921, False),
(-0.8503044244683858, False),
(-0.859163641923649, False),
(-0.8615089499457439, False),
(-0.8629441726327197, False),
(-0.8634489503139479, False),
(-0.8724572568025816, False),
(-0.8763428576141213, False),
(-0.8783756489034941, False),
(-0.8839837390131263, False),
(-0.8868167178431209, False),
(-0.8868167178431209, False),
(-0.8951957078156233, False),
(-0.8991629871831383, False),
(-0.9028066012802267, False),
(-0.9033052346022596, False),
(-0.903686881161445, False),
(-0.9043594914891545, False),
(-0.9046438733864434, False),
(-0.9070815946648161, False),
(-0.9091919353707167, False),
(-0.9092572921986563, False),
(-0.9101444001649507, False),
(-0.9102725799365707, False),
(-0.9127638842119885, False),
(-0.9150411301577511, False),
(-0.9152193585814338, False),
(-0.925157410119129, False),
(-0.9286534293273743, False),
(-0.9293439691911637, False),
(-0.929559058812907, False),
(-0.9310650068136621, False),
(-0.9319048764882879, False),
(-0.9319751264974662, False),
(-0.939705253971764, False),
(-0.9429008674047428, False),
(-0.9446801911192447, False),
(-0.9477039717163066, False),
(-0.9508419511250307, False),
(-0.9527866706782709, False),
(-0.9574480010633845, False),
(-0.9578378219582698, False),
(-0.9634089534234492, False),
(-0.9651475747293192, False),
(-0.965615377867196, False),
(-0.9669114418699017, False),
(-0.968411959377995, False),
(-0.9691380338052832, False),
(-0.9817525257477163, False),
(-0.9866509585147712, False),
(-0.9869977248801654, False),
(-0.9942752653599063, False),
(-0.9948209093110935, False),
(-1.0026355709239463, False),
(-1.0113433490599373, False),
(-1.012727575622735, False),
(-1.019203195080094, False),
(-1.0215093223988654, False),
(-1.021636299344059, False),
(-1.0271087886935426, False),
(-1.027457844963605, False),
(-1.0287809407527035, False),
(-1.0353950003248906, False),
(-1.0378495480438297, False),
(-1.042109484722372, False),
(-1.0426718561970674, False),
(-1.0468374903879527, False),
(-1.0528123308181523, False),
(-1.0532460299211488, False),
(-1.0605682366041782, False),
(-1.0679602315673593, False),
(-1.0817950275322268, False),
(-1.0818245799254416, False),
(-1.0840287012095808, False),
(-1.084059107101466, False),
(-1.0851125896521032, False),
(-1.0896840017887612, False),
(-1.0921908490581913, False),
(-1.0933389859232108, False),
(-1.0985911063406295, False),
(-1.1001280045533963, False),
(-1.1052781315356723, False),
(-1.1088827001375368, False),
(-1.1160669052274454, False),
(-1.1185367804315247, False),
(-1.1198149249886225, False),
(-1.1319918277173517, False),
(-1.1330895794186984, False),
(-1.137874317955121, False),
(-1.139256309137199, False),
(-1.1412193313860848, False),
(-1.1466793187580473, False),
(-1.1482500993582017, False),
(-1.1507407541297607, False),
(-1.151720073123184, False),
(-1.1539154502571791, False),
(-1.156263453569715, False),
(-1.157393553384665, False),
(-1.1687883125879655, False),
(-1.1740391670363886, False),
(-1.1762586749663124, False),
(-1.177887953350485, False),
(-1.1802491484863127, False),
(-1.1823247580023954, False),
(-1.185763087492961, False),
(-1.1916264979602764, False),
(-1.1928173301217098, False),
(-1.195313729232249, False),
(-1.1963431137945517, False),
(-1.2020128621447665, False),
(-1.2052640510436934, False),
(-1.2058175730025673, False),
(-1.207880483645211, False),
(-1.217006211684352, False),
(-1.2179165162450039, False),
(-1.2180913869625805, False),
(-1.2193246591588722, False),
(-1.220924191445269, False),
(-1.2252554890223917, False),
(-1.23325402173983, False),
(-1.2333283372992088, False),
(-1.234189939351645, False),
(-1.2393629731550413, False),
(-1.2414488964157222, False),
(-1.24186141728976, False),
(-1.2436028696140542, False),
(-1.245471123888228, False),
(-1.2458076715820674, False),
(-1.2486035023553743, False),
(-1.2541500978974995, False),
(-1.2553988872259678, False),
(-1.2565779409828748, False),
(-1.257156826156862, False),
(-1.2618091632950428, False),
(-1.2628948220787057, False),
(-1.2654730462075605, False),
(-1.2718630934435144, False),
(-1.2738662956101903, False),
(-1.2744284775500982, False),
(-1.2783448973770064, False),
(-1.2792472692531613, False),
(-1.2815255511560708, False),
(-1.2817943380936752, False),
(-1.283060247027382, False),
(-1.2927258589539374, False),
(-1.2948038730008842, False),
(-1.2977728117829217, False),
(-1.3094461737700898, False),
(-1.3095432352122889, False),
(-1.3109047250089025, False),
(-1.3150621428412859, False),
(-1.3172136901155134, False),
(-1.3182317858807309, False),
(-1.3190525401797992, True),
(-1.3219242649338923, False),
(-1.326850254880909, False),
(-1.3301157306800278, False),
(-1.3322114506735523, False),
(-1.336878977658922, False),
(-1.337555047319098, False),
(-1.3399943087529853, False),
(-1.3427409370940726, False),
(-1.3435309774524788, False),
(-1.3491276733944495, False),
(-1.3496163356729138, False),
(-1.3503827508559814, False),
(-1.3504270909604958, False),
(-1.3524835615750055, False),
(-1.3532867173767462, False),
(-1.35662460386953, False),
(-1.3643551430669216, False),
(-1.3653535703151605, False),
(-1.3660578366620872, False),
(-1.3678596865125878, False),
(-1.369491873087348, False),
(-1.3710347072200662, False),
(-1.3717961618738577, False),
(-1.373442233812966, False),
(-1.385335633413912, False),
(-1.3913003419521721, False),
(-1.393857006435732, False),
(-1.4100931760081414, False),
(-1.4101037786756963, False),
(-1.410741182004027, False),
(-1.4131257453433628, False),
(-1.4157735579368569, False),
(-1.4215116308392868, False),
(-1.4247297392559684, False),
(-1.427863405082101, False),
(-1.4289028559038774, False),
(-1.4370614591362147, False),
(-1.44019084031416, False),
(-1.4443032134633307, False),
(-1.4480436546962772, False),
(-1.4490336026829644, False),
(-1.4551200394601616, False),
(-1.4587005716085453, False),
(-1.46001907633036, False),
(-1.46001907633036, False),
(-1.4714900423835062, False),
(-1.4721265055306643, False),
(-1.4733308367641114, False),
(-1.480314687569143, False),
(-1.4825988745776117, False),
(-1.4851535246688188, False),
(-1.486209950358279, False),
(-1.4870615767539435, False),
(-1.491843056462963, False),
(-1.4952318003246792, False),
(-1.497054928981626, False),
(-1.4970890401989787, False),
(-1.500332531153938, False),
(-1.5049485783179666, False),
(-1.5059480177470932, False),
(-1.5061136439585499, False),
(-1.506396643111394, False),
(-1.51148440387208, False),
(-1.5218120447883516, False),
(-1.5252366706981133, False),
(-1.526740682130096, False),
(-1.5337762317028274, False),
(-1.5357458266748214, False),
(-1.542061560848373, False),
(-1.5456684514848915, False),
(-1.5484602027763545, False),
(-1.5488001018807434, False),
(-1.5501548630201385, False),
(-1.5628188580734015, False),
(-1.575799689988818, False),
(-1.5759788596489548, False),
(-1.5770107592189042, False),
(-1.5855821461582686, False),
(-1.5867829432603526, False),
(-1.5889428680981166, False),
(-1.5912571684372172, False),
(-1.597614800090072, False),
(-1.6000799338689355, False),
(-1.603494609729807, False),
(-1.60547069301525, False),
(-1.6097620630794018, False),
(-1.611037830173756, False),
(-1.6144707905413922, False),
(-1.62110483212946, False),
(-1.625627287171236, False),
(-1.6287675115079328, False),
(-1.6349973688834372, False),
(-1.6349973688834372, False),
(-1.6367956950370859, False),
(-1.6400761925278595, False),
(-1.6439925368450465, False),
(-1.646032644365786, False),
(-1.6497939815839135, False),
(-1.652304149388035, False),
(-1.6572186887832145, False),
(-1.6572411670070142, False),
(-1.671001421209682, False),
(-1.671542052233981, False),
(-1.6733241029027262, False),
(-1.6743646630102766, False),
(-1.67572477583371, False),
(-1.6797514341803677, False),
(-1.6809673699498267, False),
(-1.6827107095470863, False),
(-1.6828108432655673, False),
(-1.6837772465258103, False),
(-1.6965587922956045, False),
(-1.6995742081652634, False),
(-1.7019918370973512, False),
(-1.714052729206089, False),
(-1.7146587179200816, False),
(-1.717019956859522, False),
(-1.7170526942217565, False),
(-1.723700457104044, False),
(-1.7252631112596335, False),
(-1.7269493381634486, False),
(-1.7280423552946345, False),
(-1.730857114332327, False),
(-1.734724990607189, False),
(-1.738969101732358, False),
(-1.7389720536793714, False),
(-1.7394984021515705, False),
(-1.7536660864534905, False),
(-1.7619783891209644, False),
(-1.7648321036670689, False),
(-1.7660735015336844, False),
(-1.7704547483828348, False),
(-1.7734077815256275, False),
(-1.7821411512020546, False),
(-1.7839661768040533, False),
(-1.7878423507975065, False),
(-1.7929719135782665, False),
(-1.805490158654243, False),
(-1.806366438477443, False),
(-1.8082578133637006, False),
(-1.8137963335051284, False),
(-1.838628011974783, False),
(-1.8536121873756517, False),
(-1.8768331687309887, False),
(-1.8820983943572602, False),
(-1.8853964420613112, False),
(-1.8862401490818406, False),
(-1.8995274435842806, False),
(-1.905094967475676, False),
(-1.9103699957572666, False),
(-1.9257948159961864, False),
(-1.9275889232234675, False),
(-1.938933360325183, False),
(-1.9456314867792175, False),
(-1.9492333350673672, False),
(-1.9645711895956366, False),
(-1.9670295315401098, False),
(-1.969229256270903, False),
(-1.9721738766699994, False),
(-1.973819100264709, False),
(-1.9766175055575215, False),
(-1.9827047402240978, False),
(-1.9847165655929773, False),
(-1.9896787188528613, False),
(-1.990752560697795, False),
(-1.991197690415773, False),
(-1.9915953007328606, False),
(-1.9966494517020834, False),
(-1.999466820975684, False),
(-2.0017453942093337, True),
(-2.0135148027163727, False),
(-2.015766598103091, False),
(-2.0185719931725172, False),
(-2.0379849947853246, False),
(-2.0471319740421534, False),
(-2.049345614538491, False),
(-2.0521694054227586, False),
(-2.066166835863394, False),
(-2.0698498101618816, False),
(-2.071039028439517, False),
(-2.077289824792122, False),
(-2.0798233280791356, False),
(-2.0833470870211643, False),
(-2.0885984845217855, False),
(-2.1038090009780706, False),
(-2.1180446043532366, False),
(-2.119029285868915, False),
(-2.1239640374743254, False),
(-2.1256616013766805, False),
(-2.1270359510783194, False),
(-2.134903219357754, False),
(-2.1517789253561257, False),
(-2.1532900718063597, False),
(-2.1622329904456747, False),
(-2.165573509099502, False),
(-2.1721605061122, False),
(-2.1740501959146283, False),
(-2.176185758062802, False),
(-2.199304453571677, False),
(-2.201822879555259, False),
(-2.207230786574686, False),
(-2.2170816665824518, False),
(-2.2190645255009165, False),
(-2.2222858113849835, False),
(-2.2231791096292746, False),
(-2.2242776080587787, False),
(-2.2359043318162244, False),
(-2.2392279451299695, False),
(-2.243462078712813, False),
(-2.2446359900560795, False),
(-2.253718237315473, False),
(-2.2557520395971555, False),
(-2.257423720824498, False),
(-2.2600823532956356, False),
(-2.2755448408562833, False),
(-2.282741483889501, False),
(-2.283981292392956, False),
(-2.2876027157732866, False),
(-2.2919846395359142, False),
(-2.2936638842665205, False),
(-2.2976319948522135, False),
(-2.3042370935192653, False),
(-2.308656779669676, False),
(-2.324474206063708, False),
(-2.32751999798672, False),
(-2.3363060862551923, False),
(-2.341726025140001, False),
(-2.3652436613571663, False),
(-2.372244321705121, False),
(-2.378019516560769, False),
(-2.3826706206044683, False),
(-2.400609484588313, False),
(-2.402024620819736, False),
(-2.4088991215669844, False),
(-2.4227753331635484, False),
(-2.4425585888484855, False),
(-2.444054430256326, False),
(-2.4500790163056663, False),
(-2.4573595445859344, False),
(-2.4839015970683245, False),
(-2.484443893034727, False),
(-2.487995540085468, False),
(-2.5095935274076635, False),
(-2.5121703175438763, False),
(-2.512836634430942, False),
(-2.526024646636899, False),
(-2.5392869615424956, False),
(-2.5498574098748636, False),
(-2.580856431583131, False),
(-2.586708380018444, False),
(-2.5971356935604297, False),
(-2.6095595959104148, False),
(-2.617792129558355, False),
(-2.6478170424856926, False),
(-2.64879971596852, False),
(-2.6714731192999364, False),
(-2.6887077757048767, False),
(-2.6906536936299204, False),
(-2.6982103841020755, False),
(-2.7102175654793643, False),
(-2.7102175654793643, False),
(-2.7201629595318413, False),
(-2.735684193364576, False),
(-2.7424268446190654, False),
(-2.7667356941498733, False),
(-2.7851477923396963, False),
(-2.787145373528966, False),
(-2.7893285791152196, False),
(-2.7935669402502907, False),
(-2.7936597080265266, False),
(-2.8119998054444086, False),
(-2.81862067070448, False),
(-2.8210132305060047, False),
(-2.8275434877465755, False),
(-2.881619618024036, False),
(-2.8817705809378604, False),
(-2.8888790274186427, False),
(-2.890885936789966, False),
(-2.8986316624796724, False),
(-2.941759547451118, False),
(-2.9649338626062516, False),
(-2.996917304123262, False),
(-3.0410545357863743, False),
(-3.0410881530741576, False),
(-3.043895523036807, False),
(-3.0659130914067414, False),
(-3.200102072958202, False),
(-3.278733412718966, False),
(-3.309379143357375, False),
(-3.311700277684237, False),
(-3.3196357740600644, False),
(-3.320924965669385, False),
(-3.370056075319684, False),
(-3.378300629126202, False),
(-3.3873922930626814, False),
(-3.426479354670505, False),
(-3.4344318640337006, False),
(-3.447156031921008, False),
(-3.48311574492906, False),
(-3.5056359320006494, False),
(-3.5170444601065953, False),
(-3.52451134450975, False),
(-3.527812039542597, False),
(-3.527919834916838, False),
(-3.534492089719588, False),
(-3.565314207362008, False),
(-3.572045927145758, False),
(-3.5985742808168464, False),
(-3.620963387935, False),
(-3.644070538318951, True),
(-3.679777517963801, False),
(-3.6988264157112805, False),
(-3.741131493564024, False),
(-3.762196216300345, False),
(-3.832428126849643, False),
(-3.883506394489693, False),
(-3.898613346605582, False),
(-3.9597134104566467, False),
(-3.9752424489364206, False),
(-4.070826071794286, False),
(-4.092927193314985, False),
(-4.188596534704666, False),
(-4.215714414008602, False),
(-4.280518818282889, False),
(-4.358287675133794, False),
(-4.506986436128561, False),
(-4.507615189492087, False),
(-4.513325063109716, False),
(-4.557015784355493, False),
(-4.760999958511076, False),
(-4.851814348319181, False),
(-4.898081317318941, False),
(-4.936464675466847, False),
(-4.936620733286103, False),
(-4.969286350247987, False),
(-5.15956968108973, False),
(-5.275647079800404, False),
(-5.281206733279072, False),
(-5.313375856744507, False),
(-5.53447749009124, False),
(-5.643022597263824, False),
(-5.7746987451715315, False),
(-6.019253301748577, False),
(-6.045457936220422, False),
(-6.049290403033954, False),
(-6.141082438407262, False),
(-6.146900600594105, False),
(-6.208858501042146, False),
(-6.322421021476116, False),
(-6.4218046427478646, False),
(-6.734000608749979, False),
(-7.005423296237225, False),
(-7.006319710114822, False),
(-7.026240294404799, False),
(-7.06563815875756, False),
(-7.215911848576557, True),
(-7.308169392662952, False),
(-7.308460325315547, False),
(-7.395510153391498, False),
(-7.602132329420346, False),
(-8.041399799999773, False),
(-8.136667280668485, False),
(-8.401868506135795, False),
(-8.602327381387656, False),
(-9.305551264301561, False),
(-9.371474153578868, False),
...]
In [71]:
sortedlabels = [x[1] for x in scoreslabels]

In [72]:
sortedlabels

Out[72]:
[False,
False,
False,
False,
False,
True,
True,
False,
False,
True,
False,
True,
True,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
True,
False,
False,
True,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
True,
False,
False,
False,
False,
False,
True,
False,
False,
True,
False,
False,
True,
False,
False,
True,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
True,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
...]
In [73]:
# precision
retrieved = sum(pred)
relevant = sum(ytest)
intersection = sum([y and p for y,p in zip(ytest,pred)])

In [74]:
intersection / retrieved

Out[74]:
0.1407766990291262
In [75]:
# recall
intersection / relevant

Out[75]:
0.7073170731707317
In [76]:
# precision at 10
sum(sortedlabels[:10]) / 10

Out[76]:
0.3
In [ ]: