Package quickml.data

Examples of quickml.data.AttributesMap


    public static List<Instance<AttributesMap>> getInstances(int numInstances) {
        final List<Instance<AttributesMap>> instances = new ArrayList<>();
        for (int x = 0; x < numInstances; x++) {
            final double height = (4 * 12) + MapUtils.random.nextInt(3 * 12);
            final double weight = 120 + MapUtils.random.nextInt(110);
            AttributesMap  attributes = AttributesMap.newHashMap() ;
            attributes.put("weight", weight);
            attributes.put("height", height);
            attributes.put("gender", MapUtils.random.nextInt(2));
            instances.add(new InstanceImpl<AttributesMap>(attributes, bmiHealthy(weight, height)));
        }
        return instances;
    }
View Full Code Here


            Calendar calendar = Calendar.getInstance();
            final int year = calendar.get(Calendar.YEAR);
            final int month = calendar.get(Calendar.MONTH);
            final int day = MapUtils.random.nextInt(28)+1;
            final int hour = MapUtils.random.nextInt(24);
            final AttributesMap attributes = AttributesMap.newHashMap();
            attributes.put("weight", weight);
            attributes.put("height", height);
            attributes.put("timeOfArrival-year", year);
            attributes.put("timeOfArrival-monthOfYear", month);
            attributes.put("timeOfArrival-dayOfMonth", day);
            attributes.put("timeOfArrival-hourOfDay", hour);
            instances.add(new InstanceImpl(attributes, bmiHealthyInteger(weight, height)));
        }
        return instances;
    }
View Full Code Here

public class TemporallyReweightedClassifierBuilderTest {

    @Test(expectedExceptions = IllegalArgumentException.class)
    public void testError3ClassificationsInDataSet() throws Exception {
        final List<Instance<AttributesMap>> instances = new LinkedList<>();
        AttributesMap  map = AttributesMap.newHashMap() ;
        map.put("2", "2");
        instances.add(new InstanceImpl<AttributesMap>(map, "1"));
        instances.add(new InstanceImpl<AttributesMap>(map, "2"));
        instances.add(new InstanceImpl<AttributesMap>(map, "3"));
        PredictiveModelBuilder predictiveModelBuilder = new TreeBuilder();
        final TemporallyReweightedClassifierBuilder cpmb = new TemporallyReweightedClassifierBuilder(predictiveModelBuilder, new MapDateTimeExtractor());
View Full Code Here

        final List<Tree> trees = randomForest.trees;
        final int treeSize = trees.size();
        Assert.assertTrue(treeSize < 400, "Forest size should be less than 400");
        Assert.assertTrue((System.currentTimeMillis() - startTime) < 20000,"Building this node should take far less than 20 seconds");

        final AttributesMap testAttributes = instances.get(0).getAttributes();
        for (Map.Entry<Serializable, Double> entry : randomForest.predict(testAttributes).entrySet()) {
            Assert.assertEquals(entry.getValue(), randomForest.getProbability(testAttributes, entry.getKey()));
        }
    }
View Full Code Here

    }

    private List<Instance<AttributesMap>> getInstances() {
        final List<Instance<AttributesMap>> instances = Lists.newLinkedList();
        for(int i = 0; i < 5; i++) {
            AttributesMap attributes = AttributesMap.newHashMap() ;

            Instance<AttributesMap> instance = Mockito.mock(InstanceImpl.class);
            Mockito.when(instance.getWeight()).thenReturn(1.0);
            Mockito.when(instance.getLabel()).thenReturn("class");
            Mockito.when(instance.getAttributes()).thenReturn(attributes);
View Full Code Here

    final Set<Instance<AttributesMap>> instances = Sets.newHashSet();

    for (int x = 0; x < 10000; x++) {
      final double height = (4 * 12) + MapUtils.random.nextInt(3 * 12);
      final double weight = 120 + MapUtils.random.nextInt(110);
            AttributesMap  attributes = AttributesMap.newHashMap() ;
            attributes.put("weight", weight);
            attributes.put("height", height);
      final Instance<AttributesMap> instance = new InstanceImpl<>(attributes, TreeBuilderTestUtils.bmiHealthy(weight, height));
      instances.add(instance);
    }
    {
      final TreeBuilder tb = new TreeBuilder(new SplitDiffScorer());
View Full Code Here

    }

    @Override
    public AttributesMap apply(final AttributesMap attributes) {
        // TODO: Perhaps more efficient to use immutable map for attributes here
        AttributesMap enrichedAttributes = AttributesMap.newHashMap();
        enrichedAttributes.putAll(attributes);

        for (Map.Entry<String, Map<Serializable, Double>> attributeValueProbEntry : valueProbabilitiesByAttribute.entrySet()) {
            Serializable value = attributes.get(attributeValueProbEntry.getKey());
            if (value == null) {
                value = MISSING_VALUE_PLACEHOLDER;
            }
            Double valueProb = attributeValueProbEntry.getValue().get(value);
            if (valueProb == null) {
                valueProb = MISSING_PROBABILITY_PLACEHOLDER;
            }
            enrichedAttributes.put(attributeValueProbEntry.getKey()+ KEY_APPEND_STRING, valueProb);

        }
        return enrichedAttributes;
    }
View Full Code Here

    }

    class defaultDateTimeExtractor implements DateTimeExtractor<AttributesMap> {
        @Override
        public DateTime extractDateTime(Instance<AttributesMap> instance) {
            AttributesMap attributes = instance.getAttributes();
            int year = (Integer) attributes.get("timeOfArrival-year");
            int month = (Integer) attributes.get("timeOfArrival-monthOfYear");
            int day = (Integer) attributes.get("timeOfArrival-dayOfMonth");
            int hour = (Integer) attributes.get("timeOfArrival-hourOfDay");
            int minute = (Integer) attributes.get("timeOfArrival-minuteOfHour");
            return new DateTime(year, month, day, hour, minute, 0, 0);
        }
View Full Code Here

    }

    @Nullable
    @Override
    public AttributesMap apply(@Nullable final AttributesMap inputAttributes) {
        AttributesMap outputAttributes = AttributesMap.newHashMap();
        outputAttributes.putAll(inputAttributes);
        for (List<String> attributeKeys : attributesToCombine) {
            if (attributesNotCombinable(attributeKeys, inputAttributes))
                continue;
            StringBuilder values = new StringBuilder();
            for (String attributeKey : attributeKeys) {
                Serializable value = inputAttributes.get(attributeKey);
                if (value != null && value.toString().length() > 0) {
                    values.append(value.toString());
                } else {
                    values.append("-");
                }
            }
            outputAttributes.put(Joiner.on('-').join(attributeKeys), values.toString());
        }
        return outputAttributes;
    }
View Full Code Here

TOP

Related Classes of quickml.data.AttributesMap

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.