使用 pythonwekawrapper3 后获取与结果相关的特定值
Getting specfic values related to result after using pythonwekawrapper3
我正在使用 Pythonwekawrapper3 进行属性选择,这样我就可以删除剩余的属性并在 python 代码中使用选定的属性来制作集成学习器。但是我在仅从 weka 包装器给出的结果中获取 "Selected attributes:" 部分时遇到了问题。我想要的是一个包含所有选定属性的变量,但我不知道如何。
我在网上搜索了它,但无法找到一种方法来仅从 result_string 获取选定的属性。
search = ASSearch(classname="weka.attributeSelection.GeneticSearch", options=["-Z", "50", "-G", "100", "-C", "0.9","-M", "0.1"])
evaluator = ASEvaluation(classname="weka.attributeSelection.CfsSubsetEval", options=["-P", "1", "-E", "1"])
attsel = AttributeSelection()
attsel.search(search)
attsel.evaluator(evaluator)
attsel.select_attributes(data)
print("# attributes: " + str(attsel.number_attributes_selected))
print("attributes: " + str(attsel.selected_attributes))
print("result string:\n" + attsel.results_string)
|所选属性:2,3,7,8,9,10,11,12,13 #
变量=[2,3,7,8,9,10,11,12,13]
AttributeSelection.selected_attributes
returns 一个 numpy 数组,其中包含所选属性的从 0 开始的索引 (documentation)。
如果您想要一个列表,只需使用 list(...)
,例如:
list_of_sel_atts = list(attsel.selected_attributes))
print(list_of_sel_atts)
我正在使用 Pythonwekawrapper3 进行属性选择,这样我就可以删除剩余的属性并在 python 代码中使用选定的属性来制作集成学习器。但是我在仅从 weka 包装器给出的结果中获取 "Selected attributes:" 部分时遇到了问题。我想要的是一个包含所有选定属性的变量,但我不知道如何。
我在网上搜索了它,但无法找到一种方法来仅从 result_string 获取选定的属性。
search = ASSearch(classname="weka.attributeSelection.GeneticSearch", options=["-Z", "50", "-G", "100", "-C", "0.9","-M", "0.1"])
evaluator = ASEvaluation(classname="weka.attributeSelection.CfsSubsetEval", options=["-P", "1", "-E", "1"])
attsel = AttributeSelection()
attsel.search(search)
attsel.evaluator(evaluator)
attsel.select_attributes(data)
print("# attributes: " + str(attsel.number_attributes_selected))
print("attributes: " + str(attsel.selected_attributes))
print("result string:\n" + attsel.results_string)
|所选属性:2,3,7,8,9,10,11,12,13 #
变量=[2,3,7,8,9,10,11,12,13]
AttributeSelection.selected_attributes
returns 一个 numpy 数组,其中包含所选属性的从 0 开始的索引 (documentation)。
如果您想要一个列表,只需使用 list(...)
,例如:
list_of_sel_atts = list(attsel.selected_attributes))
print(list_of_sel_atts)