double RunModelForSingleData(double[] data) { try { double value = double.PositiveInfinity; if (_root == null) { return(value); //Model not computed } DecisionTreeNode dtn = _root; //Deal with missing values while (dtn.AttributeIndex != _origTargetAttributeIndex) { //Children are stored with Index dtn = dtn.getChildWithValue( data[dtn.AttributeIndex]); if (dtn == null) //Is null likely due to missing value, ignore it in this case { return(Constants.MISSING_VALUE); } } value = dtn.Value; return(value); } catch (Exception ex) { throw new ModelRunException(ex.Message, ex); } }
long getNumberOfCorrectPredictions(double[][] data) { long correctCount = 0; if (_root != null) //Model not computed { try { for (int rowIdx = 0; rowIdx < data[0].Length; rowIdx++) { DecisionTreeNode dtn = _root; //Deal with missing values while (dtn.AttributeIndex != _origTargetAttributeIndex) //dtn.AttributeIndex < 0 denoted invalid node { if (data[dtn.AttributeIndex][rowIdx] < dtn.Value) { //Children are stored with Index dtn = dtn.getChildWithValue(0); } else { dtn = dtn.getChildWithValue(1); } if (dtn == null) //Is null likely due to missing value, ignore it in this case { break; } } if (dtn.Value == data[_origTargetAttributeIndex][rowIdx]) { correctCount++; } } } catch (Exception ex) { throw new ModelRunException(ex.Message, ex); } } return(correctCount); }