smile.data.NumericAttribute Java Examples

The following examples show how to use smile.data.NumericAttribute. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SmileRandomForest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
protected Attribute createAttribute(String name, AttributeType type) {
    if (type == AttributeType.NOMINAL || type == AttributeType.BOOLEAN) {
        return new NominalAttribute(name);
    } else if (type == AttributeType.NUMERIC) {
        return new NumericAttribute(name);
    } else {
        return new StringAttribute(name);
    }
}
 
Example #2
Source File: LinkClassifierTrainer.java    From ache with Apache License 2.0 5 votes vote down vote up
/**
 * Converts the input instances into an AttributeDataset object that can be used to train a
 * SMILE classifier.
 * 
 * @param attributes
 * @param instances
 * @param wrapper
 * @param dataset
 * @throws IOException
 */
private AttributeDataset createDataset(List<Sampler<LinkNeighborhood>> instances,
        String[] features, List<String> classValues, LinkNeighborhoodWrapper wrapper) {
    
    List<Attribute> attributes = new ArrayList<>();
    for(String featureName : features) {
        NumericAttribute attribute = new NumericAttribute(featureName);
        attributes.add(attribute);
    }

    Attribute[] attributesArray = (Attribute[]) attributes.toArray(new Attribute[attributes.size()]);
    String[] classValuesArray = (String[]) classValues.toArray(new String[classValues.size()]);
    String description = "If link leads to relevant page or not.";
    Attribute response = new NominalAttribute("y", description, classValuesArray);
    AttributeDataset dataset = new AttributeDataset("link_classifier", attributesArray, response);

    for (int level = 0; level < instances.size(); level++) {
        Sampler<LinkNeighborhood> levelSamples = instances.get(level);
        for (LinkNeighborhood ln : levelSamples.getSamples()) {
            Instance instance;
            try {
                instance = wrapper.extractToInstance(ln, features);
            } catch (MalformedURLException e) {
                logger.warn("Failed to process intance: "+ln.getLink().toString(), e);
                continue;
            }
            double[] values = instance.getValues(); // the instance's feature vector
            int y = level; // the class we're trying to predict
            dataset.add(values, y);
        }
    }
    return dataset;
}