Example #1
0
        private List <Patient.Classification> WekaClassify()
        {
            //getting index of selected input patient
            int     inputId         = Convert.ToInt32(txtNum.Text);
            int     inputIndex      = inputList.FindIndex(x => x.ID == inputId);
            Patient selectedPatient = inputList[inputIndex];

            Patient.Classification j48Classification  = Patient.Classification.Unknown;
            Patient.Classification nngeClassification = Patient.Classification.Unknown;

            //iterating through models
            for (int modeli = 0; modeli < wekaModels.Count; modeli++)
            {
                //iterating through model rules
                for (int rulei = 0; rulei < wekaModels[modeli].Rules.Count; rulei++)
                {
                    bool match = false;
                    //iterating through ruleitems
                    for (int ruleItemi = 0; ruleItemi < wekaModels[modeli].Rules[rulei].RuleItems.Count; ruleItemi++)
                    {
                        RuleItem                  ruleItem       = wekaModels[modeli].Rules[rulei].RuleItems[ruleItemi];
                        int                       attributeIndex = patientFeatures.IndexOf(ruleItem.Feature) - 1;
                        double                    patientValue   = selectedPatient.GetSingleAttribute(attributeIndex);
                        List <double>             ruleVals       = ruleItem.GetValues();
                        List <RuleItem.Operators> ruleOps        = ruleItem.GetOps();

                        for (int i = 0; i < ruleVals.Count; i++)
                        {
                            if (ruleOps[i] == RuleItem.Operators.Equal)
                            {
                                if (patientValue == ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else if (ruleOps[i] == RuleItem.Operators.Less)
                            {
                                if (patientValue < ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else if (ruleOps[i] == RuleItem.Operators.Greater)
                            {
                                if (patientValue > ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else if (ruleOps[i] == RuleItem.Operators.LessOrEqual)
                            {
                                if (patientValue <= ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else if (ruleOps[i] == RuleItem.Operators.GreatorOrEqual)
                            {
                                if (patientValue >= ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                        }
                        if (!match)
                        {
                            break;
                        }
                    }
                    if (match)
                    {
                        if (modeli == 0)
                        {
                            j48Classification = wekaModels[modeli].Rules[rulei].Classification;
                        }
                        else
                        {
                            nngeClassification = wekaModels[modeli].Rules[rulei].Classification;
                        }
                        break;
                    }
                }
            }
            return(new List <Patient.Classification> {
                j48Classification, nngeClassification
            });
        }
        private List <Patient.Classification> WekaClassify()
        {
            //getting index of selected input patient
            int     inputId         = Convert.ToInt32(txtNum.Text);
            int     inputIndex      = inputList.FindIndex(x => x.ID == inputId);
            Patient selectedPatient = inputList[inputIndex];
            List <Patient.Classification> j48Classification  = new List <Patient.Classification>();
            List <Patient.Classification> nngeClassification = new List <Patient.Classification>();

            j48ClassifiedRule.Clear();
            nngeClassifiedRule.Clear();
            double j48Accuracy = 0;

            //iterating through models
            for (int modeli = 0; modeli < wekaModels.Count; modeli++)
            {
                if (modeli == 0)
                {
                    inputList[inputIndex].J48ModelAccuracy = wekaModels[modeli].Accuracy;
                }
                else
                {
                    inputList[inputIndex].NNgeAccuracy = wekaModels[modeli].Accuracy;
                }

                //iterating through model rules
                for (int rulei = 0; rulei < wekaModels[modeli].Rules.Count; rulei++)
                {
                    bool match = false;
                    //iterating through ruleitems
                    for (int ruleItemi = 0; ruleItemi < wekaModels[modeli].Rules[rulei].RuleItems.Count; ruleItemi++)
                    {
                        RuleItem                  ruleItem       = wekaModels[modeli].Rules[rulei].RuleItems[ruleItemi];
                        int                       attributeIndex = patientFeatures.IndexOf(ruleItem.Feature) - 1;
                        double                    patientValue   = selectedPatient.GetSingleAttribute(attributeIndex);
                        List <double>             ruleVals       = ruleItem.GetValues();
                        List <RuleItem.Operators> ruleOps        = ruleItem.GetOps();

                        for (int i = 0; i < ruleVals.Count; i++)
                        {
                            if (ruleOps[i] == RuleItem.Operators.Equal)
                            {
                                if (patientValue == ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else if (ruleOps[i] == RuleItem.Operators.Less)
                            {
                                if (patientValue < ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else if (ruleOps[i] == RuleItem.Operators.Greater)
                            {
                                if (patientValue > ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else if (ruleOps[i] == RuleItem.Operators.LessOrEqual)
                            {
                                if (patientValue <= ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                            else if (ruleOps[i] == RuleItem.Operators.GreatorOrEqual)
                            {
                                if (patientValue >= ruleVals[i])
                                {
                                    match = true;
                                }
                                else
                                {
                                    match = false;
                                    break;
                                }
                            }
                        }
                        if (!match)
                        {
                            break;
                        }
                    }
                    if (match)
                    {
                        if (modeli == 0)
                        {
                            j48Accuracy = wekaModels[modeli].Rules[rulei].Accuracy;
                            inputList[inputIndex].J48RuleAccuracy = j48Accuracy;
                            j48Classification.Add(wekaModels[modeli].Rules[rulei].Classification);
                            j48ClassifiedRule.Add(rulei);
                        }
                        else
                        {
                            nngeClassification.Add(wekaModels[modeli].Rules[rulei].Classification);
                            nngeClassifiedRule.Add(rulei);
                        }
                    }
                }
            }
            if (j48Classification.Count > 0)
            {
                inputList[inputIndex].J48Diagnosis = MostFrequentClass(j48Classification);
            }
            else
            {
                inputList[inputIndex].J48Diagnosis = Patient.Classification.Unknown;
            }
            if (nngeClassification.Count > 0)
            {
                inputList[inputIndex].NngeDiagnosis = MostFrequentClass(nngeClassification);
            }
            else
            {
                inputList[inputIndex].NngeDiagnosis = Patient.Classification.Unknown;
            }

            return(new List <Patient.Classification> {
                inputList[inputIndex].J48Diagnosis, inputList[inputIndex].NngeDiagnosis
            });
        }