CPT predictions
Date: January 16, 2019 06:21AM
Hello
May I ask a question on the CPT algorithm please.
I am using the code from ca.pfv.spmf.test.MainTestCPT on the "contextCPT.txt" data, but I am unable to get predictions when a sequence of length one is added (i.e. only one item).
Apologies if I misunderstand.
David
// example code
package ca.pfv.spmf.test;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import ca.pfv.spmf.algorithms.sequenceprediction.ipredict.database.Item;
import ca.pfv.spmf.algorithms.sequenceprediction.ipredict.database.Sequence;
import ca.pfv.spmf.algorithms.sequenceprediction.ipredict.database.SequenceDatabase;
import ca.pfv.spmf.algorithms.sequenceprediction.ipredict.predictor.CPT.CPT.CPTPredictor;
public class testforweb {
public static void main(String [] arg) throws IOException{
String inputPath = fileToPath("contextCPT.txt" ) ;
SequenceDatabase trainingSet = new SequenceDatabase();
trainingSet.loadFileSPMFFormat(inputPath, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
String optionalParameters = "splitLength:6 splitMethod:0 recursiveDividerMin:1 recursiveDividerMax:5";
CPTPredictor predictionModel = new CPTPredictor("CPT", optionalParameters);
predictionModel.Train(trainingSet.getSequences());
Sequence sequence = new Sequence(0);
sequence.addItem(new Item(1));
Sequence thePrediction = predictionModel.Predict(sequence);
System.out.println("The prediction for the next symbol is: +" + thePrediction);
}
public static String fileToPath(String filename) throws UnsupportedEncodingException{
URL url = MainTestCPT.class.getResource(filename);
return java.net.URLDecoder.decode(url.getPath(),"UTF-8" ) ;
}
}
Edited 1 time(s). Last edit at 01/16/2019 07:16AM by david.