Search in sources :

Example 1 with TreeTargetNumericColumnMetaData

use of org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData in project knime-core by knime.

the class LKGradientBoostedTreesLearner method createNumericDataFromArray.

private TreeData createNumericDataFromArray(final double[] numericData) {
    TreeData data = getData();
    TreeTargetNominalColumnData nominalTarget = (TreeTargetNominalColumnData) data.getTargetColumn();
    TreeTargetNumericColumnMetaData newMeta = new TreeTargetNumericColumnMetaData(nominalTarget.getMetaData().getAttributeName());
    TreeTargetNumericColumnData newTarget = new TreeTargetNumericColumnData(newMeta, nominalTarget.getRowKeys(), numericData);
    return new TreeData(data.getColumns(), newTarget, data.getTreeType());
}
Also used : TreeTargetNumericColumnData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnData) TreeData(org.knime.base.node.mine.treeensemble2.data.TreeData) TreeTargetNumericColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData) TreeTargetNominalColumnData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNominalColumnData)

Example 2 with TreeTargetNumericColumnMetaData

use of org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData in project knime-core by knime.

the class AbstractGradientBoostingLearner method createResidualDataFromArray.

/**
 * Creates a {@link TreeData} object that uses the values in <b>residualData</b> as target.
 *
 * @param residualData array containing the residuals
 * @param actualData the TreeData as it is provided by the user
 * @return data using the residuals as targets
 */
protected TreeData createResidualDataFromArray(final double[] residualData, final TreeData actualData) {
    TreeTargetNumericColumnData actual = (TreeTargetNumericColumnData) actualData.getTargetColumn();
    RowKey[] rowKeysAsArray = new RowKey[actual.getNrRows()];
    for (int i = 0; i < rowKeysAsArray.length; i++) {
        rowKeysAsArray[i] = actual.getRowKeyFor(i);
    }
    TreeTargetNumericColumnMetaData metaData = actual.getMetaData();
    TreeTargetNumericColumnData residualTarget = new TreeTargetNumericColumnData(metaData, rowKeysAsArray, residualData);
    return new TreeData(getData().getColumns(), residualTarget, getData().getTreeType());
}
Also used : RowKey(org.knime.core.data.RowKey) TreeTargetNumericColumnData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnData) TreeTargetNumericColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData) TreeData(org.knime.base.node.mine.treeensemble2.data.TreeData)

Example 3 with TreeTargetNumericColumnMetaData

use of org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData in project knime-core by knime.

the class AbstractGBTModelPMMLTranslator method initializeFrom.

/**
 * {@inheritDoc}
 */
@Override
public void initializeFrom(final PMMLDocument pmmlDoc) {
    PMML pmml = pmmlDoc.getPMML();
    if (pmml.getHeader() == null || pmml.getHeader().getApplication() == null || !pmml.getHeader().getApplication().getName().equals("KNIME")) {
        throw new IllegalArgumentException("Currently only models created with KNIME are supported.");
    }
    List<MiningModel> mmList = pmml.getMiningModelList();
    if (mmList == null || mmList.isEmpty()) {
        throw new IllegalArgumentException("The provided PMML does not contain a Gradient Boosted Trees model.");
    }
    MiningModel model = mmList.get(0);
    MetaDataMapper<TreeTargetNumericColumnMetaData> metaDataMapper = new RegressionMetaDataMapper(pmmlDoc, getTargetFieldName(model));
    AbstractGBTModelImporter<M> importer = createImporter(metaDataMapper);
    m_gbtModel = importer.importFromPMML(pmml.getMiningModelList().get(0));
    m_learnSpec = metaDataMapper.getLearnSpec();
}
Also used : MiningModel(org.dmg.pmml.MiningModelDocument.MiningModel) PMML(org.dmg.pmml.PMMLDocument.PMML) TreeTargetNumericColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData)

Example 4 with TreeTargetNumericColumnMetaData

use of org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData in project knime-core by knime.

the class AbstractRegressionContentParser method createNode.

