Ejemplo n.º 1
0
        public void LoadModelFromFile()
        {
            string pathFull = System.IO.Path.Combine(Util.GetProjectDir2(), _fileModelIris);
            var    xgbc     = XGBoost.XGBClassifier.LoadClassifierFromFile(pathFull);
            ///
            /// Load testingvectors
            ///
            int    noOfClasses  = 3;
            string filenameTest = "Iris\\Iris.test.data";

            iris.Iris[] recordsTest = IrisUtils.LoadIris(filenameTest);
            entity.XGVector <iris.Iris>[] vectorsTest = IrisUtils.ConvertFromIrisToFeatureVectors(recordsTest);
            entity.XGBArray arrTest     = Util.ConvertToXGBArray(vectorsTest);
            var             outcomeTest = xgbc.Predict(arrTest.Vectors);

            for (int index = 0; index < arrTest.Vectors.Length; index++)
            {
                string  sExpected  = IrisUtils.ConvertLabelFromNumericToString(arrTest.Labels[index]);
                float[] arrResults = new float[]
                {
                    outcomeTest[index * noOfClasses + 0],
                    outcomeTest[index * noOfClasses + 1],
                    outcomeTest[index * noOfClasses + 2]
                };
                float  max = arrResults.Max();
                int    indexWithMaxValue = Util.GetIndexWithMaxValue(arrResults);
                string sActualClass      = IrisUtils.ConvertLabelFromNumericToString((float)indexWithMaxValue);
                Trace.WriteLine($"{index}       Expected={sExpected}        Actual={sActualClass}");
                Assert.AreEqual(sActualClass, sExpected);
            }
        }
Ejemplo n.º 2
0
        public void BasicLoadData()
        {
            string filename = "Iris\\Iris.train.data";

            iris.Iris[] records = IrisUtils.LoadIris(filename);
            entity.XGVector <iris.Iris>[] vectors = IrisUtils.ConvertFromIrisToFeatureVectors(records);
            Assert.IsTrue(records.Length >= 140);
        }