public static IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData, IRandom random, ILeafModel leafModel = null, ISplitter splitter = null, IPruning pruning = null, bool useHoldout = false, double holdoutSize = 0.2, int minimumLeafSize = 1, bool generateRules = false, ResultCollection results = null, CancellationToken?cancellationToken = null) { if (leafModel == null) { leafModel = new LinearLeaf(); } if (splitter == null) { splitter = new Splitter(); } if (cancellationToken == null) { cancellationToken = CancellationToken.None; } if (pruning == null) { pruning = new ComplexityPruning(); } var stateScope = InitializeScope(random, problemData, pruning, minimumLeafSize, leafModel, splitter, generateRules, useHoldout, holdoutSize); var model = Build(stateScope, results, cancellationToken.Value); return(model.CreateRegressionSolution(problemData)); }
public static void PruningChart(RegressionNodeTreeModel tree, ComplexityPruning pruning, ResultCollection results) { var nodes = new Queue <RegressionNodeModel>(); nodes.Enqueue(tree.Root); var max = 0.0; var strenghts = new SortedList <double, int>(); while (nodes.Count > 0) { var n = nodes.Dequeue(); if (n.IsLeaf) { max++; continue; } if (!strenghts.ContainsKey(n.PruningStrength)) { strenghts.Add(n.PruningStrength, 0); } strenghts[n.PruningStrength]++; nodes.Enqueue(n.Left); nodes.Enqueue(n.Right); } if (strenghts.Count == 0) { return; } var plot = new ScatterPlot("Pruned Sizes", "") { VisualProperties = { XAxisTitle = "Pruning Strength", YAxisTitle = "Tree Size", XAxisMinimumAuto = false, XAxisMinimumFixedValue = 0 } }; var row = new ScatterPlotDataRow("TreeSizes", "", new List <Point2D <double> >()); row.Points.Add(new Point2D <double>(pruning.PruningStrength, max)); var fillerDots = new Queue <double>(); var minX = pruning.PruningStrength; var maxX = strenghts.Last().Key; var size = (maxX - minX) / 200; for (var x = minX; x <= maxX; x += size) { fillerDots.Enqueue(x); } foreach (var strenght in strenghts.Keys) { while (fillerDots.Count > 0 && strenght > fillerDots.Peek()) { row.Points.Add(new Point2D <double>(fillerDots.Dequeue(), max)); } max -= strenghts[strenght]; row.Points.Add(new Point2D <double>(strenght, max)); } row.VisualProperties.PointSize = 6; plot.Rows.Add(row); results.AddOrUpdateResult("PruningSizes", plot); }
protected ComplexityPruning(ComplexityPruning original, Cloner cloner) : base(original, cloner) { }