368.5.2. 构建模型

在构建模型时,我们首先选择要使用的分类算法,然后利用一些数据对其进行培训。结果是我们稍后用来分类未量数据的培训模式。

我们在此培训 J48,达到 10 倍的交叉验证。

try (CamelContext camelctx = new DefaultCamelContext()) {

    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {

            // Use the file component to read the training data
            from("file:src/test/resources/data?fileName=sfny-train.arff")

            // Build a J48 classifier using cross-validation with 10 folds
            .to("weka:model?build=J48&xval=true&folds=10&seed=1")

            // Persist the J48 model
            .to("weka:model?saveTo=src/test/resources/data/sfny-j48.model")
        }
    });
    camelctx.start();
}