검색

369.5. Samples

download PDF

369.5.1. 읽기 + 필터 + 쓰기

이 첫 번째 예는 파일 구성 요소가 포함된 CSV 파일을 읽은 다음 Weka에 전달하는 방법을 보여줍니다. Weka에서는 데이터 세트에 몇 개의 필터를 적용한 다음 쓰기를 위해 파일 구성 요소에 전달합니다.

    @Override
    public void configure() throws Exception {

        // Use the file component to read the CSV file
        from("file:src/test/resources/data?fileName=sfny.csv")

        // Convert the 'in_sf' attribute to nominal
        .to("weka:filter?apply=NumericToNominal -R first")

        // Move the 'in_sf' attribute to the end
        .to("weka:filter?apply=Reorder -R 2-last,1")

        // Rename the relation
        .to("weka:filter?apply=RenameRelation -modify sfny")

        // Use the file component to write the Arff file
        .to("file:target/data?fileName=sfny.arff")
    }

여기서는 파일 구성 요소를 사용하지 않고 위와 동일하게 수행합니다.

    @Override
    public void configure() throws Exception {

        // Initiate the route from somewhere
        .from("...")

        // Use Weka to read the CSV file
        .to("weka:read?path=src/test/resources/data/sfny.csv")

        // Convert the 'in_sf' attribute to nominal
        .to("weka:filter?apply=NumericToNominal -R first")

        // Move the 'in_sf' attribute to the end
        .to("weka:filter?apply=Reorder -R 2-last,1")

        // Rename the relation
        .to("weka:filter?apply=RenameRelation -modify sfny")

        // Use Weka to write the Arff file
        .to("weka:write?path=target/data/sfny.arff");
    }

이 예에서 클라이언트는 입력 경로 또는 기타 지원되는 유형을 제공합니다. 지원되는 입력 유형 집합을 보려면 WekaTypeConverters 를 살펴보십시오.

    @Override
    public void configure() throws Exception {

        // Initiate the route from somewhere
        .from("...")

        // Convert the 'in_sf' attribute to nominal
        .to("weka:filter?apply=NumericToNominal -R first")

        // Move the 'in_sf' attribute to the end
        .to("weka:filter?apply=Reorder -R 2-last,1")

        // Rename the relation
        .to("weka:filter?apply=RenameRelation -modify sfny")

        // Use Weka to write the Arff file
        .to("weka:write?path=target/data/sfny.arff");
    }

369.5.2. 모델 빌드

모델을 구축할 때 먼저 사용할 분류 알고리즘을 선택한 다음 일부 데이터로 교육합니다. 결과적으로 나중에 보이지 않는 데이터를 분류하는 데 사용할 수 있는 숙련된 모델입니다.

여기서는 10개의 교차 유효성 검사로 J48을 교육합니다.

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();
}

369.5.3. 클래스 예측

여기에서는 프로세서를 사용하여 엔드포인트 URI에서 직접 사용할 수 없는 기능에 액세스합니다.

여기에 직접 와서 이 구문이 약간 압도적인 것처럼 보이는 경우 Nessus API Concepts 에 대한 섹션을 간략하게 살펴볼 수 있습니다.

try (CamelContext camelctx = new DefaultCamelContext()) {

    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {

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

            // Remove the class attribute
            .to("weka:filter?apply=Remove -R last")

            // Add the 'prediction' placeholder attribute
            .to("weka:filter?apply=Add -N predicted -T NOM -L 0,1")

            // Rename the relation
            .to("weka:filter?apply=RenameRelation -modify sfny-predicted")

            // Load an already existing model
            .to("weka:model?loadFrom=src/test/resources/data/sfny-j48.model")

            // Use a processor to do the prediction
            .process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    Dataset dataset = exchange.getMessage().getBody(Dataset.class);
                    dataset.applyToInstances(new NominalPredictor());
                }
            })

            // Write the data file
            .to("weka:write?path=src/test/resources/data/sfny-predicted.arff")
        }
    });
    camelctx.start();
}
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.