@Override public Prediction getPredictionForInstance(MultiLabelInstance x){ if (this.majorityLabelset == null) { int L = x.numberOutputTargets(); return new MultiLabelPrediction(L); } return this.majorityLabelset; }
@Override public void trainOnInstanceImpl(MultiLabelInstance instance) { int numOutputs=instance.numberOutputTargets(); if(countVector==null){ countVector=new double[numOutputs]; } double weight=instance.weight(); for(int i=0; i<numOutputs;i++){ countVector[i]+=weight*instance.valueOutputAttribute(i); } numInstances+=weight; }
@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); }
public void addPrediction(Prediction prediction, MultiLabelInstance inst){ int numOutputs=inst.numberOutputTargets(); Prediction trueClass= new MultiLabelPrediction(numOutputs); for (int i=0; i<numOutputs; i++){ trueClass.setVotes(i, new double[]{inst.valueOutputAttribute(i)}); } addPrediction(prediction, trueClass, inst.weight()); }
@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); } }
L = samoaInstance.numberOutputTargets(); weka.core.Instance x = this.instanceConverter.wekaInstance(samoaInstance); x.dataset().setClassIndex(L);
@Override public void addResult(Example<Instance> example, Prediction prediction) { MultiLabelInstance inst = (MultiLabelInstance) example.getData(); if (numberOutputs == 0) { numberOutputs = inst.numberOutputTargets(); } if(this.squareError==null){ this.squareError = new double[numberOutputs]; this.averageError = new double[numberOutputs]; this.averageErrorToTargetMean=new double[numberOutputs]; this.squareErrorToTargetMean=new double[numberOutputs]; this.sumY=new double[numberOutputs]; } if (inst.weight() > 0.0) { this.weightObserved += inst.weight(); if (prediction != null && prediction.numOutputAttributes()>0) { for (int i = 0; i< numberOutputs;i++){ double error=(inst.valueOutputAttribute(i) - prediction.getVote(i, 0)); this.sumY[i]+=inst.valueOutputAttribute(i); double errorTM=(inst.valueOutputAttribute(i) - this.sumY[i]/this.weightObserved); this.averageErrorToTargetMean[i]+=Math.abs(errorTM); this.squareErrorToTargetMean[i]+=errorTM*errorTM; this.averageError[i]+=Math.abs(error); this.squareError[i]+=error*error; } } //System.out.println(inst.classValue()+", "+prediction); } }
@Override public void trainOnInstanceImpl(MultiLabelInstance instance) { if (this.hasStarted == false){ this.ensemble = new Classifier[instance.numberOutputTargets()]; Classifier baseLearner = (Classifier) getPreparedClassOption(this.baseLearnerOption); if(baseLearner.isRandomizable()) baseLearner.setRandomSeed(this.randomSeed); baseLearner.resetLearning(); for (int i = 0; i < this.ensemble.length; i++) { this.ensemble[i] = baseLearner.copy(); } this.hasStarted = true; } for (int i = 0; i < this.ensemble.length; i++) { Instance weightedInst = transformInstance(instance,i); this.ensemble[i].trainOnInstance(weightedInst); } }
@Override public void trainOnInstanceImpl(MultiLabelInstance instance) { if (this.hasStarted == false){ this.ensemble = new Classifier[instance.numberOutputTargets()]; Classifier baseLearner = (Classifier) getPreparedClassOption(this.baseLearnerOption); if(baseLearner.isRandomizable()) baseLearner.setRandomSeed(this.randomSeed); baseLearner.resetLearning(); for (int i = 0; i < this.ensemble.length; i++) { this.ensemble[i] = baseLearner.copy(); } this.hasStarted = true; } for (int i = 0; i < this.ensemble.length; i++) { Instance weightedInst = transformInstance(instance,i); this.ensemble[i].trainOnInstance(weightedInst); } }
@Override public void addResult(Example<Instance> testInst, Prediction prediction) { MultiLabelInstance inst=(MultiLabelInstance) testInst.getData(); double weight = inst.weight(); if (numberOutputs == 0) { numberOutputs = inst.numberOutputTargets(); } if (weight > 0.0) { if (TotalweightObserved == 0) { reset(inst.dataset().numClasses()); } this.TotalweightObserved += weight; this.weightObserved.add(weight); if (prediction!=null) { for (int i = 0; i< numberOutputs;i++){ double error=(inst.valueOutputAttribute(i) - prediction.getVote(i, 0)); this.squareError.add( error*error); this.averageError.add(Math.abs(error)); } } //System.out.println(inst.classValue()+", "+prediction[0]); } } }
vote = new MultiLabelPrediction(instance.numberOutputTargets());
/** * Method for updating (training) the model using a new instance */ public void trainOnInstanceImpl(MultiLabelInstance inst) { if (inst.weight() > 0) { checkRoot(); double[] prediction = treeRoot.getPrediction(inst); double[] normalError = getNormalizedError(inst, prediction); //normalError.scaleValues(inst.weight()); processInstance(inst, treeRoot, prediction, normalError, true, false); examplesSeen += inst.weight(); for (int i = 0; i < inst.numberOutputTargets(); i++) { sumOfValues.addToValue(i, inst.weight() * inst.valueOutputAttribute(i)); sumOfSquares.addToValue(i, inst.weight() * inst.valueOutputAttribute(i) * inst.valueOutputAttribute(i)); } for (int i = 0; i < inst.numInputAttributes(); i++) { sumOfAttrValues.addToValue(i, inst.weight() * inst.valueInputAttribute(i)); sumOfAttrSquares.addToValue(i, inst.weight() * inst.valueInputAttribute(i) * inst.valueInputAttribute(i)); } } }
numberOutputs = inst.numberOutputTargets();
int numOutputs=instance.numberOutputTargets();
int numOutputs=instance.numberOutputTargets();
vote = new MultiLabelPrediction(instance.numberOutputTargets());