示例#1
0
        private Attribute BuildAttributeOfTypeImpl(EAttributeType atttype, PropertyInfo prop, string name)
        {
            Attribute att;

            if (atttype == EAttributeType.Nominal)
            {
                att = GetNominalAttribute(prop);
            }
            else if (atttype == EAttributeType.Numeric)
            {
                att = new Attribute(name);
            }
            else if (atttype == EAttributeType.Binary)
            {
                att = new Attribute(name, binary);
            }
            else if (atttype == EAttributeType.String)
            {
                att = new Attribute(name, (ArrayList)null);
            }
            else if (atttype == EAttributeType.Date)
            {
                att = new Attribute(name, ISO_8601_DATE_FORMAT); // ISO-8601 Format
            }
            else
            {
                throw new NotSupportedException(atttype + " is not a supported attribute atttype.");
            }
            return(att);
        }
示例#2
0
        public void test_attribute_to_enumerable_gives_nothing_on_numerics()
        {
            Runtime rt = TestingHelpers.LoadSmallRuntime <TitanicDataRow2>("titanic_train.csv", 0, 10);

            weka.core.Attribute age = rt.Impl.attribute(4);
            System.Collections.Generic.IEnumerable <string> values = age.ToEnumerable();
            Assert.AreEqual(new string[0], values);
        }
示例#3
0
        public void test_attribute_to_enumerable_gives_all_distinct_nominal_vals()
        {
            Runtime rt = TestingHelpers.LoadSmallRuntime <TitanicDataRow>("titanic_train.csv", 0, 10);

            weka.core.Attribute pcclass = rt.Impl.attribute(1);
            System.Collections.Generic.IEnumerable <string> values = pcclass.ToEnumerable();
            Assert.AreEqual(new[] { "1", "2", "3" }, values);
        }
        public void TestCreationOfEnums()
        {
            // Arrange
            var values = new weka.core.FastVector();
            values.addElement("beech");
            values.addElement("oak");
            values.addElement("ash");

            var attribute = new weka.core.Attribute("trees", values);
            var repo = new EnumRepository();

            // Act
            var enumValue = repo.GetEnumValue(attribute, 0);

            // Assert
            var fields = enumValue.GetType().GetFields();
            Assert.AreEqual(3, fields.Length);
            Assert.AreEqual("beech", fields[0].Name);
        }
示例#5
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);
        }
            public int InitializeClassifier(string[] atributes, string[] gestures, string classAttribute, string modelLocation)
            {
                java.io.ObjectInputStream ois = new java.io.ObjectInputStream(new java.io.FileInputStream(modelLocation));


                m_cl = (weka.classifiers.Classifier)ois.readObject();

                //Declare the feature vector
                weka.core.FastVector fvWekaFeatureVector = new weka.core.FastVector(atributes.Length + 1);
                for (int i = 0; i < atributes.Length; i++)
                {
                    weka.core.Attribute aux = new weka.core.Attribute(atributes[i]);
                    fvWekaFeatureVector.addElement(aux);
                }


                //Declare the class weka.core.Attribute along with its values
                weka.core.FastVector fvClassValues = new weka.core.FastVector(gestures.Length);
                for (int i = 0; i < gestures.Length; i++)
                {
                    weka.core.Attribute z1 = new weka.core.Attribute(atributes[i]);
                    fvClassValues.addElement(gestures[i]);
                }
                //fvClassValues.addElement("yes");
                //fvClassValues.addElement("no");

                weka.core.Attribute ClassAttribute = new weka.core.Attribute(classAttribute, fvClassValues);

                fvWekaFeatureVector.addElement(ClassAttribute);

                dataSet = new weka.core.Instances("TestRel", fvWekaFeatureVector, 10);
                dataSet.setClassIndex(atributes.Length);

                testInstance = new weka.core.Instance(atributes.Length + 1);

                return(1);
            }