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());
}
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());
}
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();
}
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()]));
}
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);
}
Aggregations