Package com.blazebit.ai.decisiontree

Examples of com.blazebit.ai.decisiontree.Attribute


                usedAttributesNew.add(usedAttribute);
            } else {
                usedAttributesNew = localUsedAttributes;
            }

            final Attribute selectedAttribute = attributeSelector.select(examples, attributes, usedAttributesNew);

            if (selectedAttribute == null) {
                return new LeafNode<T>(examples);
            }

            return selectedAttribute.createNode(new SimpleDecisionNodeFactory(usedAttributesNew), examples);
        }
View Full Code Here


*/
public class ID3AttributeSelector implements AttributeSelector<Boolean> {

    @Override
    public Attribute select(final Set<Example<Boolean>> examples, final Set<Attribute> availableAttributes, final Set<Attribute> usedAttributes) {
        Attribute attribute = null;
        float attributeRem = Float.MAX_VALUE;
        int attributeValueCount = Integer.MAX_VALUE;
        float positives = 0;
        float negatives = 0;

        final Map<Attribute, Map<AttributeValue, Pair>> attributeUsage = new HashMap<Attribute, Map<AttributeValue, Pair>>();
       
        /* Make array for performance */
        final Example<Boolean>[] exampleArray = examples.toArray(new Example[0]);
        final int examplesSize = exampleArray.length;
       
        for (final Attribute attr : availableAttributes) {
            if (usedAttributes.contains(attr)) {
                continue;
            }

            final Map<AttributeValue, Pair> valueUsage = new HashMap<AttributeValue, Pair>();
            attributeUsage.put(attr, valueUsage);

            for (int i = 0; i < examplesSize; i++) {
                final AttributeValue value = exampleArray[i].getValues().get(attr);
                Pair valueUsageExamples = valueUsage.get(value);

                if (valueUsageExamples == null) {
                    valueUsageExamples = new Pair();
                    valueUsage.put(value, valueUsageExamples);
                }

                if (exampleArray[i].getResult()) {
                    ++valueUsageExamples.positive;
                    ++positives;
                } else {
                    ++valueUsageExamples.negative;
                    ++negatives;
                }
            }
        }

        if (positives > 0 && negatives > 0) {
            for (final Map.Entry<Attribute, Map<AttributeValue, Pair>> entry : attributeUsage.entrySet()) {
                final Attribute attr = entry.getKey();
                final float rem = Pair.rem(entry.getValue().values(), positives, negatives);

                if (rem < attributeRem) {
                    attribute = attr;
                    attributeRem = rem;
View Full Code Here

            return false;
        }
        if (!(obj instanceof Attribute)) {
            return false;
        }
        final Attribute other = (Attribute) obj;
        final String localName1 = this.name;
        final String localName2 = other.getName();
        if ((localName1 == null) ? (localName2 != null) : !localName1.equals(localName2)) {
            return false;
        }
        return true;
    }
View Full Code Here

TOP

Related Classes of com.blazebit.ai.decisiontree.Attribute

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.