Wednesday, May 27, 2020

Some more Flink CEP +ML examples

FlinkCEP is the Complex Event Processing (CEP) library implemented on top of Flink. It allows you to detect event patterns in an endless stream of events. Machine Learning helps with utilizing patterns discovered in events to make predictions. Together ML and FlinkCEP can improve analytics and predictions.
public static void main(String[] args) throws Exception {
 
        File file =  StreamHandler.writeToFile(StreamHelper.resolve("sequences"));
        Dataset data = FileHandler.loadDataset(file, 4, ",");

// ensemble feature selection
        RecursiveFeatureEliminationSVM[] svmrfes = new RecursiveFeatureEliminationSVM[10];
        for (int i = 0; i < svmrfes.length; i++)
            svmrfes[i] = new RecursiveFeatureEliminationSVM(0.2);
        LinearRankingEnsemble ensemble = new LinearRankingEnsemble(svmrfes);
        ensemble.build(data);
        for (int i = 0; i < ensemble.noAttributes(); i++)
            System.out.println(ensemble.rank(i));

        // feature scoring
        GainRatio ga = new GainRatio();
        ga.build(data);
        for (int i = 0; i < ga.noAttributes(); i++)
            System.out.println(ga.score(i));

         // feature ranking
        RecursiveFeatureEliminationSVM svmrfe = new RecursiveFeatureEliminationSVM(0.2);
        svmrfe.build(data);
        for (int i = 0; i < svmrfe.noAttributes(); i++)
            System.out.println(svmrfe.rank(i)); 
    }
 
}




No comments:

Post a Comment