// ---------------------------------------------------------------------------------------------------- // Method to initialize public void Initialize(DecisionTree dsTree, LibraryDecisionTree libDsTree) { viewComboBox.SelectedIndex = 0; conditionComboBox.SelectedIndex = 0; gradeComboBox.SelectedIndex = 0; sqftLiving15ComboBox.SelectedIndex = 0; sqftLivingComboBox.SelectedIndex = 0; sqftAboveComboBox.SelectedIndex = 0; sqftBsmteComboBox.SelectedIndex = 0; sqftLiving15ComboBox.SelectedIndex = 0; sqftLot15ComboBox.SelectedIndex = 0; sqftLotComboBox.SelectedIndex = 0; OwnImplementation = true; this.dsTree = dsTree; this.libDsTree = libDsTree; }
// ---------------------------------------------------------------------------------------------------- // Initialize method public void Initialize(DecisionTree dsTree, LibraryDecisionTree libDsTree, PredictControl pControl) { DecisionTree = dsTree; LibraryDecisionTree = libDsTree; PredictControl = pControl; trainingSizeSelector.SelectedIndex = 8; implementationOption1.Select(); }
// ---------------------------------------------------------------------------------------------------- // Constructor method public MainWindow() { InitializeComponent(); mainWindowTabs.DrawItem += new DrawItemEventHandler(mainWindowTabs_DrawItem); Manager = new DataSetManager(); GraphicsManager = new GraphicsProcessor(Manager); DecisionTree = new DecisionTree(Manager.Data, "price_range"); LibraryDecisionTree = new LibraryDecisionTree(); chartsControl1.Initialize(GraphicsManager); dataViewerControl.Initialize(Manager, chartsControl1); decisionTreeControl.Initialize(DecisionTree, LibraryDecisionTree, predictControl); predictControl.Initialize(DecisionTree, LibraryDecisionTree); }
// ---------------------------------------------------------------------------------------------------- // Method to implementate the tree (Button) private void selectImplementationButton_Click(object sender, EventArgs e) { if (implementationOption1.Checked) { try { int heightLimit = int.Parse(heigthLimitTxtBox.Text); if (heightLimit <= 1) { throw new FormatException("Invalid height"); } double trainingP = double.Parse((string)trainingSizeSelector.SelectedItem); double testP = double.Parse((string)testSizeSelector.SelectedItem); Stopwatch sw = new Stopwatch(); sw.Start(); DecisionTree.GenerateTree(heightLimit, trainingP, testP); sw.Stop(); Console.WriteLine("Training time(own): " + sw.ElapsedMilliseconds + " ms"); accuracyLabelTraining.Text = "Accuracy: " + Math.Round(DecisionTree.AccuracyTraining * 100, 2) + "%"; resetTreeButton.Enabled = true; trainButton.Enabled = false; LoadTree(DecisionTree.Root); testingButton.Enabled = true; PredictControl.OwnImplementation = true; } catch (FormatException) { MessageBox.Show("Be sure the number input is correct!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (implementationOption2.Checked) { Stopwatch sw = new Stopwatch(); sw.Start(); LibraryDecisionTree.BuildMultiClassificationTree(); sw.Stop(); Console.WriteLine("Training time(library): " + sw.ElapsedMilliseconds + " ms"); double accuracyTraining = LibraryDecisionTree.ClassificationTrainingMetrics.MicroAccuracy; double accuracyTesting = LibraryDecisionTree.ClassificationTestMetrics.MicroAccuracy; accuracyLabelTraining.Text = $"Accuracy: {Math.Round(accuracyTraining*100,2)}%"; accuracyLabelTest.Text = $"Accuracy: {Math.Round(accuracyTesting * 100, 2)}%"; PredictControl.OwnImplementation = false; } else { MessageBox.Show("Please select one option"); } }