@Override public void trainOnInstanceImpl(MultiLabelInstance inst) { int numOutputs = inst.numberOutputTargets(); Prediction prediction = new MultiLabelPrediction(numOutputs); for(int i=0; i<numOutputs;i++) prediction.setVotes(i,new double[]{inst.classValue(i)}); this.lastSeenClasses = prediction; }
@Override public void trainOnInstanceImpl(MultiLabelInstance x) { int L = x.numberOutputTargets(); MultiLabelPrediction y = new MultiLabelPrediction(L); for(int j=0; j<L;j++) y.setVotes(j,new double[]{1- x.classValue(j), x.classValue(j)}); double freq = x.weight(); if (this.vectorCounts.containsKey(y.toString())) { freq += this.vectorCounts.get(y.toString()); } this.vectorCounts.put(y.toString(), (Double)freq); if (freq > this.maxValue) { this.maxValue = freq; this.majorityLabelset = y; } //System.out.println("---"+this.majorityLabelset); }
@Override public void addResult(Example<Instance> example, Prediction prediction) { MultiLabelInstance inst = (MultiLabelInstance) example.getData(); if (numberOutputs == 0) { numberOutputs = inst.numberOutputTargets(); } if (inst.weight() > 0.0) { this.weightObserved += inst.weight(); if (prediction != null ) { for (int i = 0; i< numberOutputs;i++){ double err = inst.classValue(i) - ((prediction.numOutputAttributes()==0) ? 0.0 : prediction.getVote(i,0)); this.squareError += (err) * (err); this.averageError += Math.abs(err); } } //System.out.println(inst.classValue()+", "+prediction); } }
System.out.print( (int)x.classValue(j)); for (int j = 0; j < y.numOutputAttributes(); j++) { int yp = (y.getVote(j,0) > t) ? 1 : 0; correct += ((int)x.classValue(j) == yp) ? 1 : 0;
sb.append(vote + ", ").append(inst.classValue()); System.out.println(sb.toString());
if(errors==null) //if errors==null, rule has seen no predictions since expansion: return maximum error, since prediction is not reliable errors=defaultRuleErrors(vote); debug("Rule No"+ rule.getRuleNumberID() + " Vote: " + vote.toString() + " Error: " + errors + " Y: " + instance.classValue(),3); //predictionValueForThisRule); errorWeightedVote.addVote(vote,errors);
if(errors==null) //if errors==null, rule has seen no predictions since expansion: return maximum error, since prediction is not reliable errors=defaultRuleErrors(vote); debug("Rule No"+ rule.getRuleNumberID() + " Vote: " + vote.toString() + " Error: " + errors + " Y: " + instance.classValue(),3); //predictionValueForThisRule); errorWeightedVote.addVote(vote,errors);