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)
bag_of_features_transformer.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录