public int ClassifyInstance(double[] attributes, out double[] percentages)
            {
                double classificationResult = 1.0;

                testInstance.setDataset(dataSet);
                testInstance.setClassMissing();
                dataSet.add(testInstance);
                for (int i = 0; i < attributes.Length; i++)
                {
                    testInstance.setValue(i, attributes[i]);
                }
                classificationResult = m_cl.classifyInstance(testInstance);
                dataSet.delete(0);
                percentages = m_cl.distributionForInstance(testInstance);
                return((int)classificationResult);
            }
Esempio n. 2
0
        /// <summary>
        /// Uses the classifier to classify an instance (from its featureValues).
        /// </summary>
        /// <param name="featureValues">An array of doubles that describe the instance.</param>
        /// <returns>The string name of the classification of the instance.</returns>
        public string classify(double[] featureValues)
        {
            //if (!classifierBuilt) { _classifier.buildClassifier(_dataSet); classifierBuilt = true; }

            weka.core.Instance inst = new weka.core.Instance(1, featureValues);
            inst.setDataset(_dataSet);

            double result = _classifier.classifyInstance(inst);

            weka.core.Attribute attribute = _dataSet.attribute(_dataSet.numAttributes() - 1);
            string resultName             = attribute.value((int)result);

            // Get rid of this line once ARFF files are rewritten
            if (resultName == "Label")
            {
                resultName = "Text";
            }

            //Console.WriteLine(resultName);
            return(resultName);
        }
Esempio n. 3
0
        private void testButton_Click(object sender, EventArgs e)
        {
            var form = Form.ActiveForm as Form1;

            if (readyToTest)
            {
                weka.classifiers.Classifier cl   = classifiers[highestSuccessRate.Key];
                weka.core.Instance          inst = new weka.core.Instance(insts.numAttributes() - 1);
                inst.setDataset(insts);
                for (int i = 0; i < inputObjects.Count; i++)
                {
                    if (inputObjects[i].numeric)
                    {
                        inst.setValue(i, Decimal.ToDouble(inputObjects[i].num.Value));
                    }
                    else
                    {
                        inst.setValue(i, inputObjects[i].nom.SelectedItem.ToString());
                    }
                }


                try
                {
                    string[] values      = insts.attribute(insts.numAttributes() - 1).toString().Split('{', '}')[1].Split(',');
                    double   classOfData = cl.classifyInstance(inst);
                    int      idx         = Convert.ToInt32(classOfData);
                    form.testResult.Text = values[idx];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Program is not ready to test, probably needs to process data first.", "Not ready", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 public double[] ClassifyNewData(double[] newData)
 {
     weka.core.Instance newInstance = new weka.core.Instance(1, newData);
     newInstance.setDataset(playerData);
     return(classifier.distributionForInstance(newInstance));
 }
        public weka.core.Instance GenerateFeatures(PokerHand hand, int rIdx, int aIdx, weka.core.Instances data, bool generateClass = true)
        {
            // Check that we are using limit betting.
            Debug.Assert(hand.Context.BettingType == BettingType.FixedLimit);

            var results = new weka.core.Instance(data.numAttributes());
            results.setDataset(data);
            int attIdx = 0;
            foreach (var method in typeof(LimitFeatureGenerator).GetMethods())
            {
                // Get all the features of this class.
                var attributes = method.GetCustomAttributes(typeof(Feature), true);
                if (attributes.Length == 0)
                    continue;

                // Get the feature attribute on this method.
                var attr = ((Feature)attributes[0]);

                // Get the name for this attribute
                string name = attr.Name;
                //Console.WriteLine("Hand: {0} Feature: {1}", hand.Context.ID, name);

                // Get the feature only if it's applicable to this situation.
                object feature = null;
                if(rIdx >= (int)attr.MinRound && rIdx <= (int)attr.MaxRound)
                    feature = method.Invoke(this, new object[] { hand, rIdx, aIdx });

                if (SkipMissingFeatures && (feature == null || feature.ToString() == "?"))
                    continue;

                switch (attr.FType) {
                case FeatureType.Continuous:
                    results.setValue(attIdx, (double)feature);
                    break;
                case FeatureType.Discrete:
                    results.setValue(attIdx, (int)feature);
                    break;
                case FeatureType.Boolean:
                case FeatureType.Nominal:
                case FeatureType.Enum:
                {
                    var attribute = data.attribute(attIdx);
                    var attVal = attribute.indexOfValue(feature.ToString());
                    if(attVal < 0 || attVal > attribute.numValues())
                        throw new Exception(string.Format ("Invalid attribute value: {0} for attribute {1} (idx: {2} total values: {3}", feature.ToString(), name, attVal, attribute.numValues()));
                    results.setValue(attribute, attVal);
                }
                    break;
                case FeatureType.String:
                {
                    var attribute = data.attribute(attIdx);
                    results.setValue(attribute, feature.ToString());
                }
                    break;
                default: throw new Exception("Unspecified feature type for feature: " + method.Name);
                }

                attIdx++;
            }

            if(generateClass)
            {
                var classAttr = data.classAttribute();
                switch (hand.Rounds[rIdx].Actions[aIdx].Type)
                {
                case ActionType.Bet:
                case ActionType.Raise: results.setClassValue(classAttr.indexOfValue("Raise"));
                    break;
                case ActionType.Call:
                case ActionType.Check: results.setClassValue(classAttr.indexOfValue("Call"));
                    break;
                case ActionType.Fold: results.setClassValue(classAttr.indexOfValue("Fold"));;
                    break;
                default:
                    break;
                }
            }

            return results;
        }
Esempio n. 6
0
        public override double classifyInstance(Instance instance)
        {
            if (m_mustValue.HasValue)
                return m_mustValue.Value;

            instance.setDataset(m_sampleInstances);
            instance.setClassValue(0);
            m_sampleInstances.clear();
            m_sampleInstances.add(instance);

            double[] d = classifyInstances(m_sampleInstances);
            return d[0];
        }
Esempio n. 7
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));
            }
        }
 public double[] ClassifyNewData(double[] newData)
 {
     weka.core.Instance newInstance = new weka.core.Instance(1,newData);
     newInstance.setDataset(playerData);
     return classifier.distributionForInstance(newInstance);
 }