【问题标题】:Python weka wrapper attribute selectionPython weka 包装器属性选择
【发布时间】:2015-08-13 09:13:11
【问题描述】:

问题:我在我的属性选择过程中使用 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)

【问题讨论】:

  • 您能否详细说明您的代码“不起作用”的原因?你期待什么,实际发生了什么?如果您遇到异常,请发布它发生的行和异常详细信息。请edit这些详细信息,否则我们可能无法提供帮助。
  • 我没有收到任何错误。只是我只能为我的最后一个和第一个属性运行属性选择过程。有什么方法可以指定我要为其运行属性选择的类?

标签: python wrapper weka


【解决方案1】:

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

test_data.class_index = 2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-08
    • 2015-10-21
    • 2019-03-29
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 2012-08-15
    • 2021-09-23
    相关资源
    最近更新 更多