Java Code Examples for weka.core.SerializationHelper#read()

The following examples show how to use weka.core.SerializationHelper#read() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NERTool.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
public NERTool(){
		try {
//	        URL realPath = Thread.currentThread().getContextClassLoader().getResource("");
//	        System.out.println("realPath:"+realPath);
//	        String decoded = URLDecoder.decode(realPath.getFile(), "UTF-8");
//	        File fileRource1 = new File(decoded, GlobalSetting.rule_base_acdat_model);
//			File fileRource2 = new File(decoded, GlobalSetting.rule_base_dict_model);
//			System.out.println("f1="+fileRource1.getAbsolutePath());
//			System.out.println("f2="+fileRource2.getAbsolutePath());
			Resource fileRource = new ClassPathResource(rule_based_model);
			this.rbm =(RuleBasedModels) SerializationHelper.read(new GZIPInputStream(fileRource.getInputStream()));	
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
 
Example 2
Source File: Predictor.java    From browserprint with MIT License 6 votes vote down vote up
public static void initialise(String browserModelFilePath, String osModelFilePath, String fontsPath) throws Exception{
	browserAttributes = new ArrayList<Attribute>();
	osAttributes = new ArrayList<Attribute>();
	browserClassAttribute = new Attribute("className", browserGroupsWeCareAbout);
	osClassAttribute = new Attribute("className", osGroupsWeCareAbout);
	browserAttributes.add(browserClassAttribute);
	osAttributes.add(osClassAttribute);
	for(int i = 1; i <= 5300; ++i){
		browserAttributes.add(new Attribute(Integer.toString(i)));
		osAttributes.add(new Attribute(Integer.toString(i)));
	}
	
	browserClassifier = (Classifier) SerializationHelper.read(browserModelFilePath);
	osClassifier = (Classifier) SerializationHelper.read(osModelFilePath);
	
	BrowserOsGuessFingerprintNumericRepresentation.initialise(fontsPath);
}
 
Example 3
Source File: DecisionTree.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Classifier j48 = new J48();
    Instances trainingData = GenerateTestVessels.getData();
    j48.buildClassifier(trainingData);
    System.out.println(j48);



    double[] vesselUnderTest = GenerateTestVessels.getBarco(5);

    DenseInstance inst = new DenseInstance(1.0,vesselUnderTest);
    inst.setDataset(trainingData);
    inst.setClassMissing();
    System.out.println(inst);

    double result = j48.classifyInstance(inst);
    System.out.println(GenerateTestVessels.types[(int)result]);

    SerializationHelper.write(new FileOutputStream("tmp"), j48);
    J48 j48Read = (J48)SerializationHelper.read(new FileInputStream("tmp"));
}
 
Example 4
Source File: Serialized.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reads the statistics.
 *
 * @return              the statistics that were read
 */
@Override
public List<EvaluationStatistics> read() {
	List<EvaluationStatistics>  result;

	try {
		result = (List<EvaluationStatistics>) SerializationHelper.read(m_File.getAbsolutePath());
	}
	catch (Exception e) {
		result = null;
		handleException("Failed to read serialized statistics from: " + m_File, e);
	}

	return result;
}
 
Example 5
Source File: SerializedExperiment.java    From meka with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reads an experiment from disk.
 *
 * @param file      the file to load
 * @return          the experiment, null if failed to load
 */
@Override
public Experiment read(File file) {
	try {
		return (Experiment) SerializationHelper.read(file.getAbsolutePath());
	}
	catch (Exception e) {
		handleException("Failed to read experiment from: " + file, e);
		return null;
	}
}
 
Example 6
Source File: ActivityVirtualSensor.java    From gsn with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean initialize() {
	try {
		cls_act = (Classifier) SerializationHelper.read(Environment.getExternalStorageDirectory().getAbsolutePath()
			+ "/Android/data/tinygsn/" + fileName);
	} catch (Exception e) {
		return false;
	}
	return true;
}
 
Example 7
Source File: WekaEmailIntentClassifier.java    From EmailIntentDataSet with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	
	if (args.length != 2) {
		System.out.println("Usage: WekaSpeechActClassifier <train_set_input_file> <test_set_input_file>");
		System.exit(0);
	}
	
	String arffFileTrain = args[0];
	String arffFileTest = args[1];

	LibSVM wekaClassifier = new LibSVM();
	wekaClassifier.setOptions(new String[] {"-B", "-H"});

	Instances preparedData = (Instances) SerializationHelper.read(arffFileTrain);
	Instances preparedTest = (Instances) SerializationHelper.read(arffFileTest);
	
	System.out.println("Reading train set and test set done!");

	System.out.print("\nTraining...");
	wekaClassifier.buildClassifier(preparedData);
	
	System.out.println("\nTraining...done!");
	
	Evaluation evalTrain = new Evaluation(preparedData);
	evalTrain.evaluateModel(wekaClassifier, preparedData);

	DecimalFormat formatter = new DecimalFormat("#0.0");
	
	System.out.println("\nEvaluating on trainSet...");
	System.out.println(evalTrain.toSummaryString());
	
	System.out.println("\nResult on trainSet...");
	System.out.println("Precision:" + formatter.format(100*evalTrain.precision(0)) + "%" +
			" - Recal: " + formatter.format(100*evalTrain.recall(0)) + "%" +
			" - F1: " + formatter.format(evalTrain.fMeasure(0)) + "%");
	
	Evaluation eval = new Evaluation(preparedTest);
	eval.evaluateModel(wekaClassifier, preparedTest);

	System.out.println("\nEvaluating on testSet...");
	System.out.println(eval.toSummaryString());
	
	System.out.println("\nResult on testSet...");
	System.out.println("Precision:" + formatter.format(100*eval.precision(0)) + "%" +
			" - Recal: " + formatter.format(100*eval.recall(0)) + "%" +
			" - F1: " + formatter.format(100*eval.fMeasure(0)) + "%");

	System.out.println("True positive rate: " + formatter.format(100*eval.truePositiveRate(0)) + "%" + 
			" - True negative rate: "  + formatter.format(100*eval.trueNegativeRate(0)) + "%");
	System.out.println("Accuracy: " + formatter.format(100*((eval.truePositiveRate(0) + eval.trueNegativeRate(0)) / 2)) + "%");
	
	System.out.println("\nDone!");
}