Package quickml.data

Examples of quickml.data.PredictionMap


    @Override
    public PredictionMap predict(AttributesMap attributes) {
        Map<Serializable, Double> probsByClassification = Maps.newHashMap();
        probsByClassification.put(minorityClassification, getProbability(attributes, minorityClassification));
        probsByClassification.put(majorityClassification, getProbability(attributes, majorityClassification));
        return new PredictionMap(probsByClassification);
    }
View Full Code Here


        this.wrappedTwo = wrappedTwo;
    }

    @Override
    public PredictionMap predict(AttributesMap attributes) {
        PredictionMap predictionMap = PredictionMap.newMap();
        double adjustedPosProb = wrappedOne.getProbability(attributes, 1.0);
        predictionMap.put(1.0, adjustedPosProb);
        predictionMap.put(0.0, 1.0 - adjustedPosProb);
         return predictionMap;
    }
View Full Code Here

        Leaf leaf = node.getLeaf(attributes);
        Map<Serializable, Double> probsByClassification = Maps.newHashMap();
        for (Serializable classification : leaf.getClassifications()) {
            probsByClassification.put(classification, leaf.getProbability(classification));
        }
        return new PredictionMap(probsByClassification);
    }
View Full Code Here

        return predict(attributes).get(classification);
    }
    public abstract PredictionMap predict(AttributesMap attributes);

    public Serializable getClassificationByMaxProb(AttributesMap attributes) {
        PredictionMap predictions = predict(attributes);
        Serializable mostProbableClass = null;
        double probabilityOfMostProbableClass = 0;
        for (Serializable key : predictions.keySet()) {
            if (predictions.get(key).doubleValue() > probabilityOfMostProbableClass) {
                mostProbableClass = key;
                probabilityOfMostProbableClass = predictions.get(key).doubleValue();
            }
        }
        return mostProbableClass;
    }
View Full Code Here

            return getPredictionForNClasses(attributes);
        }
    }

    private PredictionMap getPredictionForNClasses(AttributesMap attributes) {
        PredictionMap sumsByClassification = new PredictionMap(new HashMap<Serializable, Double>());
        for (Tree tree : trees) {
            final PredictionMap treeProbs = tree.predict(attributes);
            for (Map.Entry<Serializable, Double> tpe : treeProbs.entrySet()) {
                Double sum = sumsByClassification.get(tpe.getKey());
                if (sum == null) sum = 0.0;
                sum += tpe.getValue();
                sumsByClassification.put(tpe.getKey(), sum);
            }
        }
        PredictionMap probsByClassification = new PredictionMap(new HashMap<Serializable, Double>());
        for (Map.Entry<Serializable, Double> sumEntry : sumsByClassification.entrySet()) {
            probsByClassification.put(sumEntry.getKey(), sumEntry.getValue() / trees.size());
        }

        return probsByClassification;
    }
View Full Code Here

        return probsByClassification;
    }

    private PredictionMap getPredictionForTwoClasses(AttributesMap attributes) {
        PredictionMap probsByClassification = PredictionMap.newMap();
        Iterator<Serializable> classIterator = classifications.iterator();
        if (!classIterator.hasNext()) {
            throw new RuntimeException("no class labels present in classification set");
        }
        Serializable firstClassification = classIterator.next();
        double firstProbability = getProbability(attributes, firstClassification);
        probsByClassification.put(firstClassification, firstProbability);
        if (classIterator.hasNext()) {
            Serializable secondClassification = classIterator.next();
            probsByClassification.put(secondClassification, 1.0 - firstProbability);
        }
        return probsByClassification;
    }
View Full Code Here

    @Override
    public double getLoss(List<LabelPredictionWeight<PredictionMap>> labelPredictionWeights)  {
        Auc auc = new Auc();
        for (LabelPredictionWeight<PredictionMap> labelPredictionWeight : labelPredictionWeights) {
            int trueValue = (Double) labelPredictionWeight.getLabel() == 1.0 ? 1 : 0;
            PredictionMap classifierPrediction = labelPredictionWeight.getPrediction();
            double probabilityOfCorrectInstance = classifierPrediction.get(labelPredictionWeight.getLabel());
            double score = 0;
            score = (trueValue == 1) ? probabilityOfCorrectInstance: 1 - probabilityOfCorrectInstance;
            auc.add(trueValue, score);
        }
        return 1 - auc.auc();
View Full Code Here

            this.dropProbability = dropProbability;
        }

        @Override
        public LabelPredictionWeight<PredictionMap> getCorrectedLabelPredictionWeight(LabelPredictionWeight<PredictionMap> labelPredictionWeight) {
            PredictionMap correctedPredictionMap = PredictionMap.newMap();
            PredictionMap uncorrectedPrediction = labelPredictionWeight.getPrediction();
            double correctedProbability;
            for (Serializable key : uncorrectedPrediction.keySet()) {
                if (key.equals(negativeLabel)) {
                    correctedProbability = 1.0 - Utils.correctProbability(dropProbability, 1.0-uncorrectedPrediction.get(key));
                    correctedPredictionMap.put(key, correctedProbability);
                } else {
                    correctedProbability = Utils.correctProbability(dropProbability, uncorrectedPrediction.get(key));
                    correctedPredictionMap.put(key, correctedProbability);
                }
            }
            double correctedWeight = labelPredictionWeight.getWeight();
            if (labelPredictionWeight.getLabel().equals(negativeLabel))
View Full Code Here

    protected abstract double getLossFromInstance(double probabilityOfCorrectInstance, double weight);
    public double getLoss(List<LabelPredictionWeight<PredictionMap>> labelPredictionWeights) {
        totalLoss = 0;
        weightOfAllInstances = 0;
        for (LabelPredictionWeight<PredictionMap> labelPredictionWeight : labelPredictionWeights) {
            PredictionMap classifierPrediction = labelPredictionWeight.getPrediction();
            double probabilityOfCorrectInstance = classifierPrediction.get(labelPredictionWeight.getLabel());
            totalLoss += getLossFromInstance(probabilityOfCorrectInstance, labelPredictionWeight.getWeight());
            weightOfAllInstances += labelPredictionWeight.getWeight();
        }
        return weightOfAllInstances > 0 ? totalLoss / weightOfAllInstances : 0;
    }
View Full Code Here

            Assert.assertTrue(randomForest1.trees.get(i).node.size() == randomForest2.trees.get(i).node.size(), "Deterministic Decision Trees must have same number of nodes");
        }

        final List<Instance<AttributesMap>> instancesTest = TreeBuilderTestUtils.getInstances(1000);
        for (Instance<AttributesMap> instance : instancesTest) {
           PredictionMap map1 = randomForest1.predict(instance.getAttributes());
           PredictionMap map2 = randomForest2.predict(instance.getAttributes());
            Assert.assertTrue(map1.equals(map2), "Deterministic Decision Trees must have equal classifications");
        }
    }
View Full Code Here

TOP

Related Classes of quickml.data.PredictionMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.