Example usage for weka.core Instances mergeInstances

List of usage examples for weka.core Instances mergeInstances

Introduction

In this page you can find the example usage for weka.core Instances mergeInstances.

Prototype

public static Instances mergeInstances(Instances first, Instances second) 

Source Link

Document

Merges two sets of Instances together.

Usage

From source file:org.opentox.jaqpot3.qsar.predictor.PLSPredictor.java

License:Open Source License

@Override
public Instances predict(Instances input) throws JaqpotException {
    PLSModel actual = (PLSModel) model.getActualModel().getSerializableActualModel();
    PLSFilter plsFilter = actual.getPls();
    Instances newData = InstancesUtil.sortForPMMLModel(model.getIndependentFeatures(), trFieldsAttrIndex, input,
            -1);/*from   w w  w.  j  a  va  2 s  .c o m*/
    try {
        newData = Filter.useFilter(newData, plsFilter);
    } catch (Exception ex) {
        Logger.getLogger(PLSPredictor.class.getName()).log(Level.SEVERE, null, ex);
    }

    AttributeCleanup justCompounds = new AttributeCleanup(true, nominal, numeric, string);
    Instances compounds = null;
    try {
        compounds = justCompounds.filter(input);
    } catch (QSARException ex) {
        //                logger.debug(null, ex);
    }

    int i = 0;
    for (Feature f : model.getPredictedFeatures()) {
        newData.renameAttribute(i++, f.getUri().toString());
    }
    String target = null;
    for (Parameter p : model.getParameters()) {
        if ("target".equals(p.getName().getValueAsString())) {
            target = p.getValue().toString();
        }
    }
    newData.renameAttribute(newData.attribute("Class"), target);

    List<Integer> trFieldsIndex = WekaInstancesProcess.getTransformationFieldsAttrIndex(newData, pmmlObject);
    newData = WekaInstancesProcess.removeInstancesAttributes(newData, trFieldsIndex);
    newData = Instances.mergeInstances(compounds, newData);
    return newData;
}

From source file:org.opentox.jaqpot3.qsar.predictor.WekaPredictor.java

License:Open Source License

@Override
public Instances predict(Instances inputSet) throws JaqpotException {

    /* THE OBJECT newData WILL HOST THE PREDICTIONS... */
    Instances newData = InstancesUtil.sortForPMMLModel(model.getIndependentFeatures(), trFieldsAttrIndex,
            inputSet, -1);/*from  w w  w.  j ava2s  .c o m*/
    /* ADD TO THE NEW DATA THE PREDICTION FEATURE*/
    Add attributeAdder = new Add();
    attributeAdder.setAttributeIndex("last");
    attributeAdder.setAttributeName(model.getPredictedFeatures().iterator().next().getUri().toString());
    Instances predictions = null;
    try {
        attributeAdder.setInputFormat(newData);
        predictions = Filter.useFilter(newData, attributeAdder);
        predictions.setClass(
                predictions.attribute(model.getPredictedFeatures().iterator().next().getUri().toString()));
    } catch (Exception ex) {
        String message = "Exception while trying to add prediction feature to Instances";
        logger.debug(message, ex);
        throw new JaqpotException(message, ex);
    }

    if (predictions != null) {
        Classifier classifier = (Classifier) model.getActualModel().getSerializableActualModel();

        int numInstances = predictions.numInstances();
        for (int i = 0; i < numInstances; i++) {
            try {
                double predictionValue = classifier.distributionForInstance(predictions.instance(i))[0];
                predictions.instance(i).setClassValue(predictionValue);
            } catch (Exception ex) {
                logger.warn("Prediction failed :-(", ex);
            }
        }
    }

    List<Integer> trFieldsIndex = WekaInstancesProcess.getTransformationFieldsAttrIndex(predictions,
            pmmlObject);
    predictions = WekaInstancesProcess.removeInstancesAttributes(predictions, trFieldsIndex);
    Instances result = Instances.mergeInstances(justCompounds, predictions);

    return result;
}

From source file:soccer.core.models.BookKeeperConsistency.java

public Instances getInstances() throws Exception {
    Instances instances = loader.getDataSet();

    setInstances(instances);

    return Instances.mergeInstances(is, instances);
}