本文整理汇总了C#中Accord.MachineLearning.DecisionTrees.DecisionTree.Decide方法的典型用法代码示例。如果您正苦于以下问题:C# DecisionTree.Decide方法的具体用法?C# DecisionTree.Decide怎么用?C# DecisionTree.Decide使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Accord.MachineLearning.DecisionTrees.DecisionTree
的用法示例。
在下文中一共展示了DecisionTree.Decide方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: same_input_different_output_minimal
public void same_input_different_output_minimal()
{
double[][] inputs = new double[][] {
new double[] { 0 },
new double[] { 0 }
};
int[] outputs = new int[] {
1,
0
};
DecisionVariable[] variables = { new DecisionVariable("x", DecisionVariableKind.Continuous) };
DecisionTree decisionTree = new DecisionTree(variables, 2);
C45Learning c45Learning = new C45Learning(decisionTree);
c45Learning.Run(inputs, outputs); // System.AggregateException thrown here
Assert.AreEqual(decisionTree.Decide(new[] { 0 }), 0);
}
示例2: same_input_different_output
public void same_input_different_output()
{
double[][] inputs = new double[][] {
new double[] { 1 },
new double[] { 0 },
new double[] { 2 },
new double[] { 3 },
new double[] { 0 },
};
int[] outputs = new int[] {
11,
00,
22,
33,
01
};
DecisionVariable[] variables = { new DecisionVariable("x", DecisionVariableKind.Continuous) };
DecisionTree decisionTree = new DecisionTree(variables, 34);
C45Learning c45Learning = new C45Learning(decisionTree)
{
Join = 10,
MaxHeight = 10
};
c45Learning.Run(inputs, outputs); // System.AggregateException thrown here
int[] actual = decisionTree.Decide(inputs);
Assert.AreEqual(11, actual[0]);
Assert.AreEqual(00, actual[1]);
Assert.AreEqual(22, actual[2]);
Assert.AreEqual(33, actual[3]);
Assert.AreEqual(00, actual[4]);
}
示例3: IrisDatasetTest
public void IrisDatasetTest()
{
#region doc_iris
// In this example, we will process the famous Fisher's Iris dataset in
// which the task is to classify weather the features of an Iris flower
// belongs to an Iris setosa, an Iris versicolor, or an Iris virginica:
//
// - https://en.wikipedia.org/wiki/Iris_flower_data_set
//
// First, let's load the dataset into an array of text that we can process
string[][] text = Resources.iris_data.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Apply(x => x.Split(','));
// The first four columns contain the flower features
double[][] inputs = text.GetColumns(0, 1, 2, 3).To<double[][]>();
// The last column contains the expected flower type
string[] labels = text.GetColumn(4);
// Since the labels are represented as text, the first step is to convert
// those text labels into integer class labels, so we can process them
// more easily. For this, we will create a codebook to encode class labels:
//
var codebook = new Codification("Output", labels);
// With the codebook, we can convert the labels:
int[] outputs = codebook.Translate("Output", labels);
// Let's declare the names of our input variables:
DecisionVariable[] features =
{
new DecisionVariable("sepal length", DecisionVariableKind.Continuous),
new DecisionVariable("sepal width", DecisionVariableKind.Continuous),
new DecisionVariable("petal length", DecisionVariableKind.Continuous),
new DecisionVariable("petal width", DecisionVariableKind.Continuous),
};
// Now, we can finally create our tree for the 3 classes:
var tree = new DecisionTree(inputs: features, classes: 3);
// And we can use the C4.5 for learning:
var teacher = new C45Learning(tree);
// And finally induce the tree:
teacher.Learn(inputs, outputs);
// To get the estimated class labels, we can use
int[] predicted = tree.Decide(inputs);
// And the classification error can be computed as
double error = new ZeroOneLoss(outputs) // 0.0266
{
Mean = true
}.Loss(tree.Decide(inputs));
// Moreover, we may decide to convert our tree to a set of rules:
DecisionSet rules = tree.ToRules();
// And using the codebook, we can inspect the tree reasoning:
string ruleText = rules.ToString(codebook, "Output",
System.Globalization.CultureInfo.InvariantCulture);
// The output is:
string expected = @"Iris-setosa =: (petal length <= 2.45)
Iris-versicolor =: (petal length > 2.45) && (petal width <= 1.75) && (sepal length <= 7.05) && (sepal width <= 2.85)
Iris-versicolor =: (petal length > 2.45) && (petal width <= 1.75) && (sepal length <= 7.05) && (sepal width > 2.85)
Iris-versicolor =: (petal length > 2.45) && (petal width > 1.75) && (sepal length <= 5.95) && (sepal width > 3.05)
Iris-virginica =: (petal length > 2.45) && (petal width <= 1.75) && (sepal length > 7.05)
Iris-virginica =: (petal length > 2.45) && (petal width > 1.75) && (sepal length > 5.95)
Iris-virginica =: (petal length > 2.45) && (petal width > 1.75) && (sepal length <= 5.95) && (sepal width <= 3.05)
";
#endregion
Assert.AreEqual(0.026666666666666668, error, 1e-10);
Assert.AreEqual(4, tree.NumberOfInputs);
Assert.AreEqual(3, tree.NumberOfOutputs);
double newError = ComputeError(rules, inputs, outputs);
Assert.AreEqual(0.026666666666666668, newError, 1e-10);
Assert.AreEqual(expected, ruleText);
}