Search in sources :

Example 6 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.

the class RegressionTreePredictorCellFactory method createFactory.

/**
 * @param predictor
 * @return factory based on RegressionTreePredictor <b>predictor</b>
 * @throws InvalidSettingsException
 */
public static RegressionTreePredictorCellFactory createFactory(final RegressionTreePredictor predictor) throws InvalidSettingsException {
    DataTableSpec testDataSpec = predictor.getDataSpec();
    RegressionTreeModelPortObjectSpec modelSpec = predictor.getModelSpec();
    RegressionTreePredictorConfiguration configuration = predictor.getConfiguration();
    UniqueNameGenerator nameGen = new UniqueNameGenerator(testDataSpec);
    List<DataColumnSpec> newColsList = new ArrayList<DataColumnSpec>();
    String targetColName = configuration.getPredictionColumnName();
    DataColumnSpec targetCol = nameGen.newColumn(targetColName, DoubleCell.TYPE);
    newColsList.add(targetCol);
    DataColumnSpec[] newCols = newColsList.toArray(new DataColumnSpec[newColsList.size()]);
    int[] learnColumnInRealDataIndices = modelSpec.calculateFilterIndices(testDataSpec);
    return new RegressionTreePredictorCellFactory(predictor, newCols, learnColumnInRealDataIndices);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ArrayList(java.util.ArrayList) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator)

Example 7 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.

the class RegressionTreeLearnerNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    BufferedDataTable t = (BufferedDataTable) inObjects[0];
    DataTableSpec spec = t.getDataTableSpec();
    final FilterLearnColumnRearranger learnRearranger = m_configuration.filterLearnColumns(spec);
    String warn = learnRearranger.getWarning();
    BufferedDataTable learnTable = exec.createColumnRearrangeTable(t, learnRearranger, exec.createSubProgress(0.0));
    DataTableSpec learnSpec = learnTable.getDataTableSpec();
    ExecutionMonitor readInExec = exec.createSubProgress(0.1);
    ExecutionMonitor learnExec = exec.createSubProgress(0.9);
    TreeDataCreator dataCreator = new TreeDataCreator(m_configuration, learnSpec, learnTable.getRowCount());
    exec.setProgress("Reading data into memory");
    TreeData data = dataCreator.readData(learnTable, m_configuration, readInExec);
    m_hiliteRowSample = dataCreator.getDataRowsForHilite();
    m_viewMessage = dataCreator.getViewMessage();
    String dataCreationWarning = dataCreator.getAndClearWarningMessage();
    if (dataCreationWarning != null) {
        if (warn == null) {
            warn = dataCreationWarning;
        } else {
            warn = warn + "\n" + dataCreationWarning;
        }
    }
    readInExec.setProgress(1.0);
    exec.setMessage("Learning tree");
    RandomData rd = m_configuration.createRandomData();
    final IDataIndexManager indexManager;
    if (data.getTreeType() == TreeType.BitVector) {
        indexManager = new BitVectorDataIndexManager(data.getNrRows());
    } else {
        indexManager = new DefaultDataIndexManager(data);
    }
    TreeNodeSignatureFactory signatureFactory = null;
    int maxLevels = m_configuration.getMaxLevels();
    if (maxLevels < TreeEnsembleLearnerConfiguration.MAX_LEVEL_INFINITE) {
        int capacity = IntMath.pow(2, maxLevels - 1);
        signatureFactory = new TreeNodeSignatureFactory(capacity);
    } else {
        signatureFactory = new TreeNodeSignatureFactory();
    }
    final RowSample rowSample = m_configuration.createRowSampler(data).createRowSample(rd);
    TreeLearnerRegression treeLearner = new TreeLearnerRegression(m_configuration, data, indexManager, signatureFactory, rd, rowSample);
    TreeModelRegression regTree = treeLearner.learnSingleTree(learnExec, rd);
    RegressionTreeModel model = new RegressionTreeModel(m_configuration, data.getMetaData(), regTree, data.getTreeType());
    RegressionTreeModelPortObjectSpec treePortObjectSpec = new RegressionTreeModelPortObjectSpec(learnSpec);
    RegressionTreeModelPortObject treePortObject = new RegressionTreeModelPortObject(model, treePortObjectSpec);
    learnExec.setProgress(1.0);
    m_treeModelPortObject = treePortObject;
    if (warn != null) {
        setWarningMessage(warn);
    }
    return new PortObject[] { treePortObject };
}
Also used : RegressionTreeModelPortObject(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) RandomData(org.apache.commons.math.random.RandomData) RegressionTreeModel(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel) IDataIndexManager(org.knime.base.node.mine.treeensemble2.data.memberships.IDataIndexManager) BitVectorDataIndexManager(org.knime.base.node.mine.treeensemble2.data.memberships.BitVectorDataIndexManager) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec) DefaultDataIndexManager(org.knime.base.node.mine.treeensemble2.data.memberships.DefaultDataIndexManager) TreeModelRegression(org.knime.base.node.mine.treeensemble2.model.TreeModelRegression) BufferedDataTable(org.knime.core.node.BufferedDataTable) FilterLearnColumnRearranger(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) TreeData(org.knime.base.node.mine.treeensemble2.data.TreeData) TreeLearnerRegression(org.knime.base.node.mine.treeensemble2.learner.TreeLearnerRegression) RowSample(org.knime.base.node.mine.treeensemble2.sample.row.RowSample) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) TreeDataCreator(org.knime.base.node.mine.treeensemble2.data.TreeDataCreator) RegressionTreeModelPortObject(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObject) PortObject(org.knime.core.node.port.PortObject) TreeNodeSignatureFactory(org.knime.base.node.mine.treeensemble2.learner.TreeNodeSignatureFactory)

Example 8 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.

the class RegressionTreePMMLPredictorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
public PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    PMMLPortObject pmmlPO = (PMMLPortObject) inObjects[0];
    Pair<RegressionTreeModel, RegressionTreeModelPortObjectSpec> modelSpecPair = importModel(pmmlPO);
    BufferedDataTable data = (BufferedDataTable) inObjects[1];
    DataTableSpec dataSpec = data.getDataTableSpec();
    // Can only happen if configure was not called before execute e.g. in generic PMML Predictor
    if (m_configuration == null) {
        m_configuration = RegressionTreePredictorConfiguration.createDefault(translateSpec(pmmlPO.getSpec()).getTargetColumn().getName());
    }
    final RegressionTreePredictor pred = new RegressionTreePredictor(modelSpecPair.getFirst(), modelSpecPair.getSecond(), dataSpec, m_configuration);
    ColumnRearranger rearranger = pred.getPredictionRearranger();
    BufferedDataTable outTable = exec.createColumnRearrangeTable(data, rearranger, exec);
    return new BufferedDataTable[] { outTable };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) RegressionTreeModel(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel) BufferedDataTable(org.knime.core.node.BufferedDataTable) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec)

Example 9 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.

the class RegressionTreePMMLPredictorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[0];
    DataType targetType = extractTargetType(pmmlSpec);
    if (!targetType.isCompatible(DoubleValue.class)) {
        throw new InvalidSettingsException("This node expects a regression model.");
    }
    try {
        AbstractTreeModelPMMLTranslator.checkPMMLSpec(pmmlSpec);
    } catch (IllegalArgumentException e) {
        throw new InvalidSettingsException(e.getMessage());
    }
    RegressionTreeModelPortObjectSpec modelSpec = translateSpec(pmmlSpec);
    String targetColName = modelSpec.getTargetColumn().getName();
    if (m_configuration == null) {
        m_configuration = RegressionTreePredictorConfiguration.createDefault(targetColName);
    } else if (!m_configuration.isChangePredictionColumnName()) {
        m_configuration.setPredictionColumnName(TreeEnsemblePredictorConfiguration.getPredictColumnName(targetColName));
    }
    DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
    final RegressionTreePredictor pred = new RegressionTreePredictor(null, modelSpec, dataSpec, m_configuration);
    return new PortObjectSpec[] { pred.getPredictionRearranger().createSpec() };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) DoubleValue(org.knime.core.data.DoubleValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DataType(org.knime.core.data.DataType) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec)

Example 10 with RegressionTreeModelPortObjectSpec

use of org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec in project knime-core by knime.

the class RegressionTreePredictorPanel method loadSettingsFrom.

/**
 * Loads the settings.
 *
 * @param settings
 * @param specs
 * @throws NotConfigurableException
 */
public void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    final RegressionTreeModelPortObjectSpec modelSpec = (RegressionTreeModelPortObjectSpec) specs[0];
    final DataColumnSpec targetSpec = modelSpec.getTargetColumn();
    RegressionTreePredictorConfiguration config = new RegressionTreePredictorConfiguration(targetSpec.getName());
    config.loadInDialog(settings);
    String colName = config.getPredictionColumnName();
    if (colName == null || colName.isEmpty()) {
        colName = RegressionTreePredictorConfiguration.getPredictColumnName("");
    }
    m_predictionColNameField.setText(colName);
    m_changePredictionColNameCheckBox.setSelected(config.isChangePredictionColumnName());
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec)

Aggregations

RegressionTreeModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec)12 DataTableSpec (org.knime.core.data.DataTableSpec)9 RegressionTreeModel (org.knime.base.node.mine.treeensemble2.model.RegressionTreeModel)5 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)5 RegressionTreeModelPortObject (org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObject)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)3 TreeModelRegression (org.knime.base.node.mine.treeensemble2.model.TreeModelRegression)2 RegressionTreeModelPMMLTranslator (org.knime.base.node.mine.treeensemble2.model.pmml.RegressionTreeModelPMMLTranslator)2 FilterLearnColumnRearranger (org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 PortObject (org.knime.core.node.port.PortObject)2 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)2 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)2 ArrayList (java.util.ArrayList)1 RandomData (org.apache.commons.math.random.RandomData)1 TreeData (org.knime.base.node.mine.treeensemble2.data.TreeData)1 TreeDataCreator (org.knime.base.node.mine.treeensemble2.data.TreeDataCreator)1 BitVectorDataIndexManager (org.knime.base.node.mine.treeensemble2.data.memberships.BitVectorDataIndexManager)1