private void button1_Click(object sender, EventArgs e)
        {
            weka.core.Instances insts = new weka.core.Instances(new java.io.FileReader(file));
            double[]            Data  = new double[insts.numAttributes()];
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].GetType() == typeof(TextBox))
                {
                    TextBox txt   = (TextBox)list[i];
                    string  value = txt.Text.Replace('.', ',');
                    Data[i] = Convert.ToDouble(value);
                }
                else
                {
                    ComboBox combobox = (ComboBox)list[i];
                    Data[i] = Convert.ToDouble(combobox.SelectedIndex);
                }
            }
            // Data[(insts.numAttributes() - 1] = 0;
            insts.setClassIndex(insts.numAttributes() - 1);
            Instance newInsts = new Instance(1.0, Data);

            insts.add(newInsts);
            string type = model.GetType().ToString();

            if (type == "weka.classifiers.bayes.NaiveBayes")
            {
                weka.filters.Filter myDiscretize = new weka.filters.unsupervised.attribute.Discretize();
                myDiscretize.setInputFormat(insts);
                insts = weka.filters.Filter.useFilter(insts, myDiscretize);
            }
            else if (type == "weka.classifiers.lazy.IBk")
            {
                weka.filters.Filter myDummy = new weka.filters.unsupervised.attribute.NominalToBinary();
                myDummy.setInputFormat(insts);
                insts = weka.filters.Filter.useFilter(insts, myDummy);

                weka.filters.Filter myNormalize = new weka.filters.unsupervised.instance.Normalize();
                myNormalize.setInputFormat(insts);
                insts = weka.filters.Filter.useFilter(insts, myNormalize);
            }
            double index = model.classifyInstance(insts.lastInstance());

            string result = insts.attribute(insts.numAttributes() - 1).value(Convert.ToInt16(index));

            MessageBox.Show(result);
        }
Esempio n. 2
0
        private void btnDiscover_Click(object sender, EventArgs e)
        {
            string type  = model.GetType().ToString();
            bool   flag  = false;
            bool   flag2 = false;

            //input kontrolleri
            if (nominal != null)
            {
                for (int i = 0; i < nominal.Length; i++)
                {
                    if (nominal[i].SelectedIndex == -1)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (numeric != null)
            {
                for (int i = 0; i < numeric.Length; i++)
                {
                    if (String.IsNullOrEmpty(numeric[i].Text))
                    {
                        flag2 = true;
                        break;
                    }
                }
            }
            if (numAtt == numeric.Length && flag2 == true)
            {
                MessageBox.Show("Please select value!", "Error Message!");
            }
            else if (numAtt == nominal.Length && flag == true)
            {
                MessageBox.Show("Please select value!", "Error Message!");
            }
            else if ((nominal.Length + numeric.Length) == numAtt && (flag == true || flag2 == true))
            {
                MessageBox.Show("Please select value!", "Error Message!");
            }
            else
            {
                weka.core.Instance newIns = new weka.core.Instance(numAtt + 1);
                newIns.setDataset(insts);

                int i1 = 0, i2 = 0;
                for (int i = 0; i < numAtt; i++)
                {
                    //nominal
                    if (typeAtt[i])
                    {
                        newIns.setValue(i, nominal[i1].SelectedItem.ToString());
                        i1++;
                    }
                    //numeric
                    else
                    {
                        newIns.setValue(i, double.Parse(numeric[i2].Text));
                        i2++;
                    }
                }

                weka.core.Instances insts2 = new weka.core.Instances(insts);
                insts2.add(newIns);

                if (type == "weka.classifiers.bayes.NaiveBayes")
                {
                    weka.filters.Filter myDiscretize = new weka.filters.unsupervised.attribute.Discretize();
                    myDiscretize.setInputFormat(insts2);
                    insts2 = weka.filters.Filter.useFilter(insts2, myDiscretize);
                }

                else if (type == "weka.classifiers.functions.Logistic")
                {
                    weka.filters.Filter myDummy = new weka.filters.unsupervised.attribute.NominalToBinary();
                    myDummy.setInputFormat(insts2);
                    insts2 = weka.filters.Filter.useFilter(insts2, myDummy);

                    weka.filters.Filter myNormalize = new weka.filters.unsupervised.instance.Normalize();
                    myNormalize.setInputFormat(insts2);
                    insts2 = weka.filters.Filter.useFilter(insts2, myNormalize);
                }

                else if (type == "new weka.classifiers.lazy.IBk")
                {
                    weka.filters.Filter myDummy = new weka.filters.unsupervised.attribute.NominalToBinary();
                    myDummy.setInputFormat(insts2);
                    insts2 = weka.filters.Filter.useFilter(insts2, myDummy);

                    weka.filters.Filter myNormalize = new weka.filters.unsupervised.instance.Normalize();
                    myNormalize.setInputFormat(insts2);
                    insts2 = weka.filters.Filter.useFilter(insts2, myNormalize);
                }
                else if (type == "weka.classifiers.trees.J48")
                {
                }
                else if (type == "weka.classifiers.trees.RandomForest")
                {
                }
                else if (type == "weka.classifiers.trees.RandomTree")
                {
                }
                else if (type == "weka.classifiers.functions.MultilayerPerceptron")
                {
                    weka.filters.Filter myDummy = new weka.filters.unsupervised.attribute.NominalToBinary();
                    myDummy.setInputFormat(insts2);
                    insts2 = weka.filters.Filter.useFilter(insts2, myDummy);

                    weka.filters.Filter myNormalize = new weka.filters.unsupervised.instance.Normalize();
                    myNormalize.setInputFormat(insts2);
                    insts2 = weka.filters.Filter.useFilter(insts2, myNormalize);
                }
                else if (type == "weka.classifiers.functions.SMO")
                {
                    weka.filters.Filter myDummy = new weka.filters.unsupervised.attribute.NominalToBinary();
                    myDummy.setInputFormat(insts2);
                    insts2 = weka.filters.Filter.useFilter(insts2, myDummy);

                    weka.filters.Filter myNormalize = new weka.filters.unsupervised.instance.Normalize();
                    myNormalize.setInputFormat(insts2);
                    insts2 = weka.filters.Filter.useFilter(insts2, myNormalize);
                }

                double index = model.classifyInstance(insts2.lastInstance());
                //Model okuma kısmı
                weka.classifiers.Classifier cls = (weka.classifiers.Classifier)weka.core.SerializationHelper.read("models/mdl.model");
                lblResult2.Text = "Result= " + insts2.attribute(insts2.numAttributes() - 1).value(Convert.ToInt16(index));
            }
        }