private static XgbTreeNode ParseXgbTreeNode(string line) { var node = new XgbTreeNode(); try { if (line.Contains("leaf")) { Match m = leafRegex.Match(line); node.Number = Int32.Parse(m.Groups[1].Value); node.LeafValue = Double.Parse(m.Groups[2].Value, CultureInfo.InvariantCulture); node.Cover = Double.Parse(m.Groups[3].Value, CultureInfo.InvariantCulture); node.IsLeaf = true; } else { Match m = nodeRegex.Match(line); node.Number = Int32.Parse(m.Groups[1].Value); node.Feature = m.Groups[2].Value; node.SplitValue = Double.Parse(m.Groups[3].Value, CultureInfo.InvariantCulture); node.LeftChild = Int32.Parse(m.Groups[4].Value); node.RightChild = Int32.Parse(m.Groups[5].Value); node.Gain = Double.Parse(m.Groups[6].Value, CultureInfo.InvariantCulture); node.Cover = Double.Parse(m.Groups[7].Value, CultureInfo.InvariantCulture); node.IsLeaf = false; } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(String.Format("Error: Invalid model file. Did you dump the model w/ with_stats=True?")); Console.WriteLine(String.Format("Unable to parse line '{0}'", line)); Console.WriteLine(e.Message); Console.ResetColor(); return(null); } return(node); }
private static XgbTreeNode ParseXgbTreeNode(string line) { var node = new XgbTreeNode(); try { if (line.Contains("leaf")) { Match m = leafRegex.Match(line); node.Number = Int32.Parse(m.Groups[1].Value); node.LeafValue = Double.Parse(m.Groups[2].Value, CultureInfo.InvariantCulture); node.Cover = Double.Parse(m.Groups[3].Value, CultureInfo.InvariantCulture); node.IsLeaf = true; } else { Match m = nodeRegex.Match(line); node.Number = Int32.Parse(m.Groups[1].Value); node.Feature = m.Groups[2].Value; node.SplitValue = Double.Parse(m.Groups[3].Value, CultureInfo.InvariantCulture); node.LeftChild = Int32.Parse(m.Groups[4].Value); node.RightChild = Int32.Parse(m.Groups[5].Value); node.Gain = Double.Parse(m.Groups[6].Value, CultureInfo.InvariantCulture); node.Cover = Double.Parse(m.Groups[7].Value, CultureInfo.InvariantCulture); node.IsLeaf = false; } } catch(Exception e) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(String.Format("Error: Invalid model file. Did you dump the model w/ with_stats=True?")); Console.WriteLine(String.Format("Unable to parse line '{0}'", line)); Console.WriteLine(e.Message); Console.ResetColor(); return null; } return node; }