// View diagnosis result private void buttonXDiagnosis_Click(object sender, EventArgs e) { if (this.modelList.Count < 1) { MessageBox.Show("Chưa có mô hình!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.dataGridViewXDiagnosis.DataSource != null) { if (this.trainningDataTabDianosis == null) { this.dataGridViewXDiagnosis.DataSource = DiscretizationData .DataDiscretizationForDiagnosis(this.dataGridViewXDiagnosis.DataSource as DataTable); } } else { MessageBox.Show("Chưa có dữ liệu để chuẩn đoán", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DataTable diagnosisDataTable = (this.dataGridViewXDiagnosis.DataSource as DataTable) .DefaultView.ToTable(false, TableMetaData.AllAttributes); this.trainningDataTabDianosis = new TrainningData(diagnosisDataTable, this.codification); DataTable resultTable = new DataTable(); List <int[]> modelResults = new List <int[]>(); string classColumnName = TableMetaData.ClassAttribute; DataRow row; // Add column foreach (var model in this.modelList) { if (model.Value.ToString() != "NaiveBayesS") { resultTable.Columns.Add(model.Value.ToString(), typeof(String)); modelResults.Add(model.Value.ComputeModel(this.trainningDataTabDianosis.TrainningAttributes)); } } // Add row int columnIndex; for (int rowIndex = 0; rowIndex < modelResults[0].Length; rowIndex++) { row = resultTable.NewRow(); columnIndex = 0; foreach (DataColumn column in resultTable.Columns) { row[column] = this.trainningDataTabDianosis.CodificationData .Translate(classColumnName, modelResults[columnIndex++][rowIndex]); } resultTable.Rows.Add(row); } this.dataGridViewXDiagnosisResult.DataSource = resultTable; }
private void buttonXDataDiscretizationDataView_Click(object sender, EventArgs e) { if ((datasetTempTA.CountRows() as int?) == 0) { DataTable newDataSet = datasetTA.GetData(); DiabetesDataSet.DataSetTempDataTable dataSetTempDataTable = new DiabetesDataSet.DataSetTempDataTable(); foreach (DataRow dtRow in newDataSet.Rows) { var row = dataSetTempDataTable.NewDataSetTempRow(); row["MaBn"] = Convert.ToDecimal(dtRow["MaBn"]); decimal TuoiHienTai = DateTime.Now.Year - Convert.ToDecimal(dtRow["NamSinh"]); row["Tuoi"] = DiscretizationData.RoiRacHoaTuoi(TuoiHienTai); row["GioiTinh"] = dtRow["GioiTinh"].ToString(); row["Cholesterol"] = dtRow["Cholesterol"].ToString(); row["HDL_Cholesterol"] = dtRow["HDL_Cholesterol"].ToString(); row["Triglyceride"] = dtRow["Triglyceride"].ToString(); row["LDL_Cholesterol"] = dtRow["LDL_Cholesterol"].ToString(); row["Glucose"] = dtRow["Glucose"].ToString(); row["SGOT"] = dtRow["SGOT"].ToString(); row["SGPT"] = dtRow["SGPT"].ToString(); row["Urea"] = dtRow["Urea"].ToString(); row["WBC"] = dtRow["WBC"].ToString(); row["LYM"] = dtRow["LYM"].ToString(); row["MONO"] = dtRow["MONO"].ToString(); row["GRAN"] = dtRow["GRAN"].ToString(); row["TyLeLYM"] = dtRow["TyLeLYM"].ToString(); row["TyLeMONO"] = dtRow["TyLeMONO"].ToString(); row["TyLeGRAN"] = dtRow["TyLeGRAN"].ToString(); row["HGB"] = dtRow["HGB"].ToString(); row["RBC"] = dtRow["RBC"].ToString(); row["HTC"] = dtRow["HTC"].ToString(); row["MCV"] = dtRow["MCV"].ToString(); row["MCH"] = dtRow["MCH"].ToString(); row["MCHC"] = dtRow["MCHC"].ToString(); row["RDW_CV"] = dtRow["RDW_CV"].ToString(); row["PLT"] = dtRow["PLT"].ToString(); row["MPV"] = dtRow["MPV"].ToString(); row["PDW"] = dtRow["PDW"].ToString(); row["PCT"] = dtRow["PCT"].ToString(); row["Na"] = dtRow["Na"].ToString(); row["K"] = dtRow["K"].ToString(); row["Cl"] = dtRow["Cl"].ToString(); row["Ca"] = dtRow["Ca"].ToString(); row["TieuDuong"] = dtRow["TieuDuong"].ToString(); dataSetTempDataTable.AddDataSetTempRow(row); //InsertDataSetTempRow(dtRow); } datasetTempTA.Update(dataSetTempDataTable); } dtDataSetTempForPreProcessing = newDataSetTempTA.GetData(); this.bindingSourcePreprocessingData.DataSource = null; this.bindingSourcePreprocessingData.DataSource = dtDataSetTempForPreProcessing; this.dataGridViewXDescriptiveData.DataSource = null; if (checkedListBoxColumnName.Items.Count > 0) { checkedListBoxColumnName.Items.Clear(); } for (int i = 3; i < dtDataSetTempForPreProcessing.Columns.Count - 1; i++) { String colName = dtDataSetTempForPreProcessing.Columns[i].ColumnName; checkedListBoxColumnName.Items.Add(colName, false); } buttonXImportDataSet.Enabled = false; buttonXDataCleanning.Enabled = false; comboBoxExDataCleanning.Enabled = false;; buttonXDiscretizationDataStatistics.Enabled = true; buttonXDataDiscretizationRun.Enabled = true; integerInputIntervalDiscretization.Enabled = true; checkBoxXDiscreteAllColumn.Enabled = true; checkedListBoxColumnName.Enabled = true; buttonXCustomDataDiscretization.Enabled = true; }
private void buttonXDiscretizationData_Click(object sender, EventArgs e) { ListBox listBoxSelectedField = new ListBox(); dtDataSetForPreProcessing = datasetTA.GetData(); int InputInterval = 0; //Biến dùng để chứa khoảng rời rạc mà người dùng nhập vào int Count = 0; //Biến dùng để kiếm tra xem người dùng có phải chỉ chọn 2 Field Tuoi & GioiTinh hay không int dataSetColIndex = 0; //Biến dùng để lưu lại index của Field cần rời rạc if (checkedListBoxColumnName.CheckedItems.Count == 0) { MessageBox.Show("Chưa chọn thuộc tính để thực hiện rời rạc", "Thông báo" , MessageBoxButtons.OK, MessageBoxIcon.Error); } else { for (int i = 0; i < checkedListBoxColumnName.CheckedItems.Count; i++) { String checkedValue = checkedListBoxColumnName.CheckedItems[i].ToString(); if (checkedValue != "Tuoi" && checkedValue != "GioiTinh") { listBoxSelectedField.Items.Add(checkedValue); } else { Count++; } } if (Count == checkedListBoxColumnName.CheckedItems.Count) { MessageBox.Show("Thuộc tính Tuoi và GioiTinh không cần thực hiện rời rạc", "Thông báo" , MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DiabetesDataSet.DataSetTempDataTable dataSetTempDataTable = datasetTempTA.GetData(); InputInterval = integerInputIntervalDiscretization.Value; for (int i = 0; i < listBoxSelectedField.Items.Count; i++) { String colName = listBoxSelectedField.Items[i].ToString(); dataSetColIndex = dtDataSetForPreProcessing.Columns.IndexOf(colName); bayesObjectTA.DeleteByOne(colName); int rowIndex = 0; foreach (DataRow dtRow in dtDataSetForPreProcessing.Rows) { decimal currentValue = Convert.ToDecimal(dtRow[dataSetColIndex]); String discreteValue = DiscretizationData.DataDiscretization(currentValue, colName, InputInterval, dtDataSetForPreProcessing); //String discreteValue = DiscretizationData.DataDiscretization(currentValue, colName, InputInterval); //decimal id = Convert.ToDecimal(dtRow[0]); //decimal maBN = Convert.ToDecimal(dtRow[1]); //String tieuDuong = dtRow[36].ToString(); //DiscretizationData.CapNhapDataSetTemp(datasetTempTA, maBN, colName, discreteValue); dataSetTempDataTable[rowIndex][colName] = discreteValue; rowIndex++; } DiscretizationData.TaoBayesObject(colName, InputInterval, dtDataSetForPreProcessing); } datasetTempTA.Update(dataSetTempDataTable); } dtDataSetTempForPreProcessing.Clear(); dtDataSetTempForPreProcessing = newDataSetTempTA.GetData(); this.bindingSourcePreprocessingData.DataSource = this.dtDataSetTempForPreProcessing; this.codification = null; } }
//Hàm dùng để rời rác hóa dataset trước khi thực hiện chẩn đoán public DataTable DataDiscretization(DataTable dt) { DiabetesDataSetB.TrainningDataTable trainningDataTable = new DiabetesDataSetB.TrainningDataTable(); trainningDataTable.Columns.Add("MaBn", typeof(decimal)); trainningDataTable.Columns["MaBn"].SetOrdinal(0); DataTable dtBayesObject = bayesObjectTA.GetData(); try { foreach (DataRow dtRow in dt.Rows) { DataRow newRow = trainningDataTable.NewRow(); foreach (DataColumn dtCol in dt.Columns) { String colName = dtCol.ColumnName; switch (colName) { case "ID": case "NgayKham": case "HoTen": case "GRAN": case "TyLeGRAN": case "Na": case "K": case "Cl": case "Ca": break; case "MaBn": newRow[colName] = dtRow[colName]; break; case "TieuDuong": newRow[colName] = Convert.ToBoolean(dtRow[colName]); break; case "GioiTinh": newRow[colName] = dtRow[colName].ToString(); break; case "NamSinh": int namSinh = Convert.ToInt16(dtRow[colName]); int tuoiHienTai = DateTime.Now.Year - namSinh; String Tuoi = DiscretizationData.RoiRacHoaTuoi(tuoiHienTai); newRow["Tuoi"] = Tuoi; break; default: decimal colValue = Convert.ToDecimal(dtRow[colName]); String giaTriRoiRac = DiscretizationData.DataDiscretizationForDiagnosis(colValue, colName); newRow[colName] = giaTriRoiRac; break; } } trainningDataTable.Rows.Add(newRow); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } return(trainningDataTable); }