HS沉寂這麼多天,誰知道恰恰在我申請離職的時候給我安排了個任務,哎,無語。html
因而,今天看了一天的Weka。java
主要是看了HS提供的三個文章(E文,在google的幫助下看完的):算法
import java.io.FileNotFoundException; import java.io.IOException; import weka.classifiers.functions.LinearRegression; import weka.core.Instances; public class Weka { /** * @param args */ public static void main(String[] args) { String inputFile = "C:\\Documents and Settings\\Administrator\\My Documents\\Downloads\\weka-3-7-5\\weka-3-7-5\\my\\house.arff"; java.io.Reader r; try { r = new java.io.BufferedReader(new java.io.FileReader(inputFile)); Instances instances = new Instances(r); instances.setClassIndex(instances.numAttributes() - 1); LinearRegression linearRegression = new LinearRegression(); linearRegression.buildClassifier(instances); double[] coef = linearRegression.coefficients(); double myHouseValue = (coef[0] * 3198) + (coef[1] * 9669) + (coef[2] * 5) + (coef[3] * 3) + (coef[4] * 1) + coef[6]; System.out.println(myHouseValue); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }