Search in sources :

Example 1 with TooManyValuesException

use of org.knime.base.node.mine.bayes.naivebayes.datamodel2.TooManyValuesException in project knime-core by knime.

the class NaiveBayesModel method updateModel.

/**
 * Updates the current {@link NaiveBayesModel} with the values from the
 * given {@link DataRow}.
 * @param row DataRow with values for update
 * @param tableSpec underlying DataTableSpec
 * @param classColIdx the index of the class column
 * @throws InvalidSettingsException if missing values occur in class column
 * or an attribute has too many values.
 */
public void updateModel(final DataRow row, final DataTableSpec tableSpec, final int classColIdx) throws InvalidSettingsException {
    if (row == null) {
        throw new NullPointerException("Row must not be null");
    }
    if (tableSpec == null) {
        throw new NullPointerException("TableSpec must not be null");
    }
    final DataCell classCell = row.getCell(classColIdx);
    if (classCell.isMissing()) {
        if (m_skipMissingVals) {
            return;
        }
        // check if the class value is missing
        throw new InvalidSettingsException("Missing class value found in row " + row.getKey() + " to skip missing values tick the box in the dialog");
    }
    final String classVal = classCell.toString();
    final int numColumns = tableSpec.getNumColumns();
    for (int i = 0; i < numColumns; i++) {
        final AttributeModel model = m_modelByAttrName.get(tableSpec.getColumnSpec(i).getName());
        if (model != null) {
            final DataCell cell = row.getCell(i);
            try {
                model.addValue(classVal, cell);
            } catch (final TooManyValuesException e) {
                if (model instanceof ClassAttributeModel) {
                    throw new InvalidSettingsException("Class attribute has too many unique values. " + "To avoid this exception increase the " + "maximum number of allowed nominal " + "values in the node dialog");
                }
                // delete the model if it contains too many unique values
                m_modelByAttrName.remove(model.getAttributeName());
                model.setInvalidCause("Too many values");
                m_skippedAttributes.add(model);
            }
        }
    }
    m_noOfRecs++;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataCell(org.knime.core.data.DataCell) TooManyValuesException(org.knime.base.node.mine.bayes.naivebayes.datamodel2.TooManyValuesException)

Example 2 with TooManyValuesException

use of org.knime.base.node.mine.bayes.naivebayes.datamodel2.TooManyValuesException in project knime-core by knime.

the class ClassAttributeModel method addValueInternal.

/**
 * {@inheritDoc}
 */
@Override
void addValueInternal(final String classValue, final DataCell attrValue) throws TooManyValuesException {
    if (attrValue.isMissing()) {
        throw new IllegalArgumentException("Missing value not allowed as class value");
    }
    MutableInteger classCounter = m_recsCounterByClassVal.get(classValue);
    if (classCounter == null) {
        if (m_recsCounterByClassVal.size() > m_maxNoOfClassVals) {
            throw new TooManyValuesException("Class value " + classValue + " doesn't fit into model");
        }
        classCounter = new MutableInteger(0);
        m_recsCounterByClassVal.put(classValue, classCounter);
    }
    classCounter.inc();
    m_totalNoOfRecs++;
}
Also used : MutableInteger(org.knime.core.util.MutableInteger) TooManyValuesException(org.knime.base.node.mine.bayes.naivebayes.datamodel2.TooManyValuesException)

Aggregations

TooManyValuesException (org.knime.base.node.mine.bayes.naivebayes.datamodel2.TooManyValuesException)2 DataCell (org.knime.core.data.DataCell)1 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)1 MutableInteger (org.knime.core.util.MutableInteger)1