您的位置:首页 > 其它

关于weka的使用————模型的建立

2016-08-03 00:00 267 查看
Classifier m_classifier = new MultilayerPerceptron();

Instances instancesTrain =m.instancesTrain("jdbc:mysql://localhost:3306/test","root","123456",2,"select openings,polite_words,professional_response,dirty_words,confirmation,closings,mark from mark");(该方法请参照上文)

设置最后一列为因变量:
instancesTrain.setClassIndex(instancesTrain.numAttributes()-1);

训练得到模型:

m_classifier.buildClassifier(instancesTrain);

/**
* 保存模型值文件中
* @param m_classifier
* @param path 文件路径
* @throws FileNotFoundException
* @throws IOException
*/
public void saveModel(Classifier m_classifier,String path) throws FileNotFoundException, IOException{
ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream(path));//"d://test.model"
oos.writeObject(m_classifier);
oos.flush();
oos.close();
}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: