# Notebook from TylerKirby/latin-pos-tagging
Path: .ipynb_checkpoints/Classical Tagger Training-checkpoint.ipynb

<code>
import glob_____no_output_____# sample https://github.com/TylerKirby/latin-pos-tagging/blob/master/texts/perseus/phi0448.phi001.perseus-lat1.tb.txt
paths = glob.glob('./texts/perseus/*.txt')
print(len(paths))
word_list = []
for p in paths:
    #sample_text_path = "./texts/perseus/phi0448.phi001.perseus-lat1.tb.txt"
    file = open(p)
    text = file.read()
    text.replace('?', '.')
    text.replace('!', '.')
    text.strip('\n')
    sentence_list = text.split('.')
    strip = {'',',',';'}
    for sent in sentence_list:
        words = sent.split(' ')
        tuple_list = []
        for word in words:
            word_tag_pair = word.split('/')
            if (len(word_tag_pair) == 2) and (word_tag_pair[0] not in strip):
                tuple_list.append( (word_tag_pair[0], word_tag_pair[1]) )
        if len(tuple_list) > 0:
            word_list.append(tuple_list)12
print(len(word_list))3434
print(word_list)[[('Cum', 'c--------'), ('esset', 'v3sisa---'), ('Caesar', 'n-s---mn-'), ('in', 'r--------'), ('citeriore', 'a-s---fbc'), ('Gallia', 'n-s---fb-'), ('in', 'r--------'), ('hibernis', 'a-p---nb-'), ('ita', 'd--------'), ('uti', 'c--------'), ('supra', 'd--------'), ('demonstravimus', 'v1pria---'), ('crebri', 'a-p---mn-'), ('ad', 'r--------'), ('eum', 'p-s---ma-'), ('rumores', 'n-p---mn-'), ('adferebantur', 'v3piip---'), ('litteris', 'n-p---fb-'), ('-que', 'c--------'), ('item', 'd--------'), ('Labieni', 'n-s---mg-'), ('certior', 'a-s---mnc'), ('fiebat', 'v3siia---'), ('omnes', 'a-p---ma-'), ('Belgas', 'n-p---ma-'), ('quam', 'p-s---fa-'), ('tertiam', 'm-s---fa-'), ('esse', 'v--pna---'), ('Galliae', 'n-s---fg-'), ('partem', 'n-s---fa-'), ('dixeramus', 'v1plia---'), ('contra', 'r--------'), ('populum', 'n-s---ma-'), ('Romanum', 'a-s---ma_'), ('coniurare', 'v--pna---'), ('obsides', 'n-p---ma-'), ('-que', 'c--------'), ('inter', 'r--------'), ('se', 'p-p---ma-'), ('dare', 'v--pna---')], [('\nConiurandi', 'v___d_-g-'), ('has', 'p-p---fa-'), ('esse', 'v--pna---'), ('causas', 'n-p---fa-'), ('primum', 'd-------_'), ('quod', 'c--------'), ('vererentur', 'v3pisd---'), ('ne', 'c--------'), ('omni', 'a-s---fb-'), ('pacata', 'v-srppfb-'), ('Gallia', 'n-s---fb-'), ('ad', 'r--------'), ('eos', 'p-p---ma-'), ('exercitus', 'n-s---mn-'), ('noster', 'p-s---mn-'), ('adduceretur', 'v3sisp---'), ('\ndeinde', 'd--------'), ('quod', 'c--------'), ('ab', 'r--------'), ('non', 'd--------'), ('nullis', 'a-p---mb-'), ('Gallis', 'n-p---mb-'), ('sollicitarentur', 'v3pisp---'), ('partim', 'd--------'), ('qui', 'p-p---mn-'), ('ut', 'c--------'), ('Germanos', 'n-p---ma-'), ('diutius', 'd-------c'), ('in', 'r--------'), ('Gallia', 'n-s---fb-'), ('versari', 'v--pnp---'), ('noluerant', 'v3plia---'), ('ita', 'd--------'), ('populi', 'n-s---mg-'), ('Romani', 'a-s---mg-'), ('exercitum', 'n-s---ma-'), ('hiemare', 'v--pna---'), ('atque', 'c--------'), ('inveterascere', 'v--pna---'), ('in', 'r--------'), ('Gallia', 'n-s---fb-'), ('moleste', 'd--------'), ('ferebant', 'v3piia---'), ('partim', 'd--------'), ('qui', 'p-p---mn-'), ('mobilitate', 'n-s---fb-'), ('et', 'c--------'), ('levitate', 'n-s---fb-'), ('animi', 'n-s---mg-'), ('novis', 'a-p---nd-'), ('imperiis', 'n-p---nd-'), ('studebant', 'v3piia---'), ('\nab', 'r--------'), ('non', 'd--------'), ('nullis', 'a-p---mb-'), ('etiam', 'd--------'), ('quod', 'c--------'), ('in', 'r--------'), ('Gallia', 'n-s---fb-'), ('a', 'r--------'), ('potentioribus', 'v-pppambc'), ('atque', 'c--------'), ('iis', 'p-p---mb-'), ('qui', 'p-p---mn-'), ('ad', 'r--------'), ('conducendos', 'v-p-g-ma-'), ('homines', 'n-p---ma-'), ('facultates', 'n-p---fa-'), ('habebant', 'v3piia---'), ('vulgo', 'd-------_'), ('regna', 'n-p---nn-'), ('occupabantur', 'v3piip---'), ('sollicitarentur', 'v3pisp---'), ('\nqui', 'p-p---mn-'), ('minus', 'd-------c'), ('facile', 'd--------'), ('eam', 'p-s---fa-'), ('rem', 'n-s---fa-'), ('imperio', 'n-s---nb-'), ('nostro', 'p-s---nb-'), ('consequi', 'v--pnd---'), ('poterant', 'v3piia---')], [('\nHis', 'p-p---nb-'), ('nuntiis', 'a-p---nb-'), ('litteris', 'n-p---fb-'), ('-que', 'c--------'), ('commotus', 'v-srppmn-'), ('Caesar', 'n-s---mn-'), ('duas', 'm-p---fa-'), ('legiones', 'n-p---fa-'), ('in', 'r--------'), ('citeriore', 'a-s---fbc'), ('Gallia', 'n-s---fb-'), ('novas', 'a-p---fa-'), ('conscripsit', 'v3sria---'), ('et', 'c--------'), ('inita', 'v-srppfb-'), ('aestate', 'n-s---fb-'), ('in', 'r--------'), ('ulteriorem', 'a-s---fac'), ('Galliam', 'n-s---fa-'), ('qui', 'p-s---mn-'), ('deduceret', 'v3sisa---'), ('Q', 'n-s---ma-'), ('Pedium', 'n-s---ma-'), ('legatum', 'n-s---ma-'), ('misit', 'v3sria---')], [('\nIpse', 'p-s---mn-'), ('cum', 'c--------'), ('primum', 'd--------'), ('pabuli', 'n-s---ng-'), ('copia', 'n-s---fn-'), ('esse', 'v--pna---'), ('inciperet', 'v3sisa---'), ('ad', 'r--------'), ('exercitum', 'n-s---ma-'), ('venit', 'v3sria---')], [('\nDat', 'v3spia---'), ('negotium', 'n-s---na-'), ('Senonibus', 'n-p---md-'), ('reliquis', 'a-p---md-'), ('-que', 'c--------'), ('Gallis', 'n-p---md-'), ('qui', 'p-s---mn-'), ('finitimi', 'a-p---mn-'), ('Belgis', 'n-p---md-'), ('erant', 'v3piia---'), ('uti', 'c--------'), ('ea', 'p-p---na-'), ('quae', 'p-p---nn-'), ('apud', 'r--------'), ('eos', 'p-p---ma-'), ('gerantur', 'v3ppsp---'), ('cognoscant', 'v3ppsa---'), ('se', 'p-s---ma-'), ('-que', 'c--------'), ('de', 'r--------'), ('his', 'p-p---fb-'), ('rebus', 'n-p---fb-'), ('certiorem', 'a-s---mac'), ('faciant', 'v3ppsa---')], [('\nHi', 'p-p---mn-'), ('constanter', 'd-------_'), ('omnes', 'a-p---mn-'), ('nuntiaverunt', 'v3pria---'), ('manus', 'n-p---fa-'), ('cogi', 'v--pnp---'), ('exercitum', 'n-s---ma-'), ('in', 'r--------'), ('unum', 'm-s---ma-'), ('locum', 'n-s---ma-'), ('conduci', 'v--pnp---')], [('\nTum', 'd--------'), ('vero', 'd--------'), ('dubitandum', 'v-spgpna-'), ('non', 'd--------'), ('existimavit', 'v3sria---'), ('quin', 'c--------'), ('ad', 'r--------'), ('eos', 'p-p---ma-'), ('proficisceretur', 'v3sisp---')], [('esse', 'v--pna---'), ('\nRe', 'n-s---fb-'), ('frumentaria', 'a-s---fb-'), ('provisa', 'v-srppfb-'), ('castra', 'n-p---na-'), ('movet', 'v3spia---'), ('diebus', 'n-p---mb-'), ('-que', 'c--------'), ('circiter', 'd--------'), ('XV', 'm-_---__-'), ('ad', 'r--------'), ('fines', 'n-p---fa-'), ('Belgarum', 'n-p---mg-'), ('pervenit', 'v3spia---')], [('\nEo', 'd--------'), ('cum', 'c--------'), ('de', 'r--------'), ('improviso', 'a-s---nb-'), ('celerius', 'd-------c'), ('-que', 'c--------'), ('omnium', 'a-p---mg-'), ('opinione', 'n-s---fb-'), ('venisset', 'v3slsa---'), ('Remi', 'n-p---mn-'), ('qui', 'p-p---mn-'), ('proximi', 'a-p---mns'), ('Galliae', 'n-s---fd-'), ('ex', 'r--------'), ('Belgis', 'n-p---mb-'), ('sunt', 'v3ppia---'), ('ad', 'r--------'), ('eum', 'p-s---ma-'), ('legatos', 'n-p---ma-'), ('Iccium', 'n-s---ma-'), ('et', 'c--------'), ('Andebrogium', 'n-s---ma-'), ('primos', 'm-p---ma-'), ('civitatis', 'n-s---fg-'), ('miserunt', 'v3pria---'), ('qui', 'p-p---mn-'), ('dicerent', 'v3pisa---'), ('se', 'p-p---ma-'), ('sua', 'p-p---na-'), ('-que', 'c--------'), ('omnia', 'a-p---na-'), ('in', 'r--------'), ('fidem', 'n-s---fa-'), ('atque', 'c--------'), ('potestatem', 'n-s---fa-'), ('populi', 'n-s---mg-'), ('Romani', 'a-s---mg-'), ('permittere', 'v--pna---'), ('neque', 'c--------'), ('se', 'p-p---ma-'), ('cum', 'r--------'), ('reliquis', 'a-p---mb-'), ('Belgis', 'n-p---mb-'), ('consensisse', 'v--rna---'), ('neque', 'c--------'), ('contra', 'r--------'), ('populum', 'n-s---ma-'), ('Romanum', 'a-s---ma-'), ('coniurasse', 'v--rna---'), ('paratos', 'v-prppma-'), ('-que', 'c--------'), ('esse', 'v--pna---'), ('et', 'c--------'), ('obsides', 'n-p---ma-'), ('dare', 'v--pna---'), ('et', 'c--------'), ('imperata', 'v-prppna-'), ('facere', 'v--pna---'), ('et', 'c--------'), ('oppidis', 'n-p---nb-'), ('recipere', 'v--pna---'), ('et', 'c--------'), ('frumento', 'n-s---nb-'), ('ceteris', 'a-p---fb-'), ('-que', 'c--------'), ('rebus', 'n-p---fb-'), ('iuvare', 'v--pna---'), ('\nreliquos', 'a-p---ma-'), ('omnes', 'a-p---ma-'), ('Belgas', 'n-p---ma-'), ('in', 'r--------'), ('armis', 'n-p---nb-'), ('esse', 'v--pna---'), ('Germanos', 'n-p---ma-'), ('-que', 'c--------'), ('qui', 'p-p---mn-'), ('cis', 'r--------'), ('Rhenum', 'n-s---ma-'), ('incolant', 'v3ppsa---'), ('sese', 'p-p---ma-'), ('cum', 'r--------'), ('his', 'p-p---mb-'), ('coniunxisse', 'v--rna---'), ('tantum', 'a-s---ma-'), ('-que', 'c--------'), ('esse', 'v--pna---'), ('eorum', 'p-p---mg-'), ('omnium', 'a-p---mg-'), ('furorem', 'n-s---ma-'), ('ut', 'c--------'), ('ne', 'c--------'), ('Suessiones', 'n-p---ma-'), ('quidem', 'd--------'), ('fratres', 'n-p---ma-'), ('consanguineos', 'a-p---ma-'), ('-que', 'c--------'), ('suos', 'p-p---ma-'), ('qui', 'p-p---mn-'), ('eodem', 'p-s---nb-'), ('iure', 'n-s---nb-'), ('et', 'c--------'), ('isdem', 'p-p---fb-'), ('legibus', 'n-p---fb-'), ('utantur', 'v3ppsp---'), ('unum', 'm-s---na-'), ('imperium', 'n-s---na-'), ('unum', 'm-s---ma-'), ('-que', 'c--------'), ('magistratum', 'n-s---ma-'), ('cum', 'r--------'), ('ipsis', 'p-p---mb-'), ('habeant', 'v3ppsa---'), ('deterrere', 'v--pna---'), ('potuerint', 'v3prsa---'), ('quin', 'c--------'), ('cum', 'r--------'), ('iis', 'p-p---mb-'), ('consentirent', 'v3pisa---')], [('\nCaesar', 'n-s---mn-'), ('Remos', 'n-p---ma-'), ('cohortatus', 'v-srpdmn_'), ('liberaliter', 'd--------'), ('-que', 'c--------'), ('oratione', 'n-s---fb-'), ('prosecutus', 'v-srpdmn_'), ('omnem', 'a-s---ma-'), ('senatum', 'n-s---ma-'), ('ad', 'r--------'), ('se', 'p-s---ma-'), ('convenire', 'v--pna---'), ('principum', 'a-p---mg_'), ('-que', 'c--------'), ('liberos', 'n-p---ma-'), ('obsides', 'n-p---ma-'), ('ad', 'r--------'), ('se', 'p-s---ma-'), ('adduci', 'v--pnp---'), ('iussit', 'v3sria---')], [('\nQuae', 'p-p---nn-'), ('omnia', 'a-p---nn-'), ('ab', 'r--------'), ('his', 'p-p---mb-'), ('diligenter', 'd--------'), ('ad', 'r--------'), ('diem', 'n-s---ma-'), ('facta', 'v-prppnn-'), ('sunt', 'v3ppia---')], [('\nIpse', 'p-s---mn-'), ('Diviciacum', 'n-s---ma-'), ('Haeduum', 'a-s---ma_'), ('magnopere', 'd--------'), ('cohortatus', 'v-srpdmn_'), ('docet', 'v3spia---'), ('quantopere', 'd--------'), ('rei', 'n-s---fg-'), ('publicae', 'a-s---fg-'), ('communis', 'a-s---fg-'), ('-que', 'c--------'), ('salutis', 'n-s---fg-'), ('intersit', 'v3spsa---'), ('manus', 'n-p---fa-'), ('hostium', 'n-p---mg-'), ('distineri', 'v--pnp---'), ('ne', 'c--------'), ('cum', 'r--------'), ('tanta', 'a-s---fb-'), ('multitudine', 'n-s---fb-'), ('uno', 'm-s---nb-'), ('tempore', 'n-s---nb-'), ('confligendum', 'v-s-g-nn-'), ('sit', 'v3spsa---')], [('\nId', 'p-s---na-'), ('fieri', 'v--pnp---'), ('posse', 'v--pna---'), ('si', 'c--------'), ('suas', 'p-p---fa-'), ('copias', 'n-p---fa-'), ('Haedui', 'n-p---mn-'), ('in', 'r--------'), ('fines', 'n-p---ma-'), ('Bellovacorum', 'n-p---mg-'), ('introduxerint', 'v3prsa---'), ('et', 'c--------'), ('eorum', 'p-p---mg-'), ('agros', 'n-p---ma-'), ('populari', 'v--pnd---'), ('coeperint', 'v3prsa---')], [('\nHis', 'p-p---nb-'), ('datis', 'v-prppnb-'), ('mandatis', 'v-prppnb-'), ('eum', 'p-s---ma-'), ('a', 'r--------'), ('se', 'p-s---mb-'), ('dimittit', 'v3spia---')], [('\nPostquam', 'c--------'), ('omnes', 'a-p---fa-'), ('Belgarum', 'n-p---mg-'), ('copias', 'n-p---fa-'), ('in', 'r--------'), ('unum', 'm-s---ma-'), ('locum', 'n-s---ma-'), ('coactas', 'v-prppfa-'), ('ad', 'r--------'), ('se', 'p-s---ma-'), ('venire', 'v--pna---'), ('vidit', 'v3sria---'), ('neque', 'c--------'), ('iam', 'd--------'), ('longe', 'd--------'), ('abesse', 'v--pna---'), ('ab', 'r--------'), ('iis', 'p-p---mb-'), ('quos', 'p-p---ma-'), ('miserat', 'v3slia---'), ('exploratoribus', 'n-p---mb-'), ('et', 'c--------'), ('ab', 'r--------'), ('Remis', 'n-p---mb-'), ('cognovit', 'v3sria---'), ('flumen', 'n-s---na-'), ('Axonam', 'n-s---ma-'), ('quod', 'p-s---nn-'), ('est', 'v3spia---'), ('in', 'r--------'), ('extremis', 'a-p---mbs'), ('Remorum', 'n-p---mg-'), ('finibus', 'n-p---mb-'), ('exercitum', 'n-s---ma-'), ('traducere', 'v--pna---'), ('maturavit', 'v3sria---'), ('atque', 'c--------'), ('ibi', 'd--------'), ('castra', 'n-p---na-'), ('posuit', 'v3sria---')], [('\nQuae', 'p-s---fn-'), ('res', 'n-s---fn-'), ('et', 'c--------'), ('latus', 'n-s---na-'), ('unum', 'm-s---na-'), ('castrorum', 'n-p---ng-'), ('ripis', 'n-p---fb-'), ('fluminis', 'n-s---ng-'), ('muniebat', 'v3siia---'), ('et', 'c--------'), ('post', 'r--------'), ('eum', 'p-s---ma-'), ('quae', 'p-p---nn-'), ('erant', 'v3piia---'), ('tuta', 'v-prpdna_'), ('ab', 'r--------'), ('hostibus', 'n-p---mb-'), ('reddebat', 'v3siia---'), ('et', 'c--------'), ('commeatus', 'n-p---ma-'), ('ab', 'r--------'), ('Remis', 'n-p---mb-'), ('reliquis', 'a-p---fb-'), ('-que', 'c--------'), ('civitatibus', 'n-p---fb-'), ('ut', 'c--------'), ('sine', 'r--------'), ('periculo', 'n-s---nb-'), ('ad', 'r--------'), ('eum', 'p-s---ma-'), ('portari', 'v--pnp---'), ('possent', 'v3pisa---'), ('efficiebat', 'v3siia---')], [('\nIn', 'r--------'), ('eo', 'p-s---nb-'), ('flumine', 'n-s---nb-'), ('pons', 'n-s---mn-'), ('erat', 'v3siia---')], [('\nIbi', 'd--------'), ('praesidium', 'n-s---na-'), ('ponit', 'v3spia---'), ('et', 'c--------'), ('in', 'r--------'), ('altera', 'a-s---fb-'), ('parte', 'n-s---fb-'), ('fluminis', 'n-s---ng-'), ('Q', 'n-s---ma-'), ('Titurium', 'n-s---ma-'), ('Sabinum', 'n-s---ma-'), ('legatum', 'n-s---ma-'), ('cum', 'r--------'), ('sex', 'm--------'), ('cohortibus', 'n-p---fb-'), ('relinquit', 'v3spia---'), ('\ncastra', 'n-p---na-'), ('in', 'r--------'), ('altitudinem', 'n-s---fa-'), ('pedum', 'n-p---mg-'), ('XII', 'm-_---__-'), ('vallo', 'n-s---nb-'), ('fossa', 'n-s---fb-'), ('-que', 'c--------'), ('duodeviginti', 'm--------'), ('pedum', 'n-p---mg-'), ('muniri', 'v--pnp---'), ('iubet', 'v3spia---')], [('\nEo', 'd--------'), ('de', 'r--------'), ('media', 'a-s---fb-'), ('nocte', 'n-s---fb-'), ('Caesar', 'n-s---mn-'), ('isdem', 'p-p---mb-'), ('ducibus', 'n-p---mb-'), ('usus', 'v-srpdmn_'), ('qui', 'p-p---mn-'), ('nuntii', 'n-p---mn-'), ('ab', 'r--------'), ('Iccio', 'n-s---mb-'), ('venerant', 'v3plia---'), ('Numidas', 'n-p---ma-'), ('et', 'c--------'), ('Cretas', 'n-p---ma-'), ('sagittarios', 'n-p---ma-'), ('et', 'c--------'), ('funditores', 'n-p---ma-'), ('Baleares', 'a-p---ma_'), ('subsidio', 'n-s---nd-'), ('oppidanis', 'n-p---md-'), ('mittit', 'v3spia---'), ('\nquorum', 'p-p---mg-'), ('adventu', 'n-s---mb-'), ('et', 'c--------'), ('Remis', 'n-p---md-'), ('cum', 'r--------'), ('spe', 'n-s---fb-'), ('defensionis', 'n-s---fg-'), ('studium', 'n-s---nn-'), ('propugnandi', 'v___d_-g-'), ('accessit', 'v3sria---'), ('et', 'c--------'), ('hostibus', 'n-p---mb-'), ('eadem', 'p-s---fb-'), ('de', 'r--------'), ('causa', 'n-s---fb-'), ('spes', 'n-s---fn-'), ('potiundi', 'v-s-g-ng-'), ('oppidi', 'n-s---ng-'), ('discessit', 'v3sria---')], [('\nItaque', 'c--------'), ('paulisper', 'd--------'), ('apud', 'r--------'), ('oppidum', 'n-s---na-'), ('morati', 'v-prpdmn_'), ('agros', 'n-p---ma-'), ('-que', 'c--------'), ('Remorum', 'n-p---mg-'), ('depopulati', 'v-prpdmn_'), ('omnibus', 'a-p---mb-'), ('vicis', 'n-p---mb-'), ('aedificiis', 'n-p---nb-'), ('-que', 'c--------'), ('quo', 'd--------'), ('adire', 'v--pna---'), ('potuerant', 'v3plia---'), ('incensis', 'v-prppnb-'), ('ad', 'r--------'), ('castra', 'n-p---na-'), ('Caesaris', 'n-s---mg-'), ('omnibus', 'a-p---fb-'), ('copiis', 'n-p---fb-'), ('contenderunt', 'v3pria---'), ('et', 'c--------'), ('a', 'r--------'), ('milibus', 'm-p---nb-'), ('passuum', 'n-p---mg-'), ('minus', 'd-------c'), ('duobus', 'm-p---nb-'), ('castra', 'n-p---na-'), ('posuerunt', 'v3pria---'), ('\nquae', 'p-p---nn-'), ('castra', 'n-p---nn-'), ('ut', 'c--------'), ('fumo', 'n-s---mb-'), ('atque', 'c--------'), ('ignibus', 'n-p---mb-'), ('significabatur', 'v3siip---'), ('amplius', 'd-------c'), ('milibus', 'm-p---nb-'), ('passuum', 'n-p---mg-'), ('VIII', 'm-_---__-'), ('latitudinem', 'n-s---fa-'), ('patebant', 'v3piia---')], [('\nPalus', 'n-s---fn-'), ('erat', 'v3siia---'), ('non', 'd--------'), ('magna', 'a-s---fn-'), ('inter', 'r--------'), ('nostrum', 'p-s---ma-'), ('atque', 'c--------'), ('hostium', 'n-p---mg-'), ('exercitum', 'n-s---ma-')], [('\nHanc', 'p-s---fa-'), ('si', 'c--------'), ('nostri', 'p-p---mn-'), ('transirent', 'v3pisa---'), ('hostes', 'n-p---mn-'), ('expectabant', 'v3piia---'), ('\nnostri', 'p-p---mn-'), ('autem', 'c--------'), ('si', 'c--------'), ('ab', 'r--------'), ('illis', 'p-p---mb-'), ('initium', 'n-s---nn-'), ('transeundi', 'v___d_-g-'), ('fieret', 'v3s-sa---'), ('ut', 'c--------'), ('impeditos', 'v-prppma-'), ('adgrederentur', 'v3pisd---'), ('parati', 'v-prppmn-'), ('in', 'r--------'), ('armis', 'n-p---nb-'), ('erant', 'v3piia---')], [('\nInterim', 'd--------'), ('proelio', 'n-s---nb-'), ('equestri', 'a-s---nb-'), ('inter', 'r--------'), ('duas', 'm-p---fa-'), ('acies', 'n-p---fa-'), ('contendebatur', 'v3siip---')], [('\nUbi', 'd--------'), ('neutri', 'a-p---mn-'), ('transeundi', 'v___d_-g-'), ('initium', 'n-s---na-'), ('faciunt', 'v3ppia---'), ('secundiore', 'a-s---nbc'), ('equitum', 'n-p---mg-'), ('proelio', 'n-s---nb-'), ('nostris', 'p-p---md-'), ('Caesar', 'n-s---mn-'), ('suos', 'p-p---ma-'), ('in', 'r--------'), ('castra', 'n-p---na-'), ('reduxit', 'v3sria---')], [('\nHostes', 'n-p---mn-'), ('protinus', 'd--------'), ('ex', 'r--------'), ('eo', 'p-s---mb-'), ('loco', 'n-s---mb-'), ('ad', 'r--------'), ('flumen', 'n-s---na-'), ('Axonam', 'n-s---ma-'), ('contenderunt', 'v3pria---'), ('quod', 'p-s---nn-'), ('esse', 'v--pna---'), ('post', 'r--------'), ('nostra', 'p-p---na-'), ('castra', 'n-p---na-'), ('demonstratum', 'v-srppnn-'), ('est', 'v3spia---')], [('\nIbi', 'd--------'), ('vadis', 'n-p---nb-'), ('repertis', 'v-prppnb-'), ('partem', 'n-s---fa-'), ('suarum', 'p-p---fg-'), ('copiarum', 'n-p---fg-'), ('traducere', 'v--pna---'), ('conati', 'v-prpdmn_'), ('sunt', 'v3ppia---'), ('eo', 'p-s---nb-'), ('consilio', 'n-s---nb-'), ('ut', 'c--------'), ('si', 'c--------'), ('possent', 'v3pisa---'), ('castellum', 'n-s---na-'), ('cui', 'p-s---nd-'), ('praeerat', 'v3siia---'), ('Q', 'n-s---mn-')], [('Titurius', 'n-s---mn-'), ('legatus', 'n-s---mn-'), ('expugnarent', 'v3pisa---'), ('pontem', 'n-s---ma-'), ('-que', 'c--------'), ('interscinderent', 'v3pisa---'), ('si', 'c--------'), ('minus', 'd-------c'), ('potuissent', 'v3plsa---'), ('agros', 'n-p---ma-'), ('Remorum', 'n-p---mg-'), ('popularentur', 'v3pisd---'), ('qui', 'p-p---mn-'), ('magno', 'a-s---md-'), ('nobis', 'p-p---md-'), ('usui', 'n-s---md-'), ('ad', 'r--------'), ('bellum', 'n-s---na-'), ('gerendum', 'v-s-g-na-'), ('erant', 'v3piia---'), ('commeatu', 'n-s---mb-'), ('-que', 'c--------'), ('nostros', 'p-p---ma-'), ('prohiberent', 'v3pisa---')], [('\nCaesar', 'n-s---mn-'), ('honoris', 'n-s---mg-'), ('Diviciaci', 'n-s---mg-'), ('atque', 'c--------'), ('Haeduorum', 'n-p---mg-'), ('causa', 'n-s---fb-'), ('sese', 'p-s---ma-'), ('eos', 'p-p---ma-'), ('in', 'r--------'), ('fidem', 'n-s---fa-'), ('recepturum', 'v-sfpama-'), ('et', 'c--------'), ('conservaturum', 'v-sfpama-'), ('dixit', 'v3sria---'), ('et', 'c--------'), ('quod', 'c--------'), ('erat', 'v3siia---'), ('civitas', 'n-s---fn-'), ('magna', 'a-s---fb-'), ('inter', 'r--------'), ('Belgas', 'n-p---ma-'), ('auctoritate', 'n-s---fb-'), ('atque', 'c--------'), ('hominum', 'n-p---mg-'), ('multitudine', 'n-s---fb-'), ('praestabat', 'v3siia---'), ('DC', 'm-p---ma-'), ('obsides', 'n-p---ma-'), ('poposcit', 'v3sria---')], [('\nHis', 'p-p---mb-'), ('traditis', 'v-prppmb-'), ('omnibus', 'a-p---nb-'), ('-que', 'c--------'), ('armis', 'n-p---nb-'), ('ex', 'r--------'), ('oppido', 'n-s---nb-'), ('conlatis', 'v-prppnb-'), ('ab', 'r--------'), ('eo', 'p-s---mb-'), ('loco', 'n-s---mb-'), ('in', 'r--------'), ('fines', 'n-p---ma-'), ('Ambianorum', 'n-p---mg-'), ('pervenit', 'v3sria---'), ('\nqui', 'p-p---mn-'), ('se', 'p-p---ma-'), ('sua', 'p-p---na-'), ('-que', 'c--------'), ('omnia', 'a-p---na-'), ('sine', 'r--------'), ('mora', 'n-s---fb-'), ('dediderunt', 'v3pria---')], [('\nEorum', 'p-p---mg-'), ('fines', 'n-p---ma-'), ('Nervii', 'n-p---mn-'), ('attingebant', 'v3piia---')], [('\nQuorum', 'p-p---mg-'), ('de', 'r--------'), ('natura', 'n-s---fb-'), ('moribus', 'n-p---mb-'), ('-que', 'c--------'), ('Caesar', 'n-s---mn-'), ('cum', 'c--------'), ('quaereret', 'v3sisa---'), ('sic', 'd--------'), ('reperiebat', 'v3siia---'), (':', 'u--------'), ('\nnullum', 'a-s---ma-'), ('esse', 'v--pna---'), ('aditum', 'n-s---ma-'), ('ad', 'r--------'), ('eos', 'p-p---ma-'), ('mercatoribus', 'n-p---md-'), ('\nnihil', 'n-s---n--'), ('pati', 'v--pnp---'), ('vini', 'n-s---ng-'), ('reliquarum', 'a-p---fg-'), ('-que', 'c--------'), ('rerum', 'n-p---fg-'), ('ad', 'r--------'), ('luxuriam', 'n-s---fa-'), ('pertinentium', 'v-pppafg-'), ('inferri', 'v--pnp---'), ('quod', 'c--------'), ('his', 'p-p---fb-'), ('rebus', 'n-p---fb-'), ('relanguescere', 'v--pna---'), ('animos', 'n-p---ma-'), ('eorum', 'p-p---mg-'), ('et', 'c--------'), ('remitti', 'v--pnp---'), ('virtutem', 'n-s---fa-'), ('existimarent', 'v3pisa---'), ('\nesse', 'v--pna---'), ('homines', 'n-p---ma-'), ('feros', 'a-p---ma-'), ('magnae', 'a-s---fg-'), ('-que', 'c--------'), ('virtutis', 'n-s---fg-'), ('\nincrepitare', 'v--pna---'), ('atque', 'c--------'), ('incusare', 'v--pna---'), ('reliquos', 'a-p---ma-'), ('Belgas', 'n-p---ma-'), ('qui', 'p-p---mn-'), ('se', 'p-p---ma-'), ('populo', 'n-s---md-'), ('Romano', 'a-s---md-'), ('dedidissent', 'v3plsa---'), ('patriam', 'a-s---fa-'), ('-que', 'c--------'), ('virtutem', 'n-s---fa-'), ('proiecissent', 'v3plsa---'), ('\nconfirmare', 'v--pna---'), ('sese', 'p-p---ma-'), ('neque', 'c--------'), ('legatos', 'n-p---ma-'), ('missuros', 'v-pfpama-'), ('neque', 'c--------'), ('ullam', 'a-s---fa-'), ('condicionem', 'n-s---fa-'), ('pacis', 'n-s---fg-'), ('accepturos', 'v-pfpama-')], [('\nCum', 'c--------'), ('per', 'r--------'), ('eorum', 'p-p---mg-'), ('fines', 'n-p---ma-'), ('triduum', 'n-s---na-'), ('iter', 'n-s---na-'), ('fecisset', 'v3slsa---'), ('inveniebat', 'v3siia---'), ('ex', 'r--------'), ('captivis', 'n-p---mb-'), ('Sabim', 'n-s---ma-'), ('flumen', 'n-s---na-'), ('a', 'r--------'), ('castris', 'n-p---nb-'), ('suis', 'p-p---nb-'), ('non', 'd--------'), ('amplius', 'd-------c'), ('milibus', 'm-p---nb-'), ('passuum', 'n-p---mg-'), ('X', 'm-_---__-'), ('abesse', 'v--pna---'), ('\ntrans', 'r--------'), ('id', 'p-s---na-'), ('flumen', 'n-s---na-'), ('omnes', 'a-p---ma-'), ('Nervios', 'n-p---ma-'), ('consedisse', 'v--rna---'), ('adventum', 'n-s---ma-'), ('-que', 'c--------'), ('ibi', 'd--------'), ('Romanorum', 'a-p---mg_'), ('expectare', 'v--pna---'), ('una', 'd--------'), ('cum', 'r--------'), ('Atrebatibus', 'n-p---mb-'), ('et', 'c--------'), ('Viromanduis', 'n-p---mb-'), ('finitimis', 'a-p---mb-'), ('suis', 'p-p---mb-'), ('(', 'u--------'), ('nam', 'c--------'), ('his', 'p-p---md-'), ('utrisque', 'p-p---md-'), ('persuaserant', 'v3plia---'), ('uti', 'c--------'), ('eandem', 'p-s---fa-'), ('belli', 'n-s---ng-'), ('fortunam', 'n-s---fa-'), ('experirentur', 'v3pisd---'), (')', 'u--------'), ('\nexpectari', 'v--pnp---'), ('etiam', 'd--------'), ('ab', 'r--------'), ('iis', 'p-p---mb-'), ('Atuatucorum', 'n-p---mg-'), ('copias', 'n-p---fa-'), ('atque', 'c--------'), ('esse', 'v--pna---'), ('in', 'r--------'), ('itinere', 'n-s---nb-'), ('\nmulieres', 'n-p---fa-'), ('qui', 'p-p---mn-'), ('-que', 'c--------'), ('per', 'r--------'), ('aetatem', 'n-s---fa-'), ('ad', 'r--------'), ('pugnam', 'n-s---fa-'), ('inutiles', 'a-p---mn-'), ('viderentur', 'v3pisp---'), ('in', 'r--------'), ('eum', 'p-s---ma-'), ('locum', 'n-s---ma-'), ('coniecisse', 'v--rna---'), ('quo', 'd--------'), ('propter', 'r--------'), ('paludes', 'n-p---fa-'), ('exercitui', 'n-s---md-'), ('aditus', 'n-s---mn-'), ('non', 'd--------'), ('esset', 'v3sisa---')], [('\nLoci', 'n-s---mg-'), ('natura', 'n-s---fn-'), ('erat', 'v3siia---'), ('haec', 'p-s---fn-'), ('quem', 'p-s---ma-'), ('locum', 'n-s---ma-'), ('nostri', 'p-p---mn-'), ('castris', 'n-p---nd-'), ('delegerant', 'v3plia---')], [('\nCollis', 'n-s---mn-'), ('ab', 'r--------'), ('summo', 'a-s---nbs'), ('aequaliter', 'd--------'), ('declivis', 'a-s---mn-'), ('ad', 'r--------'), ('flumen', 'n-s---na-'), ('Sabim', 'n-s---ma-'), ('quod', 'p-s---na-'), ('supra', 'd--------'), ('nominavimus', 'v1pria---'), ('vergebat', 'v3siia---')], [('\nAb', 'r--------'), ('eo', 'p-s---nb-'), ('flumine', 'n-s---nb-'), ('pari', 'a-s---fb-'), ('acclivitate', 'n-s---fb-'), ('collis', 'n-s---mn-'), ('nascebatur', 'v3siid---'), ('adversus', 'v-srppmn-'), ('huic', 'p-s---md-'), ('et', 'c--------'), ('contrarius', 'a-s---mn-'), ('passus', 'n-p---ma-'), ('circiter', 'd--------'), ('CC', 'm-_---__-'), ('infimus', 'd--------'), ('apertus', 'v-srppmn-'), ('ab', 'r--------'), ('superiore', 'a-s---fbc'), ('parte', 'n-s---fb-'), ('silvestris', 'a-s---mn-'), ('ut', 'c--------'), ('non', 'd--------'), ('facile', 'd--------'), ('introrsus', 'd--------'), ('perspici', 'v--pnp---'), ('posset', 'v3sisa---')], [('\nIntra', 'r--------'), ('eas', 'p-p---fa-'), ('silvas', 'n-p---fa-'), ('hostes', 'n-p---mn-'), ('in', 'r--------'), ('occulto', 'v-srppnb-'), ('sese', 'p-p---ma-'), ('continebant', 'v3piia---'), ('\nin', 'r--------'), ('aperto', 'v-srppmb-'), ('loco', 'n-s---mb-'), ('secundum', 'r--------'), ('flumen', 'n-s---na-'), ('paucae', 'a-p---fn-'), ('stationes', 'n-p---fn-'), ('equitum', 'n-p---mg-'), ('videbantur', 'v3piip---')], [('\nFluminis', 'n-s---ng-'), ('erat', 'v3siia---'), ('altitudo', 'n-s---fn-'), ('pedum', 'n-p---mg-'), ('circiter', 'd--------'), ('trium', 'm-p---mg-')], [('\nCaesar', 'n-s---mn-'), ('equitatu', 'n-s---mb-'), ('praemisso', 'v-srppmb-'), ('subsequebatur', 'v3siid---'), ('omnibus', 'a-p---fb-'), ('copiis', 'n-p---fb-'), ('\nsed', 'c--------'), ('ratio', 'n-s---fn-'), ('ordo', 'n-s---mn-'), ('-que', 'c--------'), ('agminis', 'n-s---ng-'), ('aliter', 'd-------_'), ('se', 'p-s---ma-'), ('habebat', 'v3siia---'), ('ac', 'c--------'), ('Belgae', 'n-p---mn-'), ('ad', 'r--------'), ('Nervios', 'n-p---ma-'), ('detulerant', 'v3plia---')], [('\nNam', 'c--------'), ('quod', 'c--------'), ('hostibus', 'n-p---md-'), ('adpropinquabat', 'v3siia---'), ('consuetudine', 'n-s---fb-'), ('sua', 'p-s---fb-'), ('Caesar', 'n-s---mn-'), ('VI', 'm-_---__-'), ('legiones', 'n-p---fa-'), ('expeditas', 'v-prppfa-'), ('ducebat', 'v3siia---'), ('\npost', 'r--------'), ('eas', 'p-p---fa-'), ('totius', 'a-s---mg-'), ('exercitus', 'n-s---mg-'), ('impedimenta', 'n-p---na-'), ('conlocarat', 'v3slia---'), ('\ninde', 'd--------'), ('duae', 'm-p---fn-'), ('legiones', 'n-p---fn-'), ('quae', 'p-p---fn-'), ('proxime', 'd-------s'), ('conscriptae', 'v-prppfn-'), ('erant', 'v3piia---'), ('totum', 'a-s---na-'), ('agmen', 'n-s---na-'), ('claudebant', 'v3piia---'), ('praesidio', 'n-s---nd-'), ('-que', 'c--------'), ('impedimentis', 'n-p---nd-'), ('erant', 'v3piia---')], [('\nEquites', 'n-p---mn-'), ('nostri', 'p-p---mn-'), ('cum', 'r--------'), ('funditoribus', 'n-p---mb-'), ('sagittariis', 'a-p---mb-'), ('-que', 'c--------'), ('flumen', 'n-s---na-'), ('transgressi', 'v-prpdmn_'), ('cum', 'r--------'), ('hostium', 'n-p---mg-'), ('equitatu', 'n-s---mb-'), ('proelium', 'n-s---na-'), ('commiserunt', 'v3pria---')], [('\nCum', 'c--------'), ('se', 'p-p---ma-'), ('illi', 'p-p---mn-'), ('identidem', 'd--------'), ('in', 'r--------'), ('silvis', 'n-p---fb-'), ('ad', 'r--------'), ('suos', 'p-p---ma-'), ('reciperent', 'v3pisa---'), ('ac', 'c--------'), ('rursus', 'd--------'), ('ex', 'r--------'), ('silva', 'n-s---fb-'), ('in', 'r--------'), ('nostros', 'p-p---ma-'), ('impetum', 'n-s---ma-'), ('facerent', 'v3pisa---'), ('neque', 'c--------'), ('nostri', 'p-p---mn-'), ('longius', 'd-------c'), ('quam', 'd--------'), ('quem', 'p-s---ma-'), ('ad', 'r--------'), ('finem', 'n-s---ma-'), ('porrecta', 'v-prppnn-'), ('loca', 'n-p---nn-'), ('aperta', 'v-prppnn-'), ('pertinebant', 'v3piia---'), ('cedentes', 'v-ppp-ma-'), ('insequi', 'v--pnd---'), ('auderent', 'v3pisa---'), ('interim', 'd--------'), ('legiones', 'n-p---fn-'), ('VI', 'm-_---__-'), ('quae', 'p-p---fn-'), ('primae', 'm-p---fn-'), ('venerant', 'v3plia---'), ('opere', 'n-s---nb-'), ('dimenso', 'v-srpdnb_'), ('castra', 'n-p---na-'), ('munire', 'v--pna---'), ('coeperunt', 'v3pria---')], [('\nUbi', 'd--------'), ('prima', 'm-p---nn-'), ('impedimenta', 'n-p---nn-'), ('nostri', 'p-s---mg-'), ('exercitus', 'n-s---mg-'), ('ab', 'r--------'), ('iis', 'p-p---mb-'), ('qui', 'p-p---mn-'), ('in', 'r--------'), ('silvis', 'n-p---fb-'), ('abditi', 'v-prppmn-'), ('latebant', 'v3piia---'), ('visa', 'v-prp-nn-'), ('sunt', 'v3ppia---'), ('quod', 'c--------'), ('tempus', 'n-s---nn-'), ('inter', 'r--------'), ('eos', 'p-p---ma-'), ('committendi', 'v-s-g-ng-'), ('proelii', 'n-s---ng-'), ('convenerat', 'v3slia---'), ('ut', 'c--------'), ('intra', 'r--------'), ('silvas', 'n-p---fa-'), ('aciem', 'n-s---fa-'), ('ordines', 'n-p---ma-'), ('-que', 'c--------'), ('constituerant', 'v3plia---'), ('atque', 'c--------'), ('ipsi', 'p-p---mn-'), ('sese', 'p-p---ma-'), ('confirmaverant', 'v3plia---'), ('subito', 'd-------_'), ('omnibus', 'a-p---fb-'), ('copiis', 'n-p---fb-'), ('provolaverunt', 'v3pria---'), ('impetum', 'n-s---ma-'), ('-que', 'c--------'), ('in', 'r--------'), ('nostros', 'p-p---ma-'), ('equites', 'n-p---ma-'), ('fecerunt', 'v3pria---')], [('\nHis', 'p-p---fb-'), ('facile', 'd-------_'), ('pulsis', 'v-prppfb-'), ('ac', 'c--------'), ('proturbatis', 'v-prppfb-'), ('incredibili', 'a-s---fb-'), ('celeritate', 'n-s---fb-'), ('ad', 'r--------'), ('flumen', 'n-s---na-'), ('decucurrerunt', 'v3pria---'), ('ut', 'c--------'), ('paene', 'd--------'), ('uno', 'm-s---nb-'), ('tempore', 'n-s---nb-'), ('et', 'c--------'), ('ad', 'r--------'), ('silvas', 'n-p---fa-'), ('et', 'c--------'), ('in', 'r--------'), ('flumine', 'n-s---nb-'), ('et', 'c--------'), ('iam', 'd--------'), ('in', 'r--------'), ('manibus', 'n-p---fb-'), ('nostris', 'p-p---fb-'), ('hostes', 'n-p---mn-'), ('viderentur', 'v3pisp---')], [('\nEadem', 'p-s---fb-'), ('autem', 'c--------'), ('celeritate', 'n-s---fb-'), ('adverso', 'v-srppmb-'), ('colle', 'n-s---mb-'), ('ad', 'r--------'), ('nostra', 'p-p---na-'), ('castra', 'n-p---na-'), ('atque', 'c--------'), ('eos', 'p-p---ma-'), ('qui', 'p-p---mn-'), ('in', 'r--------'), ('opere', 'n-s---nb-'), ('occupati', 'v-prppmn-'), ('erant', 'v3piia---'), ('contenderunt', 'v3pria---')], [('\nSub', 'r--------'), ('vesperum', 'n-s---ma-'), ('Caesar', 'n-s---mn-'), ('portas', 'n-p---fa-'), ('claudi', 'v--pnp---'), ('milites', 'n-p---ma-'), ('-que', 'c--------'), ('ex', 'r--------'), ('oppido', 'n-s---nb-'), ('exire', 'v--pna---'), ('iussit', 'v3sria---'), ('ne', 'c--------'), ('quam', 'p-s---fa-'), ('noctu', 'n-s---fb-'), ('oppidani', 'a-p---mn-'), ('a', 'r--------'), ('militibus', 'n-p---mb-'), ('iniuriam', 'n-s---fa-'), ('acciperent', 'v3pisa---')], [('\nIlli', 'p-p---mn-'), ('ante', 'd--------'), ('inito', 'v-srpanb-'), ('ut', 'c--------'), ('intellectum', 'v-srppnn-'), ('est', 'v3spia---'), ('consilio', 'n-s---nb-'), ('quod', 'c--------'), ('deditione', 'n-s---fb-'), ('facta', 'v-srppfb-'), ('nostros', 'p-p---ma-'), ('praesidia', 'n-p---na-'), ('deducturos', 'v-pfpama-'), ('aut', 'c--------'), ('denique', 'd--------'), ('indiligentius', 'd-------c'), ('servaturos', 'v-pfpama-'), ('crediderant', 'v3plia---'), ('partim', 'd--------'), ('cum', 'r--------'), ('iis', 'p-p---nb-'), ('quae', 'p-p---nn-'), ('retinuerant', 'v3plia---'), ('et', 'c--------'), ('celaverant', 'v3plia---'), ('armis', 'n-p---nb-'), ('partim', 'd--------'), ('scutis', 'n-p---nb-'), ('ex', 'r--------'), ('cortice', 'n-s---fb-'), ('factis', 'v-prppnb-'), ('aut', 'c--------'), ('viminibus', 'n-p---nb-'), ('intextis', 'v-prppnb-'), ('quae', 'p-p---nn-'), ('subito', 'd-------_'), ('ut', 'c--------'), ('temporis', 'n-s---ng-'), ('exiguitas', 'n-s---fn-'), ('postulabat', 'v3siia---'), ('pellibus', 'n-p---fb-'), ('induxerant', 'v3plia---'), ('tertia', 'm-s---fb-'), ('vigilia', 'n-s---fb-'), ('qua', 'p-s---fb-'), ('minime', 'd--------'), ('arduus', 'a-s---mn-'), ('ad', 'r--------'), ('nostras', 'p-p---fa-'), ('munitiones', 'n-p---fa-'), ('ascensus', 'n-s---mn-'), ('videbatur', 'v3siip---'), ('omnibus', 'a-p---fb-'), ('copiis', 'n-p---fb-'), ('repente', 'd--------'), ('ex', 'r--------'), ('oppido', 'n-s---nb-'), ('eruptionem', 'n-s---fa-'), ('fecerunt', 'v3pria---')], [('\nCeleriter', 'd--------'), ('ut', 'c--------'), ('ante', 'd--------'), ('Caesar', 'n-s---mn-'), ('imperaverat', 'v3slia---'), ('ignibus', 'n-p---mb-'), ('significatione', 'n-s---fb-'), ('facta', 'v-srppfb-'), ('ex', 'r--------'), ('proximis', 'a-p---nbs'), ('castellis', 'n-p---nb-'), ('eo', 'd--------'), ('concursum', 'v-srppnn-'), ('est', 'v3spia---'), ('pugnatum', 'v-srppnn-'), ('-que', 'c--------'), ('ab', 'r--------'), ('hostibus', 'n-p---mb-'), ('ita', 'd--------'), ('acriter', 'd-------_'), ('est', 'v3spia---'), ('ut', 'c--------'), ('a', 'r--------'), ('viris', 'n-p---mb-'), ('fortibus', 'a-p---mb-'), ('in', 'r--------'), ('extrema', 'a-s---fbs'), ('spe', 'n-s---fb-'), ('salutis', 'n-s---fg-'), ('iniquo', 'a-s---mb-'), ('loco', 'n-s---mb-'), ('contra', 'r--------'), ('eos', 'p-p---ma-'), ('qui', 'p-p---mn-'), ('ex', 'r--------'), ('vallo', 'n-s---nb-'), ('turribus', 'n-p---fb-'), ('-que', 'c--------'), ('tela', 'n-p---na-'), ('iacerent', 'v3pisa---'), ('pugnari', 'v--pnp---'), ('debuit', 'v3sria---'), ('cum', 'c--------'), ('in', 'r--------'), ('una', 'm-s---fb-'), ('virtute', 'n-s---fb-'), ('omnis', 'a-s---fn-'), ('spes', 'n-s---fn-'), ('consisteret', 'v3sisa---')], [('\nOccisis', 'v-prppnb-'), ('ad', 'd--------'), ('hominum', 'n-p---mg-'), ('milibus', 'm-p---nb-'), ('IIII', 'm-_---__-'), ('reliqui', 'a-p---mn-'), ('in', 'r--------'), ('oppidum', 'n-s---na-'), ('reiecti', 'v-prppmn-'), ('sunt', 'v3ppia---')], [('\nPostridie', 'd--------'), ('eius', 'p-s---mg-'), ('diei', 'n-s---mg-'), ('refractis', 'v-prppfb-'), ('portis', 'n-p---fb-'), ('cum', 'c--------'), ('iam', 'd--------'), ('defenderet', 'v3sisa---'), ('nemo', 'n-s---mn-'), ('atque', 'c--------'), ('intromissis', 'v-prppmb-'), ('militibus', 'n-p---mb-'), ('nostris', 'p-p---mb-'), ('sectionem', 'n-s---fa-'), ('eius', 'p-s---ng-'), ('oppidi', 'n-s---ng-'), ('universam', 'a-s---fa-'), ('Caesar', 'n-s---mn-'), ('vendidit', 'v3sria---')], [('\nAb', 'r--------'), ('iis', 'p-p---mb-'), ('qui', 'p-p---mn-'), ('emerant', 'v3plia---'), ('capitum', 'n-p---ng-'), ('numerus', 'n-s---mn-'), ('ad', 'r--------'), ('eum', 'p-s---ma-'), ('relatus', 'v-srppmn-'), ('est', 'v3spia---'), ('milium', 'm-p---ng-')], [('\nEodem', 'p-s---nb-'), ('tempore', 'n-s---nb-'), ('a', 'r--------'), ('P', 'n-s---mb-')], [('Crasso', 'n-s---mb-'), ('quem', 'p-s---ma-'), ('cum', 'r--------'), ('legione', 'n-s---fb-'), ('una', 'm-s---fb-'), ('miserat', 'v3slia---'), ('ad', 'r--------'), ('Venetos', 'n-p---ma-'), ('Venellos', 'n-p---ma-'), ('Osismos', 'n-p---ma-'), ('Coriosolitas', 'n-p---ma-'), ('Esuvios', 'n-p---ma-'), ('Aulercos', 'n-p---ma-'), ('Redones', 'n-p---ma-'), ('quae', 'p-p---fn-'), ('sunt', 'v3ppia---'), ('maritimae', 'a-p---fn-'), ('civitates', 'n-p---fn-'), ('Oceanum', 'n-s---ma-'), ('-que', 'c--------'), ('attingunt', 'v3ppia---'), ('certior', 'a-s---mnc'), ('factus', 'v-srppmn-'), ('est', 'v3spia---'), ('omnes', 'a-p---fa-'), ('eas', 'p-p---fa-'), ('civitates', 'n-p---fa-'), ('in', 'r--------'), ('dicionem', 'n-s---fa-'), ('potestatem', 'n-s---fa-'), ('-que', 'c--------'), ('populi', 'n-s---mg-'), ('Romani', 'a-s---mg-'), ('esse', 'v--pna---'), ('redactas', 'v-prppfa-')]]
def features(sentence, index):
    """ sentence: [w1, w2, ...], index: the index of the word """
    return {
        'word': sentence[index],
        'is_first': index == 0,
        'is_last': index == len(sentence) - 1,
        'is_capitalized': sentence[index][0].upper() == sentence[index][0],
        'is_all_caps': sentence[index].upper() == sentence[index],
        'is_all_lower': sentence[index].lower() == sentence[index],
        'prefix-1': sentence[index][0],
        'prefix-2': sentence[index][:2],
        'prefix-3': sentence[index][:3],
        'suffix-1': sentence[index][-1],
        'suffix-2': sentence[index][-2:],
        'suffix-3': sentence[index][-3:],
        'prev_word': '' if index == 0 else sentence[index - 1],
        'next_word': '' if index == len(sentence) - 1 else sentence[index + 1],
        'has_hyphen': '-' in sentence[index],
        'is_numeric': sentence[index].isdigit(),
        'capitals_inside': sentence[index][1:].lower() != sentence[index][1:]
    }_____no_output_____def untag(tagged_sentence):
    return [w for w, t in tagged_sentence]_____no_output_____train_size = int(.75*len(word_list))
train_sent = word_list[:train_size]
test_sent = word_list[train_size:]
def transform_to_dataset(tagged_sentences):
    X, y = [], []

    for tagged in tagged_sentences:
        for index in range(len(tagged)):
            #print(tagged)
            X.append(features(untag(tagged), index))
            y.append(tagged[index][1])

    return X, y

X, y = transform_to_dataset(train_sent)
print(len(X))_____no_output_____from sklearn.tree import DecisionTreeClassifier
from sklearn.feature_extraction import DictVectorizer
from sklearn.pipeline import Pipeline

clf = Pipeline([
    ('vectorizer', DictVectorizer(sparse=False)),
    ('classifier', DecisionTreeClassifier(criterion='entropy'))
])

clf.fit(X, y)   # Use only the first 10K samples if you're running it multiple times. It takes a fair bit :)

print ('Training completed')

X_test, y_test = transform_to_dataset(test_sent)

print ("Accuracy:" + str(clf.score(X_test, y_test)))_____no_output_____
</code>


# Notebook from WeatherGod/SciPyEcosystem
Path: Scipy_Ecosystem_Slideshow.ipynb

# Let printing work the same in Python 2 and 3
from __future__ import print_function
# Inline interactive figures
%matplotlib nbagg_____no_output_____import numpy as np
import matplotlib.pyplot as plt_____no_output_____

Introduction to the SciPy Ecosystem

<p class="gap05"

Ben Root

ben.v.root@gmail.com

Atmospheric and Environmental Research, Inc.

[Jupyter Notebook](http://nbviewer.jupyter.org/github/WeatherGod/SciPyEcosystem/blob/master/Scipy_Ecosystem_Slideshow.ipynb)

_____no_output_____# Who am I?
- B.S. & M.S. in Meteorology from Penn State
 - Perl, C/C++, Matlab & a terrible language called GrADS
 - Linux and Vim

- Spent 5 years on a PhD at the University of Oklahoma
 - Had problems with Matlab
 - Tried Matplotlib & Python
 - Posted patches to the various mailing lists_____no_output_____- Matplotlib Developer
 - John Hunter of Matplotlib said I annoyed him enough
 - Gave me commit rights!
 - Personally managed the v1.1.0 release of Matplotlib
 - Active on the matplotlib mailing list_____no_output_____- The matplotlib mailing list is directly responsible for two things:
 1. Me not finishing my dissertation
 2. Current job
   - [How matplotlib got me a job](http://matplotlib.1069221.n5.nabble.com/How-matplotlib-got-me-a-job-td27470.html)
   - tl;dr: answer questions on mailing lists, you never know if the person you are helping out will be your next
     co-worker!_____no_output_____- Author
 - [The Anatomy of Matplotlib Tutorial](https://github.com/WeatherGod/AnatomyOfMatplotlib)
 - [Interactive Applications using Matplotlib](http://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843/ref=tmm_pap_title_0)

- SciPy Conference Co-chair
 - Financial Aid (2015)
 - Tutorials (2016)

- Scientific Programmer at [Atmospheric and Environmental Research, Inc.](http://www.aer.com)_____no_output_____# Who uses SciPy?
- USGS
- Los Alamos National Laboratory
- [`LIGO`](https://losc.ligo.org/s/events/GW150914/GW150914_tutorial.html)
- Autodesk
- Kitware
- Microsoft Azure
- Bloomberg
- Amazon_____no_output_____# NumPy
- The numerical N-dimensional array class
- Provides basic math & array methods
- Lays the foundation for SciPy ecosystem
- Completely different from Python's `array`
  - `array` is geared towards having a compact form of lists (great for buffers)
  - NumPy is for math_____no_output_____

import numpy as np
np.arange(10)_____no_output_____

- Implemented mostly in C
  - Just a C-pointer with lots of dressing!
  - Interfaces with many existing numerical tools
  - Fast_____no_output_____

a = list(range(10000))
%timeit [v ** 2 for v in a]_____no_output_____b = np.array(a)
%timeit b ** 2_____no_output_____

## Array Indexing_____no_output_____

x = np.arange(100).reshape(5, 20)
# Simple Indexing
print(x[2])_____no_output_____# Slicing
print(x[2:5])_____no_output_____# Boolean Indexing (always a 1-D result)
print(x[(x % 2) == 0])_____no_output_____# Fancy Indexing -- Note the use of a list, not tuple!
print(x[[1, 4, 2]])_____no_output_____

Learn more of the basics at [Introduction to NumPy](http://nbviewer.jupyter.org/github/WeatherGod/AnatomyOfMatplotlib/blob/master/AnatomyOfMatplotlib-Part0-Intro2NumPy.ipynb)_____no_output_____# Matplotlib
  - Cross-platform, interactive-capable, scientific plotting tool
  - In science, visualizing data is paramount
  - Tables suck
  - A picture is worth a thousand words_____no_output_____  - An interactive plot in 3 lines_____no_output_____

import matplotlib.pyplot as plt
plt.plot([1, 5, 3])
plt.show()_____no_output_____

  - Not stupidly unhelpful or obtrusive.
  - Have control over as much or as little detail as you want
  - [Wide assortments of plot types](http://nbviewer.jupyter.org/github/WeatherGod/AnatomyOfMatplotlib/blob/master/AnatomyOfMatplotlib-Part2-Plotting_Methods_Overview.ipynb)
  - Acts as an abstraction library to many GUI toolkits
  - [Interactive Applications using Matplotlib](http://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843/ref=tmm_pap_title_0)_____no_output_____# SciPy
 - Goes beyond basic math algorithms
 - Has general algorithms that apply to many domains
   - `constants`
   - `cluster`
   - `fftpack`
   - `integrate`_____no_output_____   - `interpolate`_____no_output_____

from scipy import interpolate
x, y = np.linspace(-5, 5, 25), np.linspace(-5, 5, 25)
xx, yy = np.meshgrid(x, y)
z = np.sin(xx**2+yy**2)
f_rect = interpolate.RectBivariateSpline(x, y, z)

xnew, ynew = np.linspace(-4.5, 4.5, 1000), np.linspace(-4.5, 4.5, 1000)
znew = f_rect(xnew, ynew)_____no_output_____fig, axes = plt.subplots(1, 2)
axes[0].imshow(z, vmin=-1, vmax=1)
axes[1].imshow(znew, vmin=-1, vmax=1)_____no_output_____

   - `io`
     - Support for some scientific data formats
     - This used to be essential before pypi
     - matlab, fortran, netcdf3, arff, IDL, wav
   - `ndimage`
     - Convolutions, filters, transforms
     - `measurements`  (stats on labeled pixels)
     - `morphology`  (erosion, dilation, etc.)
     - For advanced features, see [`scikit-image`](http://scikit-image.org)_____no_output_____# Pineapple Express_____no_output_____

n_stores = 5
n_customers = 500
stores = np.random.random((n_stores, 2)) * 400
customers = np.random.random((n_customers, 2)) * 400
threshold = 200_____no_output_____#%%timeit
d = np.hypot(stores[:, 0][:, np.newaxis] -
             customers[:, 0][np.newaxis, :],
             stores[:, 1][:, np.newaxis] -
             customers[:, 1][np.newaxis, :])
indexes = np.argmin(d, axis=0)
d = d[indexes, np.arange(len(indexes))]
d[d > threshold] = np.inf
indexes[np.isinf(d)] = len(indexes)
rev_indexes = [np.where(indexes == store_i)
               for store_i in xrange(len(stores))]_____no_output_____fig, ax = plt.subplots()
for inds, in rev_indexes:
    ax.plot(customers[inds, 0], customers[inds, 1], '.')
ax.plot(stores[:, 0], stores[:, 1], '*y', markersize=25,
        mec='k', mew=3)_____no_output_____

   - `spatial`_____no_output_____

from scipy.spatial import cKDTree as KDTree_____no_output_____%%timeit
store_tree = KDTree(stores)
d, indexes = store_tree.query(customers,
                              distance_upper_bound=threshold)
rev_indexes = [np.where(indexes == store_i)
               for store_i in xrange(len(stores))]    _____no_output_____

   - `stats`
     - More statistics distributions than you can shake a stick at.
     - Generate random data from a distribution
     - Fit your data to a chosen distribution
     - Check out [statsmodels](http://statsmodels.sourceforge.net/) package
       for even more statistics fun._____no_output_____   - `special`
     - If you ever get a requirement to use a function with a French,
       German, or Russian-sounding name, check in here.
     - Also, when scientists talk of Lambda functions, it is usually
       not the Python `lambda`. Find it here._____no_output_____# IPython / Jupyter

  - "Weaponize your tab"
  - Paste multi-line code snippets into a REPL
  - Notebooks are for sharing code examples with results
  - Makes it easy to experiment
  - Not intended to replace the debugger or be an IDE
  - More like a sandbox_____no_output_____# Anaconda/miniconda
  - A "python" distribution from [Continuum Analytics](http://continuum.io)
  - `distutils`/`setuptools` isn't good enough for the SciPy community
  - This isn't to knock on these tools, but scientists have developed
    very useful tools that are not packaged through `pip`, and may
    have fragile binary dependency requirements._____no_output_____  - So, why not use yum/apt-get/macports/homebrew?
  - Scientists love experimenting, but *hate* when things break
  - We also hate waiting for IT to install packages
  - `conda` is user-space package management with environments
  - Dynamic library linkages are at the user-space level
  - IT can update systems without breaking things_____no_output_____# The rest of the ecosystem
## Visualization
  - [`bokeh`](http://bokeh.pydata.org/en/latest/)
  - [`seaborn`](https://stanford.edu/~mwaskom/software/seaborn/)
  - [`cartopy`](http://scitools.org.uk/cartopy/)
  - [`ggplot`](http://ggplot.yhathq.com/)
  - [`descartes`](https://bitbucket.org/sgillies/descartes/)
  - [`mayavi`](http://code.enthought.com/projects/mayavi/)
  - [`vispy`](http://vispy.org) & [`glumpy`](https://glumpy.github.io/)_____no_output_____## Do more with arrays
  - [`pandas`](http://pandas.pydata.org/)
  - [`xarray`](http://xarray.pydata.org/)
  - [`pytables`](http://pytables.org/)
  - [`ibis`](http://www.ibis-project.org/)
  - [`odo`](http://odo.readthedocs.org/en/latest/)
  - [`blaze`](http://blaze.readthedocs.org/en/latest/index.html)
  - [`pint`](https://pint.readthedocs.org)_____no_output_____

from scipy import constants
import pint
ureg = pint.UnitRegistry()
m = 10 * ureg.kg
c = constants.c * ureg.meters / ureg.second
E = m*c**2
print(E)_____no_output_____

## Python with rockets
  - [`cython`](http://cython.org/)
  - [`numba`](http://numba.pydata.org/)
  - [`numexpr`](https://github.com/pydata/numexpr)
  - [`dask`](http://dask.pydata.org/en/latest/)
  - [`theano`](http://deeplearning.net/software/theano/)_____no_output_____

def pyprimes(kmax):
    p = [0] * 1000
    result = []
    if kmax > 1000:
        kmax = 1000
    k = 0
    n = 2
    while k < kmax:
        i = 0
        while i < k and n % p[i] != 0:
            i = i + 1
        if i == k:
            p[k] = n
            k = k + 1
            result.append(n)
        n = n + 1
    return result_____no_output_____%load_ext cython_____no_output_____%%cython
def cprimes(int kmax):
    cdef int n, k, i
    cdef int p[1000]
    result = []
    if kmax > 1000:
        kmax = 1000
    k = 0
    n = 2
    while k < kmax:
        i = 0
        while i < k and n % p[i] != 0:
            i = i + 1
        if i == k:
            p[k] = n
            k = k + 1
            result.append(n)
        n = n + 1
    return result_____no_output_____%timeit pyprimes(500)
%timeit cprimes(500)_____no_output_____

## Symbolic Math
  - [`sympy`](http://sympy.org/)
  - [`sage`](http://www.sagemath.org/)
  - [`patsy`](http://patsy.readthedocs.org/en/latest/index.html)_____no_output_____## Geographic Processing
  - GDAL/OGR  (`osgeo.ogr` & `osgeo.osr`)
  - [`fiona`](http://toblerity.org/fiona/)
  - [`geopandas`](http://geopandas.org/)
  - [`shapely`](http://toblerity.org/shapely/)
  - [`pyproj`](http://jswhit.github.io/pyproj/)
  - [`geopy`](https://geopy.readthedocs.io/)_____no_output_____

from shapely.geometry import Point
a = Point(1, 1).buffer(1.5)
b = Point(2, 1).buffer(1.5)
c = a.intersection(b)_____no_output_____from descartes import PolygonPatch
fig, ax = plt.subplots()
ax.set_xlim(-1, 4); ax.set_ylim(-1, 3)
for p, color in zip([a, b, c], 'rcy'):
    ax.add_patch(PolygonPatch(p, fc=color))_____no_output_____

## Scientific Data Formats
  - [`netCDF4`](http://unidata.github.io/netcdf4-python/)
  - [`pytables`](http://pytables.org)
  - [`h5py`](http://www.h5py.org/)
  - [`PyNIO`](https://www.pyngl.ucar.edu/Nio.shtml)
  - GDAL (`osgeo.gdal`)
  - [`rasterio`](https://github.com/mapbox/rasterio)_____no_output_____## Domain Specialties
  - [`scikit-image`](http://scikit-image.org)
  - [`scikit-learn`](http://scikit-learn.org/stable/)
  - [`astropy`](http://astropy.org)
  - [`statsmodels`](http://statsmodels.sourceforge.net/)
  - [`metpy`](https://github.com/MetPy/MetPy)
  - [`pyart`](http://arm-doe.github.io/pyart/)_____no_output_____# Recommended Reading
- [Python for Data Analysis](http://shop.oreilly.com/product/0636920023784.do): Wes Mckinney
- [Cython - A Guide for Python Programmers](http://shop.oreilly.com/product/0636920033431.do): Kurt Smith
- [Effective Computation in Physics - Field Guide to Research with Python](http://shop.oreilly.com/product/0636920033424.do): Anthony Scopatz & Katy Huff
- [Mastering Matplotlib](http://www.amazon.com/dp/1783987545/ref=pd_lpo_sbs_dp_ss_1?pf_rd_p=1944687622&pf_rd_s=lpo-top-stripe-1&pf_rd_t=201&pf_rd_i=1783988843&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=0SB7JQVV0V78AWESMCEB): Duncan McGreggor_____no_output_____# Final Thoughts
  - This is but a taste of what is out there
  - Biology is one domain not covered here
  - Love the co-operative nature of the SciPy community
  - Projects complement each other and "stand on the shoulders of giants"
  - Teaching scientists how to program: [Software Carpentry](software-carpentry.org)_____no_output_____


# Notebook from joaogui1/evoflow
Path: benchmark/benchmark_analysis.ipynb

# Setup_____no_output_____

from tabulate import tabulate
import pandas as pd
from pathlib import Path
import json
import os
import altair as alt
from collections import defaultdict
from IPython.core.display import display, HTML
# alt.renderers.enable('html')

import matplotlib.pyplot as plt
%matplotlib inline
plt.style.use('ggplot')_____no_output_____VERSION = '0.4.1'  # before tf.function compatibility
VERSION = '0.5.0'  # after tf.function compatibility which cripple the perf currently
def load_benchmark_results(VERSION):
    tables = defaultdict(lambda: defaultdict(dict))
    res_dir = 'results/%s' % VERSION
    results = []
    for fname in Path(res_dir).glob('*.json'):
        for l in open(fname):
            d = json.loads(l)
            res = {}
            # flattenning
            for k, v in d.items():
                if k == 'timings':
                    for tn, tv in v.items():
                        if tn == 'raw':
                            continue
                        name = '%s_time' % (tn)
                        res[name] = tv
                else:
                        res[k] = v
            res['shape_str'] = "x".join([str(x) for x in d['shape']])
            res['test_name'] = "%s%s" % (d['group'], d['name'])

            tables[res['test_name']][res['shape_str']][res['backend']] = res['avg_time']

            results.append(res)
    return pd.DataFrame(results), tables
df, tables = load_benchmark_results(VERSION)
df.head()_____no_output_____def htmlout(data):
    display(HTML(data))

def display_table(group_name):
    BACKENDS = ['numpy', 'tensorflow-cpu', 'tensorflow-gpu', 'cupy']
    headers = ['shape', 'numpy', 'tf-cpu', 'tf-gpu', 'cupy' ]
    # htmlout('
%s
' % group_name)
    for dim in ['1D', '2D', '3D']:
        prob_name = group_name + dim
        if prob_name in tables:
            raw = tables[prob_name]
            rows = []
            for shape, data in tables[prob_name].items():
                row = [shape]
                baseline = data['numpy']
                for b in  BACKENDS:
                    ts  = round(data[b], 3)
                    perf = round(baseline / (data[b] + 0.000001), 2)
                    val = "%s (%.2fx)" % (ts, perf)
                    row.append(val)
                rows.append(row)
            htmlout('
%s' % dim)
            htmlout(tabulate(rows, headers=headers, tablefmt='html'))
_____no_output_____def display_chart(group_name):
    data = df[df['group']==group_name].sort_values('input_size')
    chart = alt.Chart(data, title='').mark_bar().encode(
            x=alt.X('backend', axis=alt.Axis(title='')),
            y=alt.Y('avg_time', sort='-x', axis=alt.Axis(title='')),
            color=alt.Color('backend', legend=None),
            column=alt.Column('shape_str', title='', sort=alt.EncodingSortField(field='input_size', order='ascending'))
            ).resolve_scale(y='independent')
    chart = chart.facet(column='name', spacing=50, title=group_name).configure_title(fontSize=20, offset=5, orient='top', anchor='middle')
    return chart_____no_output_____

# End to End problems_____no_output_____

display_chart('OneMax')_____no_output_____display_table('OneMax')_____no_output_____display_chart('TSP')_____no_output_____display_table('TSP')_____no_output_____

# Evolution OPs_____no_output_____

display_chart('RandomMutation')_____no_output_____display_table('RandomMutation')_____no_output_____display_chart('UniformCrossover')_____no_output_____display_table('UniformCrossover')_____no_output_____display_chart('SingleCrossover')_____no_output_____display_table('SingleCrossover')_____no_output_____display_chart('DualCrossover')_____no_output_____display_table('DualCrossover')_____no_output_____display_chart('Reverse')_____no_output_____display_table('Reverse')_____no_output_____display_chart('Shuffle')_____no_output_____display_table('Shuffle')_____no_output_____

## Other_____no_output_____

display_chart('Fittest')_____no_output_____display_table('Shuffle')_____no_output_____sorted(set(df[df['test_type']=='Selection']['group']))
_____no_output_____


# Notebook from FlorentCLMichel/learning_data_science
Path: Projects_Jupyter/.ipynb_checkpoints/Star_Wars_Survey-checkpoint.ipynb

# Star Wars Survey  (work in progress)

In this project we analyse data from a FiveThirtyEight survey on the first two Star Wars trilogies, whose results are reported in [this article](https://fivethirtyeight.com/features/americas-favorite-star-wars-movies-and-least-favorite-characters/) published on 22 July 2014.

## Data cleaning

The dataset, `StarWars.csv`, was created by the FiveTHirtyeight team and is encoded in ISO-8859-1.
Some of its most important columns are:

* `RespondentID`: an anonymized ID for the each respondent
* `Gender`: the respondent's gender
* `Age`: the respondent's age
* `Household Income`: the respondent's household income
* `Education`: the respondent's education level
* `Location (Census Region)`: where the respondent lives
* `Have you seen any of the 6 films in the Star Wars franchise?`: whether the respondent has seen any of the films in the first two trilogies
* `Do you consider yourself to be a fan of the Star Wars film franchise?`: whether the respondent considers themsellves a fan

We first load it into the Pandas dataframe `star_wars` and display the first 10 rows to look for possible inconsistencies._____no_output_____

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

star_wars = pd.read_csv('../Data/StarWars.csv', encoding='ISO-8859-1')
star_wars.head(10)_____no_output_____

The first line does not contain data, but only clarifies the meanings of some columns.

Number and types of objects in each column:_____no_output_____

star_wars.info()<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1187 entries, 0 to 1186
Data columns (total 38 columns):
RespondentID                                                                                1186 non-null float64
Have you seen any of the 6 films in the Star Wars franchise?                                                                                1187 non-null object
Do you consider yourself to be a fan of the Star Wars film franchise?                                                                            837 non-null object
Which of the following Star Wars films have you seen? Please select all that apply.                                                              674 non-null object
Unnamed: 4                                                                                572 non-null object
Unnamed: 5                                                                                551 non-null object
Unnamed: 6                                                                                608 non-null object
Unnamed: 7                                                                                759 non-null object
Unnamed: 8                                                                                739 non-null object
Please rank the Star Wars films in order of preference with 1 being your favorite film in the franchise and 6 being your least favorite film.    836 non-null object
Unnamed: 10                                                                                837 non-null object
Unnamed: 11                                                                                836 non-null object
Unnamed: 12                                                                                837 non-null object
Unnamed: 13                                                                                837 non-null object
Unnamed: 14                                                                                837 non-null object
Please state whether you view the following characters favorably, unfavorably, or are unfamiliar with him/her.                                   830 non-null object
Unnamed: 16                                                                                832 non-null object
Unnamed: 17                                                                                832 non-null object
Unnamed: 18                                                                                824 non-null object
Unnamed: 19                                                                                826 non-null object
Unnamed: 20                                                                                815 non-null object
Unnamed: 21                                                                                827 non-null object
Unnamed: 22                                                                                821 non-null object
Unnamed: 23                                                                                813 non-null object
Unnamed: 24                                                                                828 non-null object
Unnamed: 25                                                                                831 non-null object
Unnamed: 26                                                                                822 non-null object
Unnamed: 27                                                                                815 non-null object
Unnamed: 28                                                                                827 non-null object
Which character shot first?                                                                                829 non-null object
Are you familiar with the Expanded Universe?                                                                                829 non-null object
Do you consider yourself to be a fan of the Expanded Universe?æ                                                                                214 non-null object
Do you consider yourself to be a fan of the Star Trek franchise?                                                                                1069 non-null object
Gender                                                                                1047 non-null object
Age                                                                                1047 non-null object
Household Income                                                                                859 non-null object
Education                                                                                1037 non-null object
Location (Census Region)                                                                                1044 non-null object
dtypes: float64(1), object(37)
memory usage: 352.5+ KB

There are 38 columns.
All columns seem to contain strings except the first (`RespondentID`), which contais floats.
All columns except the second one (`Have you seen any of the 6 films in the Star Wars franchise?`) have at least one null value.
The first column has only one null value, on the first row; the others have more.
There also seems to be two useless characters at the end of the column name `Do you consider yourself to be a fan of the Expanded Universe?æ`.

Let us rename some columns using shorter and/or more informative titles and delete the first row.
Columns 15 to 28 are renamed using the information on the first row._____no_output_____

dict_replace_cols = {
    'Have you seen any of the 6 films in the Star Wars franchise?': 'seen_any',
    'Do you consider yourself to be a fan of the Star Wars film franchise?': 'fan',
    'Which of the following Star Wars films have you seen? Please select all that apply.': 'seen_1',
    'Unnamed: 4': 'seen_2',
    'Unnamed: 5': 'seen_3',
    'Unnamed: 6': 'seen_4',
    'Unnamed: 7': 'seen_5',
    'Unnamed: 8': 'seen_6',
    'Please rank the Star Wars films in order of preference with 1 being your favorite film in the franchise and 6 being your least favorite film.': 'order_pref_1',
    'Unnamed: 10': 'order_pref_2',
    'Unnamed: 11': 'order_pref_3',
    'Unnamed: 12': 'order_pref_4',
    'Unnamed: 13': 'order_pref_5',
    'Unnamed: 14': 'order_pref_6',
    'Which character shot first?': 'shot_first',
    'Are you familiar with the Expanded Universe?': 'fam_exp_universe',
    'Do you consider yourself to be a fan of the Expanded Universe?æ': 'fan_exp_universe',
    'Do you consider yourself to be a fan of the Star Trek franchise?': 'fan_star_treck',
    'Household Income': 'Income',
    'Location (Census Region)': 'Location'
}
star_wars.rename(columns = dict_replace_cols, inplace=True)

cols_names = list(star_wars.columns)
for i in list(range(15,29)):
    cols_names[i] = star_wars.iloc[0,i]
star_wars.columns = cols_names

star_wars = star_wars.iloc[1:]

star_wars.info()<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1186 entries, 1 to 1186
Data columns (total 38 columns):
RespondentID            1186 non-null float64
seen_any                1186 non-null object
fan                     836 non-null object
seen_1                  673 non-null object
seen_2                  571 non-null object
seen_3                  550 non-null object
seen_4                  607 non-null object
seen_5                  758 non-null object
seen_6                  738 non-null object
order_pref_1            835 non-null object
order_pref_2            836 non-null object
order_pref_3            835 non-null object
order_pref_4            836 non-null object
order_pref_5            836 non-null object
order_pref_6            836 non-null object
Han Solo                829 non-null object
Luke Skywalker          831 non-null object
Princess Leia Organa    831 non-null object
Anakin Skywalker        823 non-null object
Obi Wan Kenobi          825 non-null object
Emperor Palpatine       814 non-null object
Darth Vader             826 non-null object
Lando Calrissian        820 non-null object
Boba Fett               812 non-null object
C-3P0                   827 non-null object
R2 D2                   830 non-null object
Jar Jar Binks           821 non-null object
Padme Amidala           814 non-null object
Yoda                    826 non-null object
shot_first              828 non-null object
fam_exp_universe        828 non-null object
fan_exp_universe        213 non-null object
fan_star_treck          1068 non-null object
Gender                  1046 non-null object
Age                     1046 non-null object
Income                  858 non-null object
Education               1036 non-null object
Location                1043 non-null object
dtypes: float64(1), object(37)
memory usage: 352.2+ KB

Convert the values in the first column to integers: _____no_output_____

star_wars.iloc[:,0] = star_wars.iloc[:,0].astype(int)_____no_output_____

The titles of columns 1, 2, 31, 32, and 33 (with the convention that the first column has index 0) are yes/no questions.
These columns contain the values 'Yes' and 'No'.
To ease the analysis, we convert them to the boolean values `True` and `False`._____no_output_____

yes_no_dict = {'Yes': True, 'No': False}
column_indices = [1, 2, 30, 31, 32]
for col in column_indices:
    star_wars.iloc[:,col] = star_wars.iloc[:,col].map(yes_no_dict)_____no_output_____star_wars.head()_____no_output_____

Convert columns 2 to 8 to bool values: _____no_output_____

def is_string(val):
    return type(val) == str

for i in range(3,9):
    star_wars.iloc[:,i] = star_wars.iloc[:,i].map(is_string)_____no_output_____

Convert the orders of preference to numerical values:_____no_output_____

star_wars[star_wars.columns[9:15]] = star_wars[star_wars.columns[9:15]].astype(float)_____no_output_____star_wars.head()_____no_output_____

## Analysis

As a first indication of how much each movie is liked, we show the average ranking for each of them.
The error bars show one standard error on each side of the average._____no_output_____

ave_rankings = star_wars.iloc[:,9:15].apply(np.mean)
ste_rankings = star_wars.iloc[:,9:15].apply(np.std) / np.sqrt(star_wars.iloc[:,9:15].count())
ave_rankings.index = range(1,7)
ave_rankings.plot.bar(yerr = list(ste_rankings), rot = 0)
plt.xlabel('movie')
plt.ylabel('average ranking')
plt.show()_____no_output_____

The fifth episode has the best ranking by a statistically significant margin.
The thirs episode has the worst ranking by a statistically significant margin.

Let us now shos the number of views._____no_output_____

n_views = star_wars.iloc[:,3:9].apply(np.sum)
n_views.index = range(1,7)
n_views.plot.bar(rot = 0)
plt.xlabel('movie')
plt.ylabel('number of viewers')
plt.show()_____no_output_____

The fifth episode has the largest number of views, while the third one has the lowest number of views.
More generally, the higher the number of respondents to have seen a movie, the best its ranking is.

Let us now perform the same analysis for different groups of respondents.
We first define the functions `plot_rankings_by` and `plot_n_viewers_by` doing the bar plots given a column name by which to distinuish respondents._____no_output_____

def plot_rankings_by(col_name):
    groups = list(star_wars[col_name].dropna().unique())
    data_ave = []
    data_ste = []
    for group in groups:
        df = star_wars[star_wars[col_name] == group].iloc[:,9:15]
        data_ave.append(list(df.apply(np.mean)))
        data_ste.append(df.apply(np.std) / np.sqrt(df.count()))
    df_ave = pd.DataFrame(data_ave).transpose()
    df_ave.index = index=range(1,7)
    df_ave.columns = groups
    df_ave.plot.bar(yerr = data_ste, rot = 0)
    plt.xlabel('movie')
    plt.ylabel('average ranking')
    plt.show()

def plot_n_viewers_by(col_name):
    groups = list(star_wars[col_name].dropna().unique())
    data_count = []
    for group in groups:
        df = star_wars[star_wars[col_name] == group].iloc[:,3:9]
        data_count.append(list(df.apply(np.sum)))
    df_ave = pd.DataFrame(data_count).transpose()
    df_ave.index = index=range(1,7)
    df_ave.columns = groups
    df_ave.plot.bar(rot = 0)
    plt.xlabel('movie')
    plt.ylabel('number of viewers')
    plt.show()_____no_output_____

We first divide the respondents by gender._____no_output_____

plot_rankings_by('Gender')
plot_n_viewers_by('Gender')_____no_output_____

We notice that:
* On average, women have a better opinion than men of the first episode and a lower opinion of the fourth.
* Each episode has more male than female viewers. The gap is largest for the third episode and smallest for the fifth.
Interestingly, the fraction of women having seen an episode seems to decrese with its average ranking.

Let us compute the correlation coeficient between these two variables, as well as with the number of viewers._____no_output_____

n_female_viewers = star_wars[star_wars['Gender'] == 'Female'].iloc[:,3:9].apply(np.sum)
n_male_viewers = star_wars[star_wars['Gender'] == 'Male'].iloc[:,3:9].apply(np.sum)
frac_female_viewers = n_female_viewers / (n_female_viewers + n_male_viewers)

print('correlation coefficient between the fraction of female viewers and average ranking: {}'.format(np.corrcoef(list(frac_female_viewers), list(ave_rankings))[0][1]))
print('correlation coefficient between the fraction of female viewers and number of viewers: {}'.format(np.corrcoef(list(frac_female_viewers), list(n_views))[0][1]))correlation coefficient between the fraction of female viewers and average ranking: -0.8460698256979539
correlation coefficient between the fraction of female viewers and number of viewers: 0.9942656122597326

*There is a strong negative correlation between the fraction of female viewers and average  ranking, and a very strong positive correlation between the fraction of female viewers and total number of viewers.*

Let us now distinguish between viewers depending on whether they identify as fans of the tar Wars franchise._____no_output_____

plot_rankings_by('fan')
plot_n_viewers_by('fan')_____no_output_____

*Respondents who identify as fans have a significantly higher opinion of the oldest trilogy (episodes 4, 5, and 6) and a lower opinion of te newer one (episodes 1, 2, and 3).*
For each episode, a large majority of respondents who has seen it identifies as a fan of the franchise.

Finally, let us distinguish between viewers depending on whether they identify as fans of the Start Treck franchise._____no_output_____

plot_rankings_by('fan_star_treck')
plot_n_viewers_by('fan_star_treck')_____no_output_____

Viewers who identify as fans of the Star Treck franchise tend to also have a better opinion of the older trilogy and and lower opinion of the newer one.
They also from a majority (although smaller than that of Star Wars self-identified fans) in the viewership of each episode. _____no_output_____ To do:

 Segment the data by Education, Location, and “Which character shot first?” question

 find the best-liked, least-liked, and most controversial characters

_____no_output_____


# Notebook from JonETJakobsson/dmrt3-single-cell
Path: Sequencing_pipeline/workflow/workbooks/Untitled.ipynb

<code>
import scanpy as sc_____no_output_____adata = sc.read_loom("../../results/loom/mmusculus.loom")Variable names are not unique. To make them unique, call `.var_names_make_unique`.
adata.var_____no_output_____adata.X = adata.layers["RPKM"]_____no_output_____sc.pp.calculate_qc_metrics(adata, inplace=True)_____no_output_____sc.pp.log1p(adata)_____no_output_____adata.var.loc[["Cre", "tdTomato"]]_____no_output_____sc.pl.scatter(adata, x="log1p_mean_counts", y="gene_lenght")Observation names are not unique. To make them unique, call `.obs_names_make_unique`.
/home/jon/miniconda3/envs/npy/lib/python3.8/site-packages/anndata/_core/anndata.py:1192: FutureWarning: is_categorical is deprecated and will be removed in a future version.  Use is_categorical_dtype instead
  if is_string_dtype(df[key]) and not is_categorical(df[key])
... storing 'Chromosome' as categorical
adata.obs_____no_output_____sc.pl.scatter(adata, x="log1p_n_genes_by_counts", y="pct_counts_in_top_50_genes", color="tdTomato")/home/jon/miniconda3/envs/npy/lib/python3.8/site-packages/anndata/_core/anndata.py:1192: FutureWarning: is_categorical is deprecated and will be removed in a future version.  Use is_categorical_dtype instead
  if is_string_dtype(df[key]) and not is_categorical(df[key])
... storing 'Chromosome' as categorical
sc.pl.violin(adata, keys=["tdTomato", "Cre", "Bhlhe22"])_____no_output_____adata.var_names_____no_output_____sc.pl.scatter(adata, x="tdTomato", y="Wt1", color="Dmrt3")_____no_output_____
</code>


# Notebook from shiwei23/Chromatin_Analysis_Scripts
Path: Adaptor_design/Design_ligation_probes.ipynb

# Design ligation probes and branch-tree amplification

by Pu Zheng

2020.1.11_____no_output_____

<code>
%run "E:\Users\puzheng\Documents\Startup_py3.py"
sys.path.append(r"E:\Users\puzheng\Documents")

import ImageAnalysis3 as ia
%matplotlib notebook

from ImageAnalysis3 import *
print(os.getpid())3120
# biopython imports
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
from Bio.SeqRecord import SeqRecord
from Bio.Blast.Applications import NcbiblastnCommandline
from Bio.Blast import NCBIXML_____no_output_____primer_folder = r'\\10.245.74.212\Chromatin_NAS_2\Libraries\Primers'
primers = library_tools.probes.load_primers([2,9], _primer_folder=primer_folder)- Picked primer: ID: W1A03_primer_2
Name: W1A03_primer_2
Description: W1A03_primer_2
Number of features: 0
Seq('CCCGCAATGGCTGACAACCG', SingleLetterAlphabet())
- Picked primer: ID: W1A10_primer_9
Name: W1A10_primer_9
Description: W1A10_primer_9
Number of features: 0
Seq('TAATACGACTCACTATAGGGATTGCCGCATGGTTTCCG', SingleLetterAlphabet())
# ligation probe
primers[0]
_____no_output_____ligation_probe = primers[0].reverse_complement() + primers[1][-20:]
ligation_probe.id = f'{primers[0].id}-rc_{primers[1].id}'_____no_output_____
</code>


# Notebook from keesterbrugge/python-causality-handbook
Path: causal-inference-for-the-brave-and-true/05-The-Unreasonable-Effectiveness-of-Linear-Regression.ipynb

# 05 - The Unreasonable Effectiveness of Linear Regression

## All You Need is Regression

When dealing with causal inference, we saw how there are two potential outcomes for each individual: $Y_0$ is the outcome the individual would have if he or she didn't take the treatment and $Y_1$ is the outcome if he or she took the treatment. The act of setting the treatment $T$ to 0 or 1 materializes one of the potential outcomes and makes it impossible for us to ever know the other one. This leads to the fact that the individual treatment effect $\tau_i = Y_{1i} - Y_{0i}$ is unknowable.

$
Y_i = Y_{0i} + T_i(Y_{1i} - Y_{0i}) = Y_{0i}(1-T_i) + T_i Y_{1i}
$

So, for now, let's focus, on the simpler task of estimating the average causal effect. With this in mind, we are accepting the fact that some people respond better than others to the treatment, but we are also accepting that we can't know who they are. Instead, we will just try to see if the treatment works, **on average**.

$
ATE = E[Y_1 - Y_0]
$

This will give us a simplified model, with a constant treatment effect $Y_{1i} = Y_{0i} + \kappa$. If $\kappa$ is positive, we will say that the treatment has, on average, a positive effect. Even if some people will respond badly to it, on average, the impact will be positive.

Let's also recall that we can't simply estimate $E[Y_1 - Y_0]$ with the difference in mean $E[Y|T=1] - E[Y|T=0]$ due to bias. Bias often arises when the treated and untreated are different for reasons other than the treatment itself. One way to see this is on how they differ in the potential outcome $Y_0$

$
E[Y|T=1] - E[Y|T=0] = \underbrace{E[Y_1 - Y_0|T=1]}_{ATET} + \underbrace{\{ E[Y_0|T=1] - E[Y_0|T=0]\}}_{BIAS}
$

Previously, we saw how we can eliminate bias with Random Experiments, or **Randomised Controlled Trial** (RCT) as they are sometimes called. RCT forces the treated and the untreated to be equal and that's why the bias vanishes. We also saw how to place uncertainty levels around our estimates for the treatment effect. Namely, we looked at the case of online versus face-to-face classrooms, where $T=0$ represent face-to-face lectures and $T=1$ represent online ones. Students were randomly assigned to one of those 2 types of lectures and then their performance on an exam was evaluated. We've built an A/B testing function that could compare both groups, provide the average treatment effect and even place a confidence interval around it.

Now, it's time to see that we can do all of that with the workhorse of causal inference: **Linear Regression**! Think of it this way. If comparing treated and untreated means was an apple for dessert, linear regression would be cold and creamy tiramisu. Or if comparing treated and untreated is a sad and old loaf of white wonder bread, linear regression would be a crusty, soft crumb country loaf sourdough baked by Chad Robertson himself.

![img](./data/img/linear-regression/you_vs.png)

Lets see how this beauty works. In the code below, we want to run the exact same analysis of comparing online vs face-to-face classes. But instead of doing all that math of confidence intervals, we just run a regression. More specifically, we estimate the following model:

$
exam_i = \beta_0 + \kappa \ Online_i + u_i
$

This means we are modeling the exam outcome as a baseline $\beta_0$ plus $\kappa$ if the class is online.  Of course the exam result is driven by additional variables (like student's mood on the exam day, hours studied and so on). But we don't really care about understanding those relationships. So, instead, we use that $u_i$ term to represent everything else we don't care about. This is called the model error.

Notice that $Online$ is our treatment indication and hence, a dummy variable. It is zero when the treatment is face to face and 1 if it's online. With that in mind, we can see that linear regression will recover $E[Y|T=0] = \beta_0$ and $E[Y|T=1] = \beta_0 + \kappa $. $\kappa$ will be our ATE._____no_output_____

import warnings
warnings.filterwarnings('ignore')

import pandas as pd
import numpy as np
import statsmodels.formula.api as smf
import graphviz as gr
%matplotlib inline_____no_output_____data = pd.read_csv("data/online_classroom.csv").query("format_blended==0")

result = smf.ols('falsexam ~ format_ol', data=data).fit()
result.summary().tables[1]_____no_output_____

That's quite amazing. We are not only able to estimate the ATE, but we also get, for free, confidence intervals and P-Values out of it! More than that, we can see that regression is doing exactly what it supposed to do: comparing $E[Y|T=0]$ and $E[Y|T=1]$. The intercept is exactly the sample mean when $T=0$, $E[Y|T=0]$, and the coefficient of the online format is exactly the sample difference in means $E[Y|T=1] - E[Y|T=0]$. Don't trust me? No problem. You can see for yourself:_____no_output_____

(data
 .groupby("format_ol")
 ["falsexam"]
 .mean())_____no_output_____

As expected. If you add to the intercept the ATE, that is, the parameter estimate of online format, you get the sample mean for the treated: $78.5475 + (-4.9122) = 73.635263$.

## Regression Theory

I don't intend to dive too deep into how linear regression is constructed and estimated. However, a little bit of theory will go a long way in explaining its power in causal inference. First of all, regression solves a theoretical best linear prediction problem. Let $\beta^*$ be a vector of parameters:

$
\beta^* =\underset{\beta}{argmin} \ E[(Y_i - X_i'\beta)^2]
$

Linear regression finds the parameters that minimise the mean squared error (MSE).

If you differentiate it and set it to zero, you will find that the linear solution to this problem is given by

$
\beta^* = E[X_i'X_i]^{-1}E[X_i' Y_i]
$

We can estimate this beta using the sample equivalent:

$
\hat{\beta} = (X'X)^{-1}X' Y
$

But don't take my word for it. If you are one of those that understand code better than formulas, try for yourself:_____no_output_____

X = data[["format_ol"]].assign(intercep=1)
y = data["falsexam"]

def regress(y, X):
    return np.linalg.inv(X.T.dot(X)).dot(X.T.dot(y))

beta = regress(y, X)
beta_____no_output_____

The formulas above are pretty general. However, it pays off to study the case where we only have one regressor. In causal inference, we often want to estimate the causal impact of a variable $T$ on an outcome $y$. So, we use regression with this single variable to estimate this effect. Even if we include other variables in the model, they are usually just auxiliary. Adding other variables can help us estimate the causal effect of the treatment, but we are not very interested in estimating their parameters.

With a single regressor variable $T$, the parameter associated to it will be given by

$
\beta_1 = \dfrac{Cov(Y_i, T_i)}{Var(T_i)}
$

If $T$ is randomly assigned, $\beta_1$ is the ATE._____no_output_____

kapa = data["falsexam"].cov(data["format_ol"]) / data["format_ol"].var()
kapa_____no_output_____

If we have more than one regressor, we can extend the following formula to accommodate that. Let's say those other variables are just auxiliary and that we are truly interested only in estimating the parameter $\kappa$ associated to $T$.

$
y_i = \beta_0 + \kappa T_i + \beta_1 X_{1i} + ... +\beta_k X_{ki} + u_i
$

$\kappa$ can be obtained with the following formula

$
\kappa = \dfrac{Cov(Y_i, \tilde{T_i})}{Var(\tilde{T_i})}
$

where $\tilde{T_i}$ is the residual from a regression of all other covariates $X_{1i} + ... + X_{ki}$ on $T_i$. Now, let's appreciate how cool this is. It means that the coefficient of a multivariate regression is the bivariate coefficient of the same regressor **after accounting for the effect of other variables in the model**. In causal inference terms, $\kappa$ is the bivariate coefficient of $T$ after having used all other variables to predict it.

This has a nice intuition behind it. If we can predict $T$ using other variables, it means it's not random. However, we can make it so that $T$ is as good as random once we control for other available variables. To do so, we use linear regression to predict it from the other variables and then we take the residuals of that regression $\tilde{T}$. By definition, $\tilde{T}$ cannot be predicted by the other variables $X$ that we've already used to predict $T$. Quite elegantly, $\tilde{T}$ is a version of the treatment that is not associated with any other variable in $X$.

By the way, this is also a property of linear regression. The residual are always orthogonal or uncorrelated with any of the variables in the model that created it:_____no_output_____

e = y - X.dot(beta)
print("Orthogonality imply that the dot product is zero:", np.dot(e, X))
X[["format_ol"]].assign(e=e).corr()Orthogonality imply that the dot product is zero: [7.81597009e-13 4.63984406e-12]

And what is even cooler is that these properties don't depend on anything! They are mathematical truths, regardless of what your data looks like.

## Regression For Non-Random Data

So far, we worked with random experiment data but, as we know, those are hard to come by. Experiments are very expensive to conduct or simply infeasible. It's very hard to convince McKinsey & Co. to randomly provide their services free of charge so that we can, once and for all, distinguish the value their consulting services brings from the fact that those firms that can afford to pay them are already very well off.

For this reason, we shall now delve into non random or observational data. In the following example, we will try to estimate the impact of an additional year of education on hourly wage. As you might have guessed, it is extremely hard to conduct an experiment with education. You can't simply randomize people to 4, 8 or 12 years of education. In this case observational data is all we have.

First, let's estimate a very simple model. We will regress log hourly wages on years of education. We use logs here so that our parameter estimates have a percentage interpretation (if you never heard about this amazing properties of the log and want to know why that is, check out [this link](https://stats.stackexchange.com/questions/244199/why-is-it-that-natural-log-changes-are-percentage-changes-what-is-about-logs-th)). With it, we will be able to say that 1 extra year of education yields a wage increase of x%.

$
log(hwage)_i = \beta_0 + \beta_1 educ_i + u_i
$_____no_output_____

wage = pd.read_csv("./data/wage.csv").dropna()
model_1 = smf.ols('np.log(hwage) ~ educ', data=wage.assign(hwage=wage["wage"]/wage["hours"])).fit()
model_1.summary().tables[1]_____no_output_____

The estimate of $\beta_1$ is 0.0536, with a 95% confidence interval of (0.039, 0.068). This means that this model predicts that wages will increase about 5.3% for every additional year of education. This percentage increase is inline with the belief that education impacts wages in an exponential fashion: we expect that going from 11 to 12 years of education (average to graduate high school) to be less rewarding than going from 14 to 16 years (average to graduate college)._____no_output_____

from matplotlib import pyplot as plt
from matplotlib import style
style.use("fivethirtyeight")

x = np.array(range(5, 20))
plt.plot(x, np.exp(model_1.params["Intercept"] + model_1.params["educ"] * x))
plt.xlabel("Years of Education")
plt.ylabel("Hourly Wage")
plt.title("Impact of Education on Hourly Wage")
plt.show()_____no_output_____

Of course, it is not because we can estimate this simple model that it's correct. Notice how I was carefully with my words saying it **predicts** wage from education. I never said that this prediction was causal. In fact, by now, you probably have very serious reasons to believe this model is biased. Since our data didn't come from a random experiment, we don't know if those that got more education are comparable to those who got less. Going even further, from our understanding of how the world works, we are very certain that they are not comparable. Namely, we can argue that those with more years of education probably have richer parents, and that the increase we are seeing in wages as we increase education is just a reflection of how the family wealth is associated with more years of education. Putting it in math terms, we think that $E[Y_0|T=0] < E[Y_0|T=1]$, that is, those with more education would have higher income anyway, even without so many years of education. If you are really grim about education, you can argue that it can even *reduce* wages by keeping people out of the workforce and lowering their experience.

Fortunately, in our data, we have access to lots of other variables. We can see the parents' education `meduc`, `feduc`, the `IQ` score for that person, the number of years of experience `exper` and the tenure of the person in his or her current company `tenure`. We even have some dummy variables for marriage and black ethnicity. _____no_output_____

wage.head()_____no_output_____

We can include all those extra variables in a model and estimate it:

$
log(hwage)_i = \beta_0 + \kappa \ educ_i + \pmb{\beta}X_i + u_i
$

To understand how this helps with the bias problem, let's recap the bivariate breakdown of multivariate linear regression.

$
\kappa = \dfrac{Cov(Y_i, \tilde{T_i})}{Var(\tilde{T_i})}
$

This formula says that we can predict `educ` from the parents' education, from IQ, from experience and so on. After we do that, we'll be left with a version of `educ`, $\tilde{educ}$, which is uncorrelated with all the variables included previously. This will break down arguments such as "people that have more years of education have it because they have higher IQ. It is not the case that education leads to higher wages. It is just the case that it is correlated with IQ, which is what drives wages". Well, if we include IQ in our model, then $\kappa$ becomes the return of an additional year of education while keeping IQ fixed. Pause a little bit to understand what this implies. Even if we can't use randomised controlled trials to keep other factors equal between treated and untreated, regression can do this by including those same factors in the model, even if the data is not random!_____no_output_____

controls = ['IQ', 'exper', 'tenure', 'age', 'married', 'black',
            'south', 'urban', 'sibs', 'brthord', 'meduc', 'feduc']

X = wage[controls].assign(intercep=1)
t = wage["educ"]
y = wage["lhwage"]

beta_aux = regress(t, X)
t_tilde = t - X.dot(beta_aux)

kappa = t_tilde.cov(y) / t_tilde.var()
kappa_____no_output_____

This coefficient we've just estimated tells us that, for people with the same IQ, experience, tenure, age and so on, we should expect an additional year of education to be associated with a 4.11% increase in hourly wage. This confirms our suspicion that the first simple model with only `educ` was biased. It also confirms that this bias was overestimating the impact of education. Once we controlled for other factors, the estimated impact of education fell.

If we are wiser and use software that other people wrote instead of coding everything yourself, we can even place a confidence interval around this estimate. _____no_output_____

model_2 = smf.ols('lhwage ~ educ +' + '+'.join(controls), data=wage).fit()
model_2.summary().tables[1]_____no_output_____

## Omitted Variable or Confounding Bias

The question that remains is: is this parameter we've estimated causal? Unfortunately, we can't say for sure. We can argue that the first simple model that regress wage on education probably isn't. It omits important variables that are correlated both with education and with wages. Without controlling for them, the estimated impact of education is also capturing the impact of those other variables that were not included in the model.

To better understand how this bias work, let's suppose the true model for how education affects wage looks a bit like this

$
Wage_i = \alpha + \kappa \ Educ_i + A_i'\beta + u_i
$

wage is affected by education, which is measured by the size of $\kappa$ and by additional ability factors, denoted as the vector $A$. If we omit ability from our model, our estimate for $\kappa$ will look like this:

$
\dfrac{Cov(Wage_i, Educ_i)}{Var(Educ_i)} = \kappa + \beta'\delta_{Ability}
$

where $\delta_{A}$ is the vector of coefficients from the regression of $A$ on $Educ$

The key point here is that it won't be exactly the $\kappa$ that we want. Instead, it comes with this extra annoying term $\beta'\delta_{A}$. This term is the impact of the omitted $A$ on $Wage$, $\beta$ times the impact of the omitted on the included $Educ$. This is important for economists that Joshua Angrist made a mantra out of it so that the students can recite it in meditation:

```
"Short equals long
plus the effect of omitted
times the regression of omitted on included"
```

Here, the short regression is the one that omits variables, while the long is the one that includes them. This formula or mantra gives us further insight into the nature of bias. First, the bias term will be zero if the omitted variables have no impact on the dependent variable $Y$. This makes total sense. I don't need to control for stuff that is irrelevant for wages when trying to understand the impact of education on it (like how tall the lilies of the field). Second, the bias term will also be zero if the omitted variables have no impact on the treatment variable. This also makes intuitive sense. If everything that impacts education has been included in the model, there is no way the estimated impact of education is mixed with a correlation from education on something else that also impacts wages.

![img](data/img/linear-regression/confused_cat.png)

To put it more succinctly, we say that **there is no OVB if all the confounding variables are accounted for in the model**. We can also leverage our knowledge about causal graphs here. A confounding variable is one that **causes both the treatment and the outcome**. In the wage example, IQ is a confounder. People with high IQ tend to complete more years of education because it's easier for them, so we can say that IQ causes education. People with high IQ also tend to be naturally more productive and consequently have higher wages, so IQ also causes wage. Since confounders are variables that affect both the treatment and the outcome, we mark them with an arrow going to T and Y. Here, I've denoted them with $W$. I've also marked positive causation with red and negative causation with blue._____no_output_____

g = gr.Digraph()

g.edge("W", "T"), g.edge("W", "Y"), g.edge("T", "Y")

g.edge("IQ", "Educ", color="red"), g.edge("IQ", "Wage", color="red"), g.edge("Educ", "Wage", color="red")

g.edge("Crime", "Police", color="red"), g.edge("Crime", "Violence", color="red"),
g.edge("Police", "Violence", color="blue")

g_____no_output_____

Causal graphs are excellent to depict our understanding of the world and understand how confounding bias works. In our first example, we have a graph where education causes wage: more education leads to higher wages. However, IQ also causes wage and it also causes education: high IQ causes both more education and wage. If we don't account for IQ in our model, some of its effect on wage will flow through the correlation with education. That will make the impact of education look higher than it actually is. This is an example of positive bias.

Just to give another example, but with negative bias, consider the causal graph about the effect of police on city violence. What we usually see in the world is that cities with higher police force also have more violence. Does this mean that the police are causing the violence? Well, it could be, I don't think it's worth getting into that discussion here. But, there is also a strong possibility that there is a confounding variable causing us to see a biased version of the impact of police on violence. It could be that increasing police force decreases violence. But, a third variable crime, causes both more violence and more police force. If we don't account for it, the impact of crime on violence will flow through police force, making it look like it increases violence. This is an example of negative bias.

Causal graphs can also show us how both regression and randomized control trials are correct for confounding bias. RCT does so by severing the connection of the confounder to the treatment variable. By making $T$ random, by definition, nothing can cause it. _____no_output_____

g = gr.Digraph()

g.edge("W", "Y"), g.edge("T", "Y")

g.edge("IQ", "Wage", color="red"), g.edge("Educ", "Wage", color="red")

g_____no_output_____

Regression, on the other hand, does so by comparing the effect of $T$ while maintaining the confounder $W$ set to a fixed level. With regression, it is not the case that W cease to cause T and Y. It is just that it is held fixed, so it can't influence changes on T and Y._____no_output_____

g = gr.Digraph()

g.node("W=w"), g.edge("T", "Y")
g.node("IQ=x"), g.edge("Educ", "Wage", color="red")

g_____no_output_____

Now, back to our question, is the parameter we've estimated for the impact of `educ` on wage causal? I'm sorry to bring it to you, but that will depend on our ability to argue in favor or against that fact that all confounders have been included in the model. Personally, I think they haven't. For instance, we haven't included family wealth. Even if we included family education, that can only be seen as a proxy for wealth. We've also not accounted for factors like personal ambition. It could be that ambition is what causes both more years of education and higher wage, so it is a confounder. This is to show that **causal inference with non-random or observational data should always be taken with a grain of salt**. We can never be sure that all confounders were accounted for.

## Key Ideas

We've covered a lot of ground with regression. We saw how regression can be used to perform A/B testing and how it conveniently gives us confidence intervals. Then, we moved to study how regression solves a prediction problem and it is the best linear approximation to the CEF. We've also discussed how, in the bivariate case, the regression treatment coefficient is the covariance between the treatment and the outcome divided by the variance of the treatment. Expanding to the multivariate case, we figured out how regression gives us a partialling out interpretation of the treatment coefficient: it can be interpreted as how the outcome would change with the treatment while keeping all other included variables constant. This is what economists love to refer as *ceteris paribus*.

Finally, we took a turn to understanding bias. We saw how `Short equals long plus the effect of omitted times the regression of omitted on included`. This shed some light to how bias comes to be. We discovered that the source of omitted variable bias is confounding: a variable that affects both the treatment and the outcome. Lastly, we used causal graphs to see how RCT and regression fixes confounding.

## References

I like to think of this entire book as a tribute to Joshua Angrist, Alberto Abadie and Christopher Walters for their amazing Econometrics class. Most of the ideas here are taken from their classes at the American Economic Association. Watching them is what is keeping me sane during this tough year of 2020.
* [Cross-Section Econometrics](https://www.aeaweb.org/conference/cont-ed/2017-webcasts)
* [Mastering Mostly Harmless Econometrics](https://www.aeaweb.org/conference/cont-ed/2020-webcasts)

I'll also like to reference the amazing books from Angrist. They have shown me that Econometrics, or 'Metrics as they call it, is not only extremely useful but also profoundly fun.

* [Mostly Harmless Econometrics](https://www.mostlyharmlesseconometrics.com/)
* [Mastering 'Metrics](https://www.masteringmetrics.com/)

My final reference is Miguel Hernan and Jamie Robins' book. It has been my trustworthy companion in the most thorny causal questions I had to answer.

* [Causal Inference Book](https://www.hsph.harvard.edu/miguel-hernan/causal-inference-book/)

![img](./data/img/poetry.png)

## Contribute

Causal Inference for the Brave and True is an open-source material on causal inference, the statistics of science. It uses only free software, based in Python. Its goal is to be accessible monetarily and intellectually.
If you found this book valuable and you want to support it, please go to [Patreon](https://www.patreon.com/causal_inference_for_the_brave_and_true). If you are not ready to contribute financially, you can also help by fixing typos, suggesting edits or giving feedback on passages you didn't understand. Just go to the book's repository and [open an issue](https://github.com/matheusfacure/python-causality-handbook/issues). Finally, if you liked this content, please share it with others who might find it useful and give it a [star on GitHub](https://github.com/matheusfacure/python-causality-handbook/stargazers)._____no_output_____


# Notebook from MCSZN/qna
Path: notebooks/QnA/plot_res.ipynb

<code>
import json
with open("../../results/results.json", 'r') as f:
    results = json.load(f)

from matplotlib import pyplot as plt

trg_0 = [val[1] for val in results.values() if val[0]==0]
trg_1 = [val[1] for val in results.values() if val[0]==1]

plt.figure(figsize=(11,4))
plt.plot(trg_0, label="trg_0")
plt.plot(trg_1, label="trg_1")
plt.title('Evolution of loss during training')
plt.ylabel('Loss')
plt.legend()
plt.show()_____no_output_____
</code>