utils.py 917 字节
Newer Older
O
overlordmax 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import numpy as np 
import os
import paddle.fluid as fluid

class CriteoDataset(object):

    def _reader_creator(self, file):
        def reader():
            with open(file, 'r') as f:
                for i,line in enumerate(f):
                    if i == 0:
                        continue
                    line = line.strip().split(',')
                    features = list(map(float, line))
                    wide_feat = features[0:8]
                    deep_feat = features[8:58+8]
                    label = features[-1]
                    output = []
                    output.append(wide_feat)
                    output.append(deep_feat)
                    output.append([label])
                    
                    yield output

        return reader

    def train(self, file):
        return self._reader_creator(file)

    def test(self, file):
        return self._reader_creator(file)