Package quickml.supervised.classifier

Examples of quickml.supervised.classifier.Classifier


        final Map.Entry<Serializable, Double> minorityEntry = MapUtils.getEntryWithLowestValue(classificationProportions).get();
        Serializable majorityClassification = majorityEntry.getKey();
        final double majorityProportion = majorityEntry.getValue();
        final double naturalMinorityProportion = 1.0 - majorityProportion;
        if (naturalMinorityProportion >= targetMinorityProportion) {
            final Classifier wrappedPredictiveModel = predictiveModelBuilder.buildPredictiveModel(trainingData);
            return new DownsamplingClassifier(wrappedPredictiveModel, majorityClassification, minorityEntry.getKey(), 0);
        }

        final double dropProbability = (naturalMinorityProportion > targetMinorityProportion)0 : 1.0 - ((naturalMinorityProportion - targetMinorityProportion*naturalMinorityProportion) / (targetMinorityProportion - targetMinorityProportion *naturalMinorityProportion));

        Iterable<? extends Instance<AttributesMap>> downsampledTrainingData = Iterables.filter(trainingData, new RandomDroppingInstanceFilter(majorityClassification, dropProbability));

        final Classifier wrappedPredictiveModel = predictiveModelBuilder.buildPredictiveModel(downsampledTrainingData);

        return new DownsamplingClassifier(wrappedPredictiveModel, majorityClassification, minorityEntry.getKey(), dropProbability);
    }
View Full Code Here


    public TwoStageModel buildPredictiveModel(Iterable<? extends Instance<AttributesMap>> trainingData) {
        List<Instance<AttributesMap>> stage1Data = Lists.newArrayList();
        List<Instance<AttributesMap>> stage2Data = Lists.newArrayList();
        List<Instance<AttributesMap>> validationData = Lists.newArrayList();
        createTrainingAndValidationData(trainingData, stage1Data, stage2Data, validationData);
        Classifier c1 = wrappedModelBuilder1.buildPredictiveModel(stage1Data);
        Classifier c2 = wrappedModelBuilder2.buildPredictiveModel(stage2Data);
        return new TwoStageModel(c1, c2);
    }
View Full Code Here

    @Override
    public TemporallyReweightedClassifier buildPredictiveModel(Iterable<? extends Instance<AttributesMap>> trainingData) {
        validateData(trainingData);
        DateTime mostRecent = getMostRecentInstance(trainingData);
        List<Instance<AttributesMap>> trainingDataList = reweightTrainingData(trainingData, mostRecent);
        final Classifier predictiveModel = wrappedBuilder.buildPredictiveModel(trainingDataList);
        return new TemporallyReweightedClassifier(predictiveModel);
    }
View Full Code Here

            validateData(newData);
            DateTime mostRecentInstance = getMostRecentInstance(newData);

            List<Instance<AttributesMap>> newDataList = reweightTrainingData(newData, mostRecentInstance);

            Classifier pm = predictiveModel.getWrappedClassifier();
            ((UpdatablePredictiveModelBuilder) wrappedBuilder).updatePredictiveModel(pm, newDataList, splitNodes);
        } else {
            throw new RuntimeException("Cannot update predictive model without UpdatablePredictiveModelBuilder");
        }
    }
View Full Code Here

    }

    private Classifier getModelForAttributes(AttributesMap attributes) {
        Serializable value = attributes.get(attributeKey);
        if (value == null) value = SplitOnAttributeClassifierBuilder.NO_VALUE_PLACEHOLDER;
        Classifier predictiveModel = splitModels.get(value);
        if (predictiveModel == null) {
            predictiveModel = defaultPM;
        }
        return predictiveModel;
    }
View Full Code Here

            splitModels.put(trainingDataEntry.getKey(), wrappedBuilder.buildPredictiveModel(trainingDataEntry.getValue()));
        }

        logger.info("Building default predictive model");
        setID(null);
        final Classifier defaultPM = wrappedBuilder.buildPredictiveModel(trainingData);
        return new SplitOnAttributeClassifier(attributeKey, splitModels, defaultPM);
    }
View Full Code Here

    @Override
    public void updatePredictiveModel(SplitOnAttributeClassifier predictiveModel, Iterable<? extends Instance<AttributesMap>> newData, boolean splitNodes) {
        if (wrappedBuilder instanceof UpdatablePredictiveModelBuilder) {
            Map<Serializable, ArrayList<Instance<AttributesMap>>> splitNewData = splitTrainingData(newData);
            for (Map.Entry<Serializable, ArrayList<Instance<AttributesMap>>> newDataEntry : splitNewData.entrySet()) {
                Classifier pm = predictiveModel.getSplitModels().get(newDataEntry.getKey());
                if(pm == null) {
                    logger.info("Building predictive model for "+attributeKey+"="+newDataEntry.getKey());
                    setID(newDataEntry.getKey());
                    pm = wrappedBuilder.buildPredictiveModel(newDataEntry.getValue());
                    predictiveModel.getSplitModels().put(newDataEntry.getKey(), pm);
View Full Code Here

        return this;
    }

    @Override
    public CalibratedPredictiveModel buildPredictiveModel(Iterable<? extends Instance<AttributesMap>> trainingData) {
        Classifier predictiveModel;
        if (wrappedPredictiveModel.isPresent()) {
            predictiveModel = wrappedPredictiveModel.get();
        } else {
            predictiveModel = wrappedPredictiveModelBuilder.buildPredictiveModel(trainingData);
        }
View Full Code Here

        storedObservations = Lists.newArrayList();
        for (int fold = 1; fold <= foldsForCalibrationSet; fold++) {
            List<Instance<AttributesMap>> trainingInstances = Lists.newArrayList();
            List<Instance<AttributesMap>> calibrationInstances = Lists.newArrayList();
            createTrainingAndCalibrationSets(trainingInstances, calibrationInstances, allInstances, fold);
            Classifier predictiveModel = wrappedPredictiveModelBuilder.buildPredictiveModel(trainingInstances);
            List<PoolAdjacentViolatorsModel.Observation> foldObservations = getObservations(predictiveModel, calibrationInstances);
            storedObservations.addAll(foldObservations);
        }

        return new PoolAdjacentViolatorsModel(storedObservations, (int)Math.max(1, storedObservations.size() /(double) binsInCalibrator));
View Full Code Here

* Created by ian on 4/24/14.
*/
public class DownsamplingPredictiveModelTest {
    @Test
    public void simpleTest() {
        final Classifier classifier = mock(Classifier.class);
        when(classifier.getProbability(any(AttributesMap.class), eq(Boolean.TRUE))).thenReturn(0.5);
        DownsamplingClassifier downsamplingClassifier = new DownsamplingClassifier(classifier, Boolean.FALSE, Boolean.TRUE, 0.9);
        double corrected = downsamplingClassifier.getProbability(AttributesMap.newHashMap(), Boolean.TRUE);
        double error = Math.abs(corrected - 0.1/1.1);
        Assert.assertTrue(String.format("Error (%s) should be negligible", error), error < 0.0000001);
    }
View Full Code Here

TOP

Related Classes of quickml.supervised.classifier.Classifier

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.