코드 - Weka의 LinearRegression 클래스

3038 단어 SSI
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   
    }  
} 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

좋은 웹페이지 즐겨찾기