The Data Mining Forum                             open-source data mining software data mining conferences Data Science for Social and Behavioral Analytics DSSBA 2022 data science journal
IMPORTANT: This is the old Data Mining forum.
I keep it online so that you can read the old messages.

Please post your new messages in the new forum: https://forum2.philippe-fournier-viger.com/index.php
 
saving to file and loading a pretrained sequence prediction model with CPT / CPT+ / AKOM / PPM / TDAG etc in SPMF
Date: February 12, 2021 12:05AM

Hi all,

For all of those using CPT, CPT+, AKOM, PPM, DG and other sequence prediction models of SPMF, in the new version 2.44, I have added some example in the code about how to save a pretrained model to a file and then load it again. It is very simple. For example, in MainTestCPT.java, the code for saving a trained CPT model and loading it from file to do a prediction looks like this:

// ******* IF we want to save the trained model to a file ******* ///
ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream("model.ser" ) ) ;
stream.writeObject(predictionModel);
stream.close();
		
// ****** Then, we can also load the trained model from the file ****** ///
ObjectInputStream stream2 = new ObjectInputStream(new FileInputStream("model.ser" ) ) ;
Predictor predictionModel2 = (Predictor) stream2.readObject();
stream.close();

// and then make a prediction
Sequence thePrediction2 = predictionModel2.Predict(sequence);
System.out.println("For the sequence <(1),(4)>, the prediction for the next symbol is: +" + thePrediction2);

That is easy ! :-)



Edited 5 time(s). Last edit at 02/12/2021 12:08AM by webmasterphilfv.

Options: ReplyQuote


This forum is powered by Phorum and provided by P. Fournier-Viger (© 2012).
Terms of use.