public void ClassificationMetric_On_Strings()
        {
            var targets     = new string[] { "Quality1", "Quality2", "Quality2", "Quality2", "Quality3", "Quality1", "Quality1", "Quality2", "Quality3" };
            var predictions = new string[] { "Quality1", "Quality2", "Quality2", "Quality2", "Quality1", "Quality2", "Quality2", "Quality1", "Quality3" };

            var metric = new TotalErrorClassificationMetric <string>();

            Trace.WriteLine(metric.ErrorString(targets, predictions));
        }
        public void ClassificationMetric_ErrorString()
        {
            var targets     = new double[] { 1, 2, 2, 2, 3, 1, 1, 2, 3 };
            var predictions = new double[] { 1, 2, 2, 2, 1, 2, 2, 1, 3 };

            var metric = new TotalErrorClassificationMetric <double>();

            Trace.WriteLine(metric.ErrorString(targets, predictions));
        }
        public void TotalErrorClassificationMetric_ErrorString()
        {
            var predictions = new double[] { 0, 1, 1, 2, 3, 4, 4 };
            var targets     = new double[] { 0, 1, 1, 2, 2, 3, 4 };

            var sut    = new TotalErrorClassificationMetric <double>();
            var actual = sut.ErrorString(targets, predictions);

            var expected = ";0;1;2;3;4;0;1;2;3;4\r\n0;1.000;0.000;0.000;0.000;0.000;100.000;0.000;0.000;0.000;0.000\r\n1;0.000;2.000;0.000;0.000;0.000;0.000;100.000;0.000;0.000;0.000\r\n2;0.000;0.000;1.000;1.000;0.000;0.000;0.000;50.000;50.000;0.000\r\n3;0.000;0.000;0.000;0.000;1.000;0.000;0.000;0.000;0.000;100.000\r\n4;0.000;0.000;0.000;0.000;1.000;0.000;0.000;0.000;0.000;100.000\r\nError: 28.571\r\n";;

            Assert.AreEqual(expected, actual);
        }
        public void ClassificationMetric_ErrorString_Translate_Target_Values_To_Names()
        {
            var targets     = new double[] { 1, 2, 2, 2, 3, 1, 1, 2, 3 };
            var predictions = new double[] { 1, 2, 2, 2, 1, 2, 2, 1, 3 };

            var translation = new Dictionary <double, string> {
                { 1.0, "Quality1" }, { 2.0, "Quality2" }, { 3.0, "Quality3" }
            };
            var metric = new TotalErrorClassificationMetric <double>();

            Trace.WriteLine(metric.ErrorString(targets, predictions, translation));
        }
        public void TotalErrorClassificationMetric_ErrorString_TargetStringMapping()
        {
            var predictions = new double[] { 0, 1, 1, 2, 3, 4, 4 };
            var targets     = new double[] { 0, 1, 1, 2, 2, 3, 4 };

            var sut = new TotalErrorClassificationMetric <double>();
            var targetStringMapping = new Dictionary <double, string> {
                { 0, "One" }, { 1, "Two" }, { 2, "Three" }, { 3, "Four" }, { 4, "Five" }
            };

            var actual   = sut.ErrorString(targets, predictions, targetStringMapping);
            var expected = ";One;Two;Three;Four;Five;One;Two;Three;Four;Five\r\nOne;1.000;0.000;0.000;0.000;0.000;100.000;0.000;0.000;0.000;0.000\r\nTwo;0.000;2.000;0.000;0.000;0.000;0.000;100.000;0.000;0.000;0.000\r\nThree;0.000;0.000;1.000;1.000;0.000;0.000;0.000;50.000;50.000;0.000\r\nFour;0.000;0.000;0.000;0.000;1.000;0.000;0.000;0.000;0.000;100.000\r\nFive;0.000;0.000;0.000;0.000;1.000;0.000;0.000;0.000;0.000;100.000\r\nError: 28.571\r\n";;

            Assert.AreEqual(expected, actual);
        }
Beispiel #6
0
        double ClassificationDecisionTreeLearner_Learn_Glass_Weighted(int treeDepth, double weight)
        {
            var(observations, targets) = DataSetUtilities.LoadGlassDataSet();

            var weights = targets.Select(v => Weight(v, 1, weight)).ToArray();
            var sut     = new ClassificationDecisionTreeLearner(treeDepth, 1, observations.ColumnCount, 0.001, 42);
            var model   = sut.Learn(observations, targets, weights);

            var predictions = model.Predict(observations);
            var evaluator   = new TotalErrorClassificationMetric <double>();

            Trace.WriteLine(evaluator.ErrorString(targets, predictions));
            var error = evaluator.Error(targets, predictions);

            return(error);
        }
        double ClassificationDecisionTreeLearner_Learn_Glass_Weighted(int treeDepth, double weight)
        {
            var parser       = new CsvParser(() => new StringReader(Resources.Glass));
            var observations = parser.EnumerateRows(v => v != "Target").ToF64Matrix();
            var targets      = parser.EnumerateRows("Target").ToF64Vector();
            var rows         = targets.Length;

            var weights = targets.Select(v => Weight(v, 1, weight)).ToArray();
            var sut     = new ClassificationDecisionTreeLearner(treeDepth, 1, observations.ColumnCount, 0.001, 42);
            var model   = sut.Learn(observations, targets, weights);

            var predictions = model.Predict(observations);
            var evaluator   = new TotalErrorClassificationMetric <double>();

            Trace.WriteLine(evaluator.ErrorString(targets, predictions));
            var error = evaluator.Error(targets, predictions);

            return(error);
        }