@Override
public final TreeNodeRegression createNode(final Node node, final TargetColumnHelper<TreeTargetNumericColumnMetaData> targetHelper, final TreeNodeSignature signature, final List<TreeNodeRegression> children) {
    double mean = Double.parseDouble(node.getScore());
    OptionalDouble totalSum = node.getExtensionList().stream().filter(e -> e.getName().equals(TranslationUtil.TOTAL_SUM_KEY)).mapToDouble(e -> Double.parseDouble(e.getValue())).findFirst();
    OptionalDouble sumSquaredDeviation = node.getExtensionList().stream().filter(e -> e.getName().equals(TranslationUtil.SUM_SQUARED_DEVIATION_KEY)).mapToDouble(e -> Double.parseDouble(e.getValue())).findFirst();
    return createNodeInternal(node, targetHelper.getMetaData(), signature, mean, totalSum.orElse(-1), sumSquaredDeviation.orElse(-1), children.toArray(new TreeNodeRegression[children.size()]));
}
Also used : List(java.util.List) TreeTargetNumericColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData) TreeNodeSignature(org.knime.base.node.mine.treeensemble2.model.TreeNodeSignature) TreeNodeRegression(org.knime.base.node.mine.treeensemble2.model.TreeNodeRegression) OptionalDouble(java.util.OptionalDouble) Node(org.dmg.pmml.NodeDocument.Node) TreeNodeRegression(org.knime.base.node.mine.treeensemble2.model.TreeNodeRegression) OptionalDouble(java.util.OptionalDouble)

Example 5 with TreeTargetNumericColumnMetaData

use of org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData in project knime-core by knime.

the class AbstractGBTModelImporter method readTreeModel.

private Pair<TreeModelRegression, Map<TreeNodeSignature, Double>> readTreeModel(final Segment segment) {
    GBTRegressionContentParser contentParser = new GBTRegressionContentParser();
    TreeModelImporter<TreeNodeRegression, TreeModelRegression, TreeTargetNumericColumnMetaData> treeImporter = new TreeModelImporter<TreeNodeRegression, TreeModelRegression, TreeTargetNumericColumnMetaData>(m_metaDataMapper, m_conditionParser, m_signatureFactory, contentParser, m_treeFactory);
    TreeModel treeModel = segment.getTreeModel();
    TreeModelRegression tree = treeImporter.importFromPMML(treeModel);
    Map<TreeNodeSignature, Double> coefficientMap = contentParser.getCoefficientMap();
    return new Pair<>(tree, coefficientMap);
}
Also used : TreeModel(org.dmg.pmml.TreeModelDocument.TreeModel) TreeTargetNumericColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData) TreeNodeSignature(org.knime.base.node.mine.treeensemble2.model.TreeNodeSignature) TreeNodeRegression(org.knime.base.node.mine.treeensemble2.model.TreeNodeRegression) TreeModelRegression(org.knime.base.node.mine.treeensemble2.model.TreeModelRegression) Pair(org.knime.core.util.Pair)

Aggregations

TreeTargetNumericColumnMetaData (org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData)5 TreeData (org.knime.base.node.mine.treeensemble2.data.TreeData)2 TreeTargetNumericColumnData (org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnData)2 TreeNodeRegression (org.knime.base.node.mine.treeensemble2.model.TreeNodeRegression)2 TreeNodeSignature (org.knime.base.node.mine.treeensemble2.model.TreeNodeSignature)2 List (java.util.List)1 OptionalDouble (java.util.OptionalDouble)1 MiningModel (org.dmg.pmml.MiningModelDocument.MiningModel)1 Node (org.dmg.pmml.NodeDocument.Node)1 PMML (org.dmg.pmml.PMMLDocument.PMML)1 TreeModel (org.dmg.pmml.TreeModelDocument.TreeModel)1 TreeTargetNominalColumnData (org.knime.base.node.mine.treeensemble2.data.TreeTargetNominalColumnData)1 TreeModelRegression (org.knime.base.node.mine.treeensemble2.model.TreeModelRegression)1 RowKey (org.knime.core.data.RowKey)1 Pair (org.knime.core.util.Pair)1