如何使用Java代码在Weka中使用新实例测试现有模型? [英] How to test existing model with new instance in weka, using java code?

查看:78
本文介绍了如何使用Java代码在Weka中使用新实例测试现有模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过Weka GUI获取的分类器之一的.model文件.现在,我想在某些实例上测试此模型.谁能告诉我该怎么做?

I have a .model file of one of the classifier which I got through Weka GUI. Now I would like to test this model on some instance. Can anyone tell me how to do this ?

Classifier cModel = (Classifier)new NaiveBayes();  
cModel.buildClassifier(isTrainingSet);  

我不想像这段代码中那样一次又一次地建立分类器.如何使用.model文件执行此操作?

I don't want to build classifier again and again like in this code. How to do this using .model file?

 // Test the model
 Evaluation eTest = new Evaluation(isTrainingSet);
 eTest.evaluateModel(cModel, isTrainingSet);

推荐答案

将您的代码与Omer提供的链接中找到的代码相结合:

Combining your code with the code found in the link provided by Omer:

Classifier cModel = (Classifier)new NaiveBayes();  
cModel.buildClassifier(isTrainingSet);  

weka.core.SerializationHelper.write("/some/where/nBayes.model", cModel);

Classifier cls = (Classifier) weka.core.SerializationHelper.read("/some/where/nBayes.model");

// Test the model
Evaluation eTest = new Evaluation(isTrainingSet);
eTest.evaluateModel(cls, isTrainingSet);

这篇关于如何使用Java代码在Weka中使用新实例测试现有模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