public string Predict(T record) { if (mSplitVariableName == DecisionTree.DecisionTree <T> .ClassVariableName) { return(PredictedLabel); } else { string featureValue = record[mSplitVariableName]; if (record.IsCategorical(mSplitVariableName)) { if (mChildren.ContainsKey(featureValue)) { DecisionTreeNode <T> child = mChildren[featureValue]; return(child.Predict(record)); } else { return(null); } } else { double numericFeatureValue = 0; if (double.TryParse(featureValue, out numericFeatureValue)) { foreach (string key in mChildren.Keys) { if (key.StartsWith("<=")) { double cutoff = double.Parse(key.Replace("<=", "").Trim()); if (numericFeatureValue <= cutoff) { return(mChildren[key].Predict(record)); } } else { double cutoff = double.Parse(key.Replace(">", "").Trim()); if (numericFeatureValue > cutoff) { return(mChildren[key].Predict(record)); } } } } else { List <string> keys = mChildren.Keys.ToList(); string selectedKey = keys[RandomEngine.NextInt(keys.Count)]; return(mChildren[selectedKey].Predict(record)); } } } return(null); }
public string Predict(T record) { return(mRootNode.Predict(record)); }