After creating the Alphabet, we are create the full words that represents the ECG


In [1]:
import psycopg2
from psycopg2.extensions import register_adapter, AsIs
from collections import Counter
import pandas as pd
import numpy as np
from time import time
from sklearn.decomposition import NMF, LatentDirichletAllocation
from sklearn.linear_model import LogisticRegression
np.set_printoptions(suppress=True,precision=10)

In [2]:
def obtainSubjects(dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    select_stament = ("SELECT DISTINCT subject_id "
                      " FROM waveformqrst WHERE centroid IS NOT NULL" # limit 150"
    )
    cur.execute(select_stament)
    subject = []
    for row in cur :
        subject.append(row[0])
    conn.close()
    return subject

In [3]:
def obtainWord(subject,dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    select_stament = ("SELECT centroid "
                      " FROM waveformqrst WHERE subject_id="+str(subject)+" ORDER BY qrtsorder"
    )
    cur.execute(select_stament)
    centroids = ""
    for row in cur :
        centroid = row[0]
        if centroid is not None :
            centroids= centroids+centroid
    conn.close()
    return centroids

In [4]:
def deleteWord(dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    select_stament = "DELETE FROM subjectwords"
    cur.execute(select_stament)
    conn.commit()
    cur.close()
    conn.close()

In [5]:
def instertWord(words,dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    insert_statement = 'INSERT into subjectwords (%s) values %s'
    columns = words.keys()
    values = [words[column] for column in columns]
#    print(cur.mogrify(insert_statement, (AsIs(','.join(columns)), tuple(values))))
    cur.execute(insert_statement, (AsIs(','.join(columns)), tuple(values)))
    conn.commit()
    cur.close()
    conn.close()

In [6]:
def selectWord(dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    select_stament = ("SELECT subject_id,word "
                      " FROM subjectwords WHERE length(word)>1000"
    )
    cur.execute(select_stament)
    select = []
    for row in cur :
        select.append([row[0],row[1]])
    conn.close()
    return select

In [7]:
deleteWord()
subjects = obtainSubjects() 
print(len(subjects))
for subject in subjects :
    word = obtainWord(subject)
    if word is not None:
        words = {'subject_id':subject,'word':word}
        print(len(word),end=":")
        instertWord(words)
        print(words['subject_id'],end=",")


366
3316:3623,19077:16639,1996:7153,83:8985,12695:9070,1474:6901,12801:7009,20229:7442,18536:7492,12464:12217,13516:571,8284:9732,14811:7612,14091:6673,3232:10487,2512:6889,5492:8814,13554:2990,18321:8698,18758:5933,16256:8533,8747:10656,8850:10510,14707:10738,492:7521,10691:3612,4878:8573,9711:2442,21960:8347,12944:1908,13659:11931,7445:7452,2607:3554,19713:4059,1339:7360,19590:4317,17769:6981,16256:20,18828:2148,14355:4068,18616:10595,19579:8198,7236:10209,16901:3745,19691:9425,3950:7522,17238:5336,7210:16172,53:8996,14527:3622,718:7981,7681:9335,18999:8415,25:90495,1165:1802,7:7517,17212:2185,350:17218,10722:10534,62:2228,15762:10766,12702:8009,4408:8936,10929:8087,31:16909,16902:12251,21314:12215,10005:9871,15761:10096,9622:8670,20614:7651,20151:9354,6974:9672,4497:6708,16262:9705,14755:10186,7280:5766,9684:7084,8754:7528,15553:7172,18395:135,4315:16709,7305:9630,1716:7799,6180:4865,14987:7685,15688:7289,2918:17182,20034:7860,10783:16360,20312:9366,13916:4180,10881:8336,985:11951,2595:3863,16388:4656,11172:9398,9636:10013,20585:974,18715:1222,22340:8451,13918:7786,21436:1004,18036:2492,5178:8734,2390:8084,9285:8870,15510:16607,1761:17246,15812:8524,13685:9005,21070:16490,10053:7048,14861:6607,18524:3798,14280:1075,3034:33,11472:7782,18322:5607,14004:4587,5374:16192,10763:9434,18774:4688,15730:16122,4647:1744,2077:9958,11981:7644,539:28065,14083:7371,2548:7448,4175:9949,90:7567,10521:3372,13535:7542,9346:408,20765:2049,15016:7225,10164:2917,10911:8569,3451:8121,12725:16280,10114:1569,2850:9363,12888:10077,15565:8207,12636:8654,17332:1459,13314:10847,16524:11998,8219:8432,12880:3057,16718:7470,19793:9338,16524:8949,15357:8272,12837:4664,16648:9637,4461:9253,13099:7472,2096:2827,12997:11703,17:9356,9123:16881,8635:9967,16990:4462,14465:1528,8695:3768,13930:11852,16796:9460,924:12167,15025:16748,20897:8548,15120:886,15975:16992,1568:9882,20280:10061,14637:2340,1968:17216,113:9685,18764:8467,19303:8674,17216:1531,21925:2317,16988:9494,7773:8557,2852:10686,16346:16336,9044:9518,18593:9148,17250:10604,12217:4420,7509:11757,15293:16511,299:4338,7831:7303,5269:16161,12510:1924,17500:11988,480:7798,2607:7497,626:17372,6032:9951,14851:1414,18795:4448,805:10906,154:9358,14364:8466,8:8115,19553:7422,10929:4786,641:4077,11831:6649,175:8984,15222:3853,3289:9664,14987:9361,15007:16504,13068:9708,2806:4685,9787:9289,1856:17366,16814:793,19126:9965,16814:6914,15462:3886,9285:2224,16054:16949,15639:1144,11068:10856,11292:682,3647:7138,10394:4490,16550:10241,15816:952,1623:2498,77:608,17:8568,6807:6669,4433:6983,521:1123,2174:3764,4505:4188,8591:10247,5927:4805,16225:7224,5524:8363,9834:1226,11400:515,11985:11877,16280:4859,12858:3441,18033:743,20801:8406,7:7136,4688:8461,2340:9642,19665:6868,13577:8964,9433:16961,18900:7666,5108:618,16886:10433,2803:7432,1411:10689,12637:7263,16801:8318,14054:4329,14754:20448,7419:7328,14388:10782,1734:17262,19285:8989,15274:462,10916:6917,35:7977,5673:7265,8586:10564,9623:9393,7551:8932,8965:1650,59:7339,15433:9176,1185:625,11853:9847,1859:11827,13673:2946,34:7234,19000:7217,12449:1029,16971:9555,15419:9667,9822:7183,541:17401,11826:10289,14517:9269,16064:2246,15796:1941,19450:3521,2923:3340,3175:17058,5196:317,13374:8231,10543:6876,3495:85,4395:9036,2164:17092,11127:9615,17689:9783,143:17018,15443:2514,5806:9891,16052:736,2442:11684,20527:9251,4100:6841,16172:9330,13418:7512,16785:8122,12775:638,14837:9998,8:7262,3050:427,340:17075,19426:10432,10416:7320,19835:9389,10641:377,19884:2172,16372:9043,19071:7125,5588:6636,10900:91428,15043:1160,11229:9021,9598:9297,15277:7894,17103:8749,9915:3935,17050:749,13359:7400,15193:9105,4972:9526,18068:283,13441:8990,11924:6945,18171:7683,91:2274,13688:2467,10:6075,15127:11764,10176:7175,59:10030,4053:328,11442:99992,938:11907,4225:10655,8348:10042,10489:3642,12300:263,180:7910,14285:12319,11155:8040,1097:16447,19887:3571,12585:8871,17999:12078,

In [8]:
def get_all_substrings(input_string,length=5):
    substrings = []
    for j in range(len(input_string)) :
        for i in range(length) :
            substrings.append(input_string[j:j+i+1])
    return Counter(substrings)

In [9]:
def existMatrix(word,subject,dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    select_stament = ("SELECT 1 "
                      " FROM matrix WHERE subject_id='"+str(subject)+"' AND word='"+str(word)+"'"
    )
    cur.execute(select_stament)
    exist = False
    for row in cur :
        exist = True
    cur.close()
    conn.close()
    return exist

In [10]:
def saveMatrix(matrix,dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    insert_statement=('INSERT INTO matrix(word,subject_id,counting)'
                      ' SELECT unnest( %(word)s ) ,'
                      ' unnest( %(subject_id)s) ,'
                      ' unnest( %(counting)s)')
    word=[r['word'] for r in matrix]
    subject_id=[r['subject_id'] for r in matrix]
    counting=[r['counting'] for r in matrix]
#    print(cur.mogrify(insert_statement,locals()))
    cur.execute(insert_statement,locals())
    conn.commit()
    cur.close()
    conn.close()

In [11]:
def cleanMatrix(dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    select_stament = ("DELETE "
                      " FROM matrix"
    )
    cur.execute(select_stament)
    conn.commit()
    cur.close()
    conn.close()

In [12]:
words = selectWord()
cleanMatrix()
i=0
for word in words :
    subject = word[0]
    subs =get_all_substrings(word[1],length=10)
    matrix = []
    for key in subs:
        matrix.append({'word':key,'counting':subs[key],'subject_id':subject})
#        if not existMatrix(key,subject) :
    if matrix != [] :
        print(i,end=",")
        i=i+1
        saveMatrix(matrix)
#    print(subs.keys())


0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,

In [13]:
def selectMatrix(dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    select_stament = ("SELECT subject_id,word,counting "
                      " FROM matrix ORDER BY subject_id"
    )
    cur.execute(select_stament)
    select = []
    for row in cur :
        select.append((row))
    cur.close()
    conn.close()
    return select

In [14]:
labels = ['subject_id', 'Word', 'Counting']
df = pd.DataFrame.from_records(selectMatrix(), columns=labels)
table = pd.pivot_table(df,index=["subject_id"],columns=["Word"],values=["Counting"],
                       aggfunc={"Counting":[np.sum]},fill_value=0)
print(table)


           Counting                                                      \
                sum                                                       
Word              a     aa    aaa   aaaa  aaaaa aaaaaa aaaaaaa aaaaaaaa   
subject_id                                                                
20            16265  16263  16261  16259  16257  16255   16253    16251   
33             3038   3031   3024   3017   3010   3003    2996     2989   
85             2821   2319   1941   1651   1426   1241    1085      957   
135           18404  18402  18400  18398  18396  18394   18392    18390   
263           12308  12305  12302  12299  12296  12293   12290    12287   
283           18065  18051  18037  18024  18011  17998   17986    17974   
317            5189   5182   5175   5168   5162   5156    5150     5144   
328            4026   3988   3952   3918   3888   3859    3832     3806   
377           10644  10636  10628  10621  10614  10607   10600    10593   
408            9352   9348   9344   9340   9336   9332    9328     9324   
427            3059   3057   3055   3053   3051   3049    3047     3045   
462           15277  15269  15261  15253  15245  15237   15229    15221   
515           10942  10489  10059   9645   9249   8865    8510     8172   
571           13506  13486  13467  13449  13431  13413   13395    13377   
618            5117   5115   5113   5111   5109   5107    5105     5103   
625            1194   1192   1190   1188   1186   1184    1182     1180   
638           12780  12774  12768  12762  12756  12750   12744    12738   
682           11294  11285  11276  11267  11258  11249   11240    11232   
736           16033  16003  15973  15943  15913  15883   15853    15824   
743           18037  18030  18023  18016  18009  18002   17995    17988   
749           17051  17041  17031  17022  17013  17004   16995    16986   
793           16821  16817  16813  16809  16805  16801   16797    16793   
886           15128  15125  15122  15119  15116  15113   15110    15107   
952           15822  15817  15812  15807  15802  15797   15792    15787   
974           20592  20588  20584  20580  20576  20572   20568    20564   
1004          21445  21443  21441  21439  21437  21435   21433    21431   
1029          12454  12448  12442  12436  12430  12424   12418    12412   
1075          14287  14283  14279  14275  14271  14267   14263    14259   
1144          15626  15602  15578  15554  15530  15506   15482    15458   
1160          15048  15044  15041  15038  15035  15032   15029    15026   
...             ...    ...    ...    ...    ...    ...     ...      ...   
12319         14294  14292  14290  14288  14286  14284   14282    14280   
16122         15737  15733  15729  15725  15721  15717   15713    15709   
16161          5269   5258   5248   5238   5228   5218    5208     5198   
16172          7203   7185   7168   7151   7134   7117    7100     7083   
16192          5383   5381   5379   5377   5375   5373    5371     5369   
16280         12715  12694  12674  12654  12634  12614   12594    12574   
16336         16313  16270  16228  16186  16146  16106   16066    16027   
16360         10792  10790  10788  10786  10784  10782   10780    10778   
16447          1105   1102   1099   1096   1094   1092    1090     1088   
16490         21073  21065  21057  21049  21041  21033   21025    21017   
16504         15016  15014  15012  15010  15008  15006   15004    15002   
16511         15292  15280  15268  15256  15244  15232   15220    15208   
16607         15518  15515  15512  15509  15506  15503   15500    15497   
16639         19078  19068  19058  19048  19038  19028   19018    19008   
16709          4302   4278   4254   4230   4206   4182    4158     4134   
16748         15029  15022  15015  15008  15001  14995   14989    14983   
16881          9124   9115   9106   9097   9088   9079    9071     9063   
16949         16060  16056  16052  16048  16044  16040   16036    16032   
16961          9417   9390   9363   9336   9309   9282    9255     9228   
16992         15980  15974  15968  15962  15956  15950   15944    15938   
17058          3178   3170   3162   3154   3146   3138    3130     3122   
17092          2172   2169   2166   2163   2160   2157    2154     2151   
17182          2927   2925   2923   2921   2919   2917    2915     2913   
17216          1975   1971   1967   1963   1959   1955    1951     1947   
17246          1770   1768   1766   1764   1762   1760    1758     1756   
17262          1740   1735   1730   1725   1720   1715    1710     1705   
17366          1865   1863   1861   1859   1857   1855    1853     1851   
20448         14693  14622  14555  14491  14427  14363   14299    14235   
91428         10882  10853  10824  10795  10766  10733   10706    10680   
99992          6294   3791   2484   1814   1447   1233    1094      990   

                                   ...                                         \
                                   ...                                          
Word       aaaaaaaaa aaaaaaaaaa    ...     hhhcffbd hhhcffbdb hhhcffbdba hhhd   
subject_id                         ...                                          
20             16249      16247    ...            0         0          0    0   
33              2983       2977    ...            0         0          0    0   
85               847        759    ...            0         0          0    0   
135            18388      18386    ...            0         0          0    0   
263            12284      12281    ...            0         0          0    0   
283            17963      17952    ...            0         0          0    0   
317             5138       5133    ...            0         0          0    0   
328             3780       3755    ...            0         0          0    0   
377            10586      10579    ...            0         0          0    0   
408             9320       9316    ...            0         0          0    0   
427             3043       3041    ...            0         0          0    0   
462            15213      15205    ...            0         0          0    0   
515             7852       7542    ...            0         0          0    0   
571            13360      13343    ...            0         0          0    0   
618             5101       5099    ...            0         0          0    0   
625             1178       1176    ...            0         0          0    0   
638            12732      12726    ...            0         0          0    0   
682            11224      11216    ...            0         0          0    0   
736            15795      15766    ...            0         0          0    0   
743            17981      17974    ...            0         0          0    0   
749            16977      16968    ...            0         0          0    0   
793            16789      16785    ...            0         0          0    0   
886            15104      15101    ...            0         0          0    0   
952            15782      15777    ...            0         0          0    0   
974            20560      20556    ...            0         0          0    0   
1004           21429      21427    ...            0         0          0    0   
1029           12406      12400    ...            0         0          0    0   
1075           14255      14251    ...            0         0          0    0   
1144           15434      15410    ...            0         0          0    0   
1160           15023      15020    ...            0         0          0    0   
...              ...        ...    ...          ...       ...        ...  ...   
12319          14278      14276    ...            0         0          0    0   
16122          15705      15701    ...            0         0          0    0   
16161           5188       5178    ...            0         0          0    0   
16172           7066       7049    ...            0         0          0    0   
16192           5367       5365    ...            0         0          0    0   
16280          12554      12535    ...            0         0          0    0   
16336          15988      15949    ...            0         0          0    0   
16360          10776      10774    ...            0         0          0    0   
16447           1086       1084    ...            0         0          0    0   
16490          21009      21001    ...            0         0          0    0   
16504          15000      14998    ...            0         0          0    0   
16511          15196      15184    ...            0         0          0    0   
16607          15494      15491    ...            0         0          0    0   
16639          18998      18989    ...            0         0          0    0   
16709           4110       4086    ...            0         0          0    0   
16748          14977      14971    ...            0         0          0    0   
16881           9055       9047    ...            0         0          0    0   
16949          16028      16024    ...            0         0          0    0   
16961           9201       9174    ...            0         0          0    0   
16992          15932      15926    ...            0         0          0    0   
17058           3114       3106    ...            0         0          0    0   
17092           2148       2145    ...            0         0          0    0   
17182           2911       2909    ...            0         0          0    0   
17216           1943       1939    ...            0         0          0    0   
17246           1754       1752    ...            0         0          0    0   
17262           1700       1695    ...            0         0          0    0   
17366           1849       1847    ...            0         0          0    0   
20448          14171      14108    ...            0         0          0    0   
91428          10654      10628    ...            0         0          0    0   
99992            914        859    ...            0         0          0    0   

                                                               
                                                               
Word       hhhdb hhhdbb hhhdbbb hhhdbbba hhhdbbbab hhhdbbbabe  
subject_id                                                     
20             0      0       0        0         0          0  
33             0      0       0        0         0          0  
85             0      0       0        0         0          0  
135            0      0       0        0         0          0  
263            0      0       0        0         0          0  
283            0      0       0        0         0          0  
317            0      0       0        0         0          0  
328            0      0       0        0         0          0  
377            0      0       0        0         0          0  
408            0      0       0        0         0          0  
427            0      0       0        0         0          0  
462            0      0       0        0         0          0  
515            0      0       0        0         0          0  
571            0      0       0        0         0          0  
618            0      0       0        0         0          0  
625            0      0       0        0         0          0  
638            0      0       0        0         0          0  
682            0      0       0        0         0          0  
736            0      0       0        0         0          0  
743            0      0       0        0         0          0  
749            0      0       0        0         0          0  
793            0      0       0        0         0          0  
886            0      0       0        0         0          0  
952            0      0       0        0         0          0  
974            0      0       0        0         0          0  
1004           0      0       0        0         0          0  
1029           0      0       0        0         0          0  
1075           0      0       0        0         0          0  
1144           0      0       0        0         0          0  
1160           0      0       0        0         0          0  
...          ...    ...     ...      ...       ...        ...  
12319          0      0       0        0         0          0  
16122          0      0       0        0         0          0  
16161          0      0       0        0         0          0  
16172          0      0       0        0         0          0  
16192          0      0       0        0         0          0  
16280          0      0       0        0         0          0  
16336          0      0       0        0         0          0  
16360          0      0       0        0         0          0  
16447          0      0       0        0         0          0  
16490          0      0       0        0         0          0  
16504          0      0       0        0         0          0  
16511          0      0       0        0         0          0  
16607          0      0       0        0         0          0  
16639          0      0       0        0         0          0  
16709          0      0       0        0         0          0  
16748          0      0       0        0         0          0  
16881          0      0       0        0         0          0  
16949          0      0       0        0         0          0  
16961          0      0       0        0         0          0  
16992          0      0       0        0         0          0  
17058          0      0       0        0         0          0  
17092          0      0       0        0         0          0  
17182          0      0       0        0         0          0  
17216          0      0       0        0         0          0  
17246          0      0       0        0         0          0  
17262          0      0       0        0         0          0  
17366          0      0       0        0         0          0  
20448          0      0       0        0         0          0  
91428          0      0       0        0         0          0  
99992          0      0       0        0         0          0  

[327 rows x 136291 columns]

In [15]:
# Fit the NMF model
t0 = time()
nmf = NMF(n_components=30, random_state=1,alpha=.1, l1_ratio=.5)
W = nmf.fit_transform(table)
H = nmf.components_
print(W)
print("done in %0.3fs." % (time() - t0))


[[ 59.7198433777   0.             0.           ...,   0.             0.
    0.          ]
 [ 10.9425792887   0.2777407337   0.0001579825 ...,   0.0019648461   0.
    0.          ]
 [  2.738067762   17.8686213274   0.4898717575 ...,   0.             0.
    0.2518760099]
 ..., 
 [ 51.8583587917   2.7670185946   0.0019755654 ...,   0.9659574204
    0.0096008726   0.          ]
 [ 39.0660364907   1.2347535354   0.007121405  ...,   0.2243629173   0.
    0.          ]
 [  2.7443450367  23.4069701784   6.4158242254 ...,   0.4552525055
    5.5139710128   0.          ]]
done in 509.078s.

In [16]:
print(np.shape(W))
print(np.shape(H))


(327, 30)
(30, 136291)

In [17]:
def patientIsAlive(patient,dbname="mimic") :
    conn = psycopg2.connect("dbname="+dbname)
    cur = conn.cursor()
    select_stament = ("SELECT dod "
                      " FROM patients WHERE subject_id = "+str(patient)
    )
    cur.execute(select_stament)
    select = []
    for row in cur :
        select.append(1 if row[0] is not None else 0 )
    cur.close()
    conn.close()
    return select

In [18]:
patients = []
for patient in table.index :
    patients.append(patientIsAlive(patient)[0])
print(len(patients))


327

In [19]:
# flatten y into a 1-D array
y = np.ravel(patients)
modelo_lr = LogisticRegression()
modelo_lr.fit(y=y,X=W)


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

In [20]:
modelo_lr.score(W, y)


Out[20]:
0.58409785932721714

In [21]:
y.mean()


Out[21]:
0.54434250764525993

In [25]:
predicion = modelo_lr.predict(W)
print(W[:1])
print(predicion,y[:1])


[[ 59.7198433777   0.             0.             0.             0.             0.
    0.             0.             0.             0.             0.             0.
    0.             0.             0.             0.             0.             0.
    0.             0.             0.             0.             0.
    0.0586727148   0.3381246636   0.             0.             0.             0.
    0.          ]]
[1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1
 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 0 1 0 0 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1
 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1
 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1
 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 0 1 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1
 1 0 0 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0] [0]

In [23]:
modelo_lr


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

In [24]:
y


Out[24]:
array([0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1,
       1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1,
       1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0,
       1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0,
       1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
       0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0,
       1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0,
       1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1,
       0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1,
       0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1,
       0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0,
       1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0,
       0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1,
       0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0,
       0, 1, 1, 0, 0])

In [ ]: