bag_of_features_transformer.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:xpandas 作者: alan-turing-institute 项目源码 文件源码
def __init__(self, dictionary=None, **kwargs):
        '''
        :param dictionary: custom dictionary to count against. if None, calculate dictionary from dataset
        '''
        self.dictionary = dictionary

        accepted_types = [
            pd.Series, list, np.array, tuple
        ]

        def bag_of_words_transform_function(corpus):
            counter = Counter(corpus)
            for el in self.dictionary:
                if counter.get(el) is None:
                    counter[el] = 0
            return counter

        super(BagOfWordsTransformer, self).__init__(data_types=accepted_types,
                                                    columns=None,
                                                    transform_function=bag_of_words_transform_function)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号