Example #1
0
        private DataTable getDataTableForCodification()
        {
            int?maxRow = this.discreteIntervalTableAdapter.MaxRow();

            DiabetesDataSetB.TrainningDataTable dataTable = new DiabetesDataSetB.TrainningDataTable();

            DataRow   newRow;
            DataTable attributeInterval;
            int       indexLastColumn = dataTable.Columns.Count - 1;

            // Add max row
            for (int i = 0; i < maxRow; i++)
            {
                newRow = dataTable.NewRow();
                newRow[indexLastColumn] = TableMetaData.PositiveString;
                dataTable.Rows.Add(newRow);
            }

            // Add value for each column
            foreach (DataColumn column in dataTable.Columns)
            {
                attributeInterval = this.discreteIntervalTableAdapter.GetDataByTenThuocTinh(column.ColumnName);

                // Add value for each row
                for (int rowIndex = 0; rowIndex < dataTable.Rows.Count; rowIndex++)
                {
                    if (rowIndex < attributeInterval.Rows.Count)
                    {
                        dataTable.Rows[rowIndex][column] = attributeInterval.Rows[rowIndex][1].ToString();
                    }
                    else
                    {
                        if (!column.ColumnName.Equals(TableMetaData.ClassAttribute))
                        {
                            dataTable.Rows[rowIndex][column] = attributeInterval.Rows[0][1].ToString();
                        }
                    }
                }
            }
            dataTable.Rows[0][indexLastColumn] = TableMetaData.NegativeString;

            return(dataTable);
        }
Example #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);
        }
        //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;
        }
        private DataTable getDataTableForCodification()
        {            
            int? maxRow = this.discreteIntervalTableAdapter.MaxRow();

            DiabetesDataSetB.TrainningDataTable dataTable = new DiabetesDataSetB.TrainningDataTable();

            DataRow newRow;
            DataTable attributeInterval;
            int indexLastColumn = dataTable.Columns.Count - 1;

            // Add max row
            for (int i = 0; i < maxRow; i++)
            {
                newRow = dataTable.NewRow();
                newRow[indexLastColumn] = TableMetaData.PositiveString;
                dataTable.Rows.Add(newRow);
            }

            // Add value for each column
            foreach (DataColumn column in dataTable.Columns)
            {
                attributeInterval = this.discreteIntervalTableAdapter.GetDataByTenThuocTinh(column.ColumnName);

                // Add value for each row
                for (int rowIndex = 0; rowIndex < dataTable.Rows.Count; rowIndex++)
                {
                    
                    if (rowIndex < attributeInterval.Rows.Count)
                    {
                        dataTable.Rows[rowIndex][column] = attributeInterval.Rows[rowIndex][1].ToString();
                    }
                    else
                    {
                        if (!column.ColumnName.Equals(TableMetaData.ClassAttribute))
                        {                            
                            dataTable.Rows[rowIndex][column] = attributeInterval.Rows[0][1].ToString();
                        }
                    }                    
                }
            }
            dataTable.Rows[0][indexLastColumn] = TableMetaData.NegativeString;            

            return dataTable;
        }