本文整理汇总了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;
//.........这里部分代码省略.........