Python weka包装器属性选择

时间:2015-08-10 19:41:19

标签: python wrapper weka

问题:我正在使用python weka包装器进行属性选择过程,但我只能为最后一个或第一个属性运行它。关于如何运行任何属性的任何想法?

代码:

# load a dataset
test_file = helper.get_data_dir() + os.sep + "test.arff"
helper.print_info("Loading dataset: " + test_file)
loader = Loader("weka.core.converters.ArffLoader")
test_data = loader.load_file(test_file)
test_data.class_is_last()

# perform attribute selection
helper.print_title("Attribute selection")
search = ASSearch(classname="weka.attributeSelection.BestFirst", options=["-D", "1", "-N", "5"])
evaluation = ASEvaluation(classname="weka.attributeSelection.CfsSubsetEval", options=["-P", "1", "-E", "1"])
attsel = AttributeSelection()
attsel.search(search)
attsel.evaluator(evaluation)
attsel.select_attributes(test_data)
print("# attributes: " + str(attsel.number_attributes_selected))
print("attributes: " + str(attsel.selected_attributes))
print("result string:\n" + attsel.results_string)

1 个答案:

答案 0 :(得分:1)

您可以使用class_index对象的Instances属性(基于0的属性索引)设置数据集的类索引。例如,将第三个属性设置为类属性:

test_data.class_index = 2