def get_ratio_data(vocabpath, sizecap, ratio, tags4positive, tags4negative, excludebelow=0, excludeabove=3000):
    " Loads metadata, selects instances for the positive\n    and negative classes (using a ratio to dilute the positive\n    class with negative instances), creates a lexicon if one doesn't\n    already exist, and creates a pandas dataframe storing\n    texts as rows and words/features as columns. A refactored\n    and simplified version of get_data_for_model().\n    "
    holdout_authors = True
    freqs_already_normalized = True
    verbose = False
    datecols = ['firstpub']
    indexcol = ['docid']
    extension = '.tsv'
    genrecol = 'tags'
    numfeatures = 8000
    sourcefolder = '../data/'
    metadatapath = '../metadata/mastermetadata.csv'
    allthefiles = os.listdir(sourcefolder)
    volumeIDsinfolder = list()
    volumepaths = list()
    numchars2trim = len(extension)
    for filename in allthefiles:
        if filename.endswith(extension):
            volID = filename[0:(- numchars2trim)]
            volumeIDsinfolder.append(volID)
    metadata = metaselector.load_metadata(metadatapath, volumeIDsinfolder, excludebelow, excludeabove, indexcol=indexcol, datecols=datecols, genrecol=genrecol)
    (orderedIDs, classdictionary) = metaselector.dilute_positive_class(metadata, sizecap, tags4positive, tags4negative, ratio)
    metadata = metadata.loc[orderedIDs]
    volspresent = [(x, ((sourcefolder + x) + extension)) for x in orderedIDs]
    print(len(volspresent))
    print('Building vocabulary.')
    vocablist = versatiletrainer2.get_vocablist(vocabpath, volspresent, n=numfeatures)
    numfeatures = len(vocablist)
    print()
    print(('Number of features: ' + str(numfeatures)))
    authormatches = [[] for x in orderedIDs]
    if holdout_authors:
        for (idx1, anid) in enumerate(orderedIDs):
            thisauthor = metadata.loc[(anid, 'author')]
            authormatches[idx1] = list(np.flatnonzero((metadata['author'] == thisauthor)))
    for alist in authormatches:
        alist.sort(reverse=True)
    print()
    print('Authors matched.')
    print()
    (masterdata, classvector) = versatiletrainer2.get_dataframe(volspresent, classdictionary, vocablist, freqs_already_normalized)
    return (metadata, masterdata, classvector, classdictionary, orderedIDs, authormatches, vocablist)
Loads metadata, selects instances for the positive
and negative classes (using a ratio to dilute the positive
class with negative instances), creates a lexicon if one doesn't
already exist, and creates a pandas dataframe storing
texts as rows and words/features as columns. A refactored
and simplified version of get_data_for_model().
def get_ratio_data(vocabpath, sizecap, ratio, tags4positive, tags4negative, excludebelow=0, excludeabove=3000):
    " Loads metadata, selects instances for the positive\n    and negative classes (using a ratio to dilute the positive\n    class with negative instances), creates a lexicon if one doesn't\n    already exist, and creates a pandas dataframe storing\n    texts as rows and words/features as columns. A refactored\n    and simplified version of get_data_for_model().\n    "
    holdout_authors = True
    freqs_already_normalized = True
    verbose = False
    datecols = ['firstpub']
    indexcol = ['docid']
    extension = '.tsv'
    genrecol = 'tags'
    numfeatures = 8000
    sourcefolder = '../data/'
    metadatapath = '../metadata/mastermetadata.csv'
    allthefiles = os.listdir(sourcefolder)
    volumeIDsinfolder = list()
    volumepaths = list()
    numchars2trim = len(extension)
    for filename in allthefiles:
        if filename.endswith(extension):
            volID = filename[0:(- numchars2trim)]
            volumeIDsinfolder.append(volID)
    metadata = metaselector.load_metadata(metadatapath, volumeIDsinfolder, excludebelow, excludeabove, indexcol=indexcol, datecols=datecols, genrecol=genrecol)
    (orderedIDs, classdictionary) = metaselector.dilute_positive_class(metadata, sizecap, tags4positive, tags4negative, ratio)
    metadata = metadata.loc[orderedIDs]
    volspresent = [(x, ((sourcefolder + x) + extension)) for x in orderedIDs]
    print(len(volspresent))
    print('Building vocabulary.')
    vocablist = versatiletrainer2.get_vocablist(vocabpath, volspresent, n=numfeatures)
    numfeatures = len(vocablist)
    print()
    print(('Number of features: ' + str(numfeatures)))
    authormatches = [[] for x in orderedIDs]
    if holdout_authors:
        for (idx1, anid) in enumerate(orderedIDs):
            thisauthor = metadata.loc[(anid, 'author')]
            authormatches[idx1] = list(np.flatnonzero((metadata['author'] == thisauthor)))
    for alist in authormatches:
        alist.sort(reverse=True)
    print()
    print('Authors matched.')
    print()
    (masterdata, classvector) = versatiletrainer2.get_dataframe(volspresent, classdictionary, vocablist, freqs_already_normalized)
    return (metadata, masterdata, classvector, classdictionary, orderedIDs, authormatches, vocablist)