当前位置: 首页>>代码示例>>C#>>正文


C# KernelSupportVectorMachine.Decide方法代码示例

本文整理汇总了C#中Accord.MachineLearning.VectorMachines.KernelSupportVectorMachine.Decide方法的典型用法代码示例。如果您正苦于以下问题:C# KernelSupportVectorMachine.Decide方法的具体用法?C# KernelSupportVectorMachine.Decide怎么用?C# KernelSupportVectorMachine.Decide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Accord.MachineLearning.VectorMachines.KernelSupportVectorMachine的用法示例。


在下文中一共展示了KernelSupportVectorMachine.Decide方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: weight_test_homogeneous_linear_kernel

        public void weight_test_homogeneous_linear_kernel()
        {
            var dataset = yinyang;
            double[][] inputs = dataset.Submatrix(null, 0, 1).ToJagged();
            int[] labels = dataset.GetColumn(2).ToInt32();

            Accord.Math.Tools.SetupGenerator(0);

            var kernel = new Linear();
            Assert.AreEqual(kernel.Constant, 0);

            {
                var machine = new KernelSupportVectorMachine(kernel, inputs[0].Length);
                var smo = new SequentialMinimalOptimization(machine, inputs, labels);

                smo.Complexity = 1.0;
                smo.PositiveWeight = 1;
                smo.NegativeWeight = 1;
                smo.Tolerance = 0.001;

                double error = smo.Run();

                int[] actual = new int[labels.Length];
                for (int i = 0; i < actual.Length; i++)
                    actual[i] = machine.Decide(inputs[i]) ? 1 : 0;

                ConfusionMatrix matrix = new ConfusionMatrix(actual, labels);

                Assert.AreEqual(43, matrix.TruePositives); // both classes are
                Assert.AreEqual(43, matrix.TrueNegatives); // well equilibrated
                Assert.AreEqual(7, matrix.FalseNegatives);
                Assert.AreEqual(7, matrix.FalsePositives);

                Assert.AreEqual(1.0, smo.Complexity);
                Assert.AreEqual(1.0, smo.WeightRatio);
                Assert.AreEqual(1.0, smo.NegativeWeight);
                Assert.AreEqual(1.0, smo.PositiveWeight);
                Assert.AreEqual(0.14, error);
                Assert.AreEqual(0.001, smo.Tolerance);
                Assert.AreEqual(31, machine.SupportVectors.Length);

                machine.Compress();
                Assert.AreEqual(1, machine.Weights[0]);
                Assert.AreEqual(1, machine.SupportVectors.Length);
                Assert.AreEqual(-1.3107402300323954, machine.SupportVectors[0][0]);
                Assert.AreEqual(-0.5779471529948812, machine.SupportVectors[0][1]);
                Assert.AreEqual(-0.53366022455811646, machine.Threshold);
                for (int i = 0; i < actual.Length; i++)
                {
                    int expected = actual[i];
                    int y = machine.Decide(inputs[i]) ? 1 : 0;
                    Assert.AreEqual(expected, y);
                }
            }

            {
                var machine = new KernelSupportVectorMachine(kernel, inputs[0].Length);
                var smo = new SequentialMinimalOptimization(machine, inputs, labels);

                smo.Complexity = 1;
                smo.PositiveWeight = 100;
                smo.NegativeWeight = 1;
                smo.Tolerance = 0.001;

                double error = smo.Run();

                int[] actual = new int[labels.Length];
                for (int i = 0; i < actual.Length; i++)
                    actual[i] = machine.Decide(inputs[i]) ? 1 : 0;

                ConfusionMatrix matrix = new ConfusionMatrix(actual, labels);

                Assert.AreEqual(50, matrix.TruePositives); // has more importance
                Assert.AreEqual(23, matrix.TrueNegatives);
                Assert.AreEqual(0, matrix.FalseNegatives); // has more importance
                Assert.AreEqual(27, matrix.FalsePositives);

                Assert.AreEqual(1.0, smo.Complexity);
                Assert.AreEqual(100, smo.WeightRatio);
                Assert.AreEqual(1.0, smo.NegativeWeight);
                Assert.AreEqual(100, smo.PositiveWeight);
                Assert.AreEqual(0.001, smo.Tolerance);
                Assert.AreEqual(0.27, error);
                Assert.AreEqual(42, machine.SupportVectors.Length);
            }

            {
                var machine = new KernelSupportVectorMachine(kernel, inputs[0].Length);
                var smo = new SequentialMinimalOptimization(machine, inputs, labels);

                smo.Complexity = 1;
                smo.PositiveWeight = 1;
                smo.NegativeWeight = 100;
                smo.Tolerance = 0.001;

                double error = smo.Run();

                int[] actual = new int[labels.Length];
                for (int i = 0; i < actual.Length; i++)
                    actual[i] = machine.Decide(inputs[i]) ? 1 : 0;
//.........这里部分代码省略.........
开发者ID:accord-net,项目名称:framework,代码行数:101,代码来源:SequentialMinimalOptimizationTest.cs


注:本文中的Accord.MachineLearning.VectorMachines.KernelSupportVectorMachine.Decide方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。