如何在WEKA的探险家中应用分类器?
-
24-10-2019 - |
题
假设,我已经建立了一个模型(例如J4.8树),并通过交叉验证对其进行了评估。我怎样才能 使用此模型对新数据集进行分类?我知道,我可以将带有数据的文件设置为与“提供的测试集”选项进行分类,在“更多选项”窗口中标记“输出预测”,然后再次运行分类。它几乎会产生我需要的东西,但这似乎是一个非常奇怪的工作流程。此外,它重新创建了所有模型,这可能需要不必要的时间。是否有更直接的方法可以使用已经建立的模型进行分类?
解决方案
MISC软件包中有特殊的类串行classifier,它将模型文件作为参数并具有模拟训练阶段。
其他提示
有几种方法。
第一
您可以使用命令行保存和加载模型,-L和-D命令行开关允许您执行此操作。
来自WEKA文档
-l Sets model input file. In case the filename ends with '.xml', a PMML file is loaded or, if that fails, options are loaded from the XML file. -d Sets model output file. In case the filename ends with '.xml', only the options are saved to the XML file, not the model.
第二个
同样,生成模型后,请使用第二次单击来保存和加载模型。看
第三个
您也可以为分类器生成Java代码。这样,您可以保存分类器并重新使用它。遵循此步骤。
- 单击更多选项按钮。
- 从打开
,选择输出源代码。
- 给分类器名称更有意义。
这些步骤将为您的J48分类器输出Java类。 WEKA由WEKA创建以与IRIS数据集一起创建。
class WekaJ48ForIris {
public static double classify(Object[] i)
throws Exception {
double p = Double.NaN;
p = WekaJ48ForIris.N26a305890(i);
return p;
}
static double N26a305890(Object []i) {
double p = Double.NaN;
if (i[3] == null) {
p = 0;
} else if (((Double) i[3]).doubleValue() <= 0.6) {
p = 0;
} else if (((Double) i[3]).doubleValue() > 0.6) {
p = WekaJ48ForIris.N18c079301(i);
}
return p;
}
static double N18c079301(Object []i) {
double p = Double.NaN;
if (i[3] == null) {
p = 1;
} else if (((Double) i[3]).doubleValue() <= 1.7) {
p = WekaJ48ForIris.N4544b022(i);
} else if (((Double) i[3]).doubleValue() > 1.7) {
p = 2;
}
return p;
}
static double N4544b022(Object []i) {
double p = Double.NaN;
if (i[2] == null) {
p = 1;
} else if (((Double) i[2]).doubleValue() <= 4.9) {
p = 1;
} else if (((Double) i[2]).doubleValue() > 4.9) {
p = WekaJ48ForIris.N3a0872863(i);
}
return p;
}
static double N3a0872863(Object []i) {
double p = Double.NaN;
if (i[3] == null) {
p = 2;
} else if (((Double) i[3]).doubleValue() <= 1.5) {
p = 2;
} else if (((Double) i[3]).doubleValue() > 1.5) {
p = 1;
}
return p;
}
}
不隶属于 StackOverflow