コード例 #1
0
        // 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;
        }
コード例 #2
0
        //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);
        }