【发布时间】:2022-11-04 00:34:33
【问题描述】:
我有一个我一直在处理的配置文件,例如:
"Preprocessing": {
"BOW":{"ngram_range":[1,2], "max_features":[100, 200]},
"RemoveStopWords": {"Parameter1": ["..."]}
}
这个想法是获取这些数据并在两个预处理步骤之间运行每次迭代,并将其传递给 Preprocessing 对象。我正在寻找的输出是:
[{"BOW":{"ngram_range":1, "max_features":100}, "RemoveStopWords":{"Parameter1": "..."},
{"BOW":{"ngram_range":2, "max_features":100}, "RemoveStopWords":{"Parameter1": "..."},
{"BOW":{"ngram_range":1, "max_features":200}, "RemoveStopWords":{"Parameter1": "..."},
{"BOW":{"ngram_range":2, "max_features":200}, "RemoveStopWords":{"Parameter1": "..."}]
当前代码:
def unpack_preprocessing_steps(preprocessing: dict):
"""
This script will take the Preprocessing section of the config file
and produce a list of preprocessing combinations.
"""
preprocessing_steps = [] # save for all steps bow, w2v, etc.
preprocessing_params = [] # individual parameters for each preprocessing step
for key, values in preprocessing.items():
preprocessing_steps.append(key)
for _, values2 in values.items():
preprocessing_params.append(values2)
iterables = product(*preprocessing_params) # Creates a matrix of every combination
iterable_of_params = [i for i in iterables]
exploded_preprocessing_list = []
for params in iterable_of_params:
individual_objects = {} # store each object as an unpackable datatype
for step, param in zip(preprocessing_steps, params):
individual_objects[step] = param # This stores ever iteration as it's own set of preprocesses
exploded_preprocessing_list.append(individual_objects)
return exploded_preprocessing_list
当前输出(和错误)输出为:
[{"BOW":1, "RemoveStopWords":100},
{"BOW":2, "RemoveStopWords":200}]
【问题讨论】:
标签: python machine-learning data-structures statistics