示例#1
0
    static void Main(string[] args)
    {
        data = new List<Entry>();
        classNames = new List<String>();
        possibleValues = new List<String[]>();
        classNames.Add("Outlook");
        possibleValues.Add(new String[]{"Sunny" , "Overcast", "Rainy"});
        classNames.Add("Temperature");
        possibleValues.Add(new String[] { "cool", "mild", "hot" });
        classNames.Add("Humidity");
        possibleValues.Add(new String[] { "normal", "high" });

        classNames.Add("Windy");
        possibleValues.Add(new String[] { "false", "true" });
        String[] lines = System.IO.File.ReadAllLines(@"C:\Users\Grole\Desktop\iris\weather.txt");
        String[] w;
        foreach(String line in lines)
        {
            w = line.Split(',');
            if (w[4].Equals("yes"))
            {
                data.Add(new Entry(true, classNames, w));
            }
            else
            {
                data.Add(new Entry(false, classNames, w));
            }
        }
        bool[] free = { true, true, true, true };
        TreeNode t = new TreeNode(data, free);

        t.outputTree(0);
        foreach(Entry q in data)
        {
            Console.WriteLine(t.Predict(q));
        }
    }