List of usage examples for weka.classifiers.trees.m5 PreConstructedLinearModel coefficients
public double[] coefficients()
From source file:cn.ict.zyq.bestConf.COMT2.Branch2.java
License:Open Source License
public Instance maxPoint(Instances dataset) throws Exception { Instance max = new DenseInstance(dataset.numAttributes()); max.setDataset(dataset);/*w ww.java 2 s . c o m*/ double[] combinedCoefs = null; int len = 0; for (PreConstructedLinearModel model : linearModelList) { //initialization if (combinedCoefs == null) { len = model.coefficients().length; combinedCoefs = new double[len]; for (int i = 0; i < len; i++) combinedCoefs[i] = 0; } for (int i = 0; i < len; i++) combinedCoefs[i] += model.coefficients()[i]; } //the max value is obtained at ends of a range for (Map.Entry<Attribute, Range<Double>> ent : rangeMap.entrySet()) { int attIdx = ent.getKey().index(); if (combinedCoefs[attIdx] > 0) { //use the upper bound if (ent.getValue().hasUpperBound()) max.setValue(attIdx, ent.getValue().upperEndpoint()); } else if (combinedCoefs[attIdx] < 0) { //use the lower bound if (ent.getValue().hasLowerBound()) max.setValue(attIdx, ent.getValue().lowerEndpoint()); } } //now we set the predicted values double y = 0; for (PreConstructedLinearModel model : linearModelList) { y += model.classifyInstance(max); } y /= linearModelList.size(); max.setClassValue(y); return max; }