// buttonXCreateModel click event private void buttonXCreateModel_Click(object sender, EventArgs e) { DialogResult dialogResult; DataTable orginalTrainningTable = this.dataGridViewXTrainning.DataSource as DataTable; DataTable tableForTrainning; int numberOfTrainningRows = 0; // Get number of row form percent if (this.comboBoxExTrainningDataPercent.SelectedValue != null) { numberOfTrainningRows = Convert.ToInt32(Math.Truncate( ((int)comboBoxExTrainningDataPercent.SelectedValue * 1.0 * orginalTrainningTable.Rows.Count) / 100)); } // Set trainning data if (numberOfTrainningRows == 0) { tableForTrainning = orginalTrainningTable; } else { var query = orginalTrainningTable.AsEnumerable().Take(numberOfTrainningRows); tableForTrainning = query.CopyToDataTable <DataRow>(); } TrainningData trainningData = new TrainningData(tableForTrainning, this.codification); Properties.Settings.Default.negativeValue = trainningData.NegativeValue; // Ask user what to do when selected model already exists if (this.HaveModel()) { dialogResult = MessageBox.Show("Mô hình này đã có. Bạn có muốn tạo mô hình mới?", "Lỗi", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.No || dialogResult == DialogResult.Cancel) { return; } } // Check dictionary already have active model. If not add new model if (!this.modelList.ContainsKey(this.activeLearningAlgorithm)) { this.modelList.Add(this.activeLearningAlgorithm, ClassificationModel.CreateModel(this.activeLearningAlgorithm)); } // Trainning model this.modelList[activeLearningAlgorithm].TrainningModel(trainningData); }
// buttonXTestModel click event private void buttonXTestModel_Click(object sender, EventArgs e) { int numberOfTrainningRows = 0; DataTable orginalTrainningTable = this.dataGridViewXTrainning.DataSource as DataTable; DataTable testTable; // Get number of row form percent if (this.comboBoxExTrainningDataPercent.SelectedValue != null) { numberOfTrainningRows = Convert.ToInt32(Math.Truncate( ((int)comboBoxExTrainningDataPercent.SelectedValue * 1.0 * orginalTrainningTable.Rows.Count) / 100)); } // Set test data var query = orginalTrainningTable.AsEnumerable().Skip(numberOfTrainningRows); testTable = query.CopyToDataTable <DataRow>(); if (!HaveModel()) { MessageBox.Show("Chưa có mô hình!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } TrainningData data = new TrainningData(testTable, this.codification); // Show test result dataGridViewXTrainningResult.DataSource = this.modelList[activeLearningAlgorithm].TestModel(data); List <int> hideColumns = new List <int>(new int[] { 9, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }); for (int indexColum = 0; indexColum < this.dataGridViewXTrainningResult.Columns.Count; indexColum++) { if (hideColumns.Contains(indexColum)) { this.dataGridViewXTrainningResult.Columns[indexColum].Visible = false; } } }