liboss

            夫为道者,譬如一人与万人战,挂铠出门,意或怯弱,或半路而退,或格斗而死,或得胜而还。沙门学道,应当坚持其心,精进勇锐,不畏前境,破灭众魔,而得道果!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::
package kit.weka;
import weka.classifiers.Evaluation;  
import weka.classifiers.functions.LinearRegression;  
import weka.core.Instance;  
import weka.core.Instances;  
import weka.core.converters.ConverterUtils.DataSource;  
public class LegressionTest 
{  
    public static void main(String[] args) throws Exception 
    {  
        // TODO Auto-generated method stub   
        DataSource train_data = new DataSource("d:\\Program Files\\Weka-3-7\\data\\train.arff");//读训练数据  
        DataSource test_data = new DataSource("d:\\Program Files\\Weka-3-7\\data\\test.arff");//读测试数据  
        Instances insTrain = train_data.getDataSet();  
        Instances insTest = test_data.getDataSet();  
        insTrain.setClassIndex(insTrain.numAttributes()-1);//设置训练集中,target的index   
        insTest.setClassIndex(insTest.numAttributes()-1);//设置测试集中,target的index   
        LinearRegression lr = new LinearRegression();//定义分类器的类型   
        lr.buildClassifier(insTrain);//训练分类器   
        Evaluation eval=new Evaluation(insTrain);  
        eval.evaluateModel(lr, insTest);//评估效果   
        System.out.println(eval.meanAbsoluteError());//计算MAE   
    }  
} 
posted on 2014-01-03 10:51  lam99v  阅读(801)  评论(0编辑  收藏  举报