public static void Main(string[] args) { // Step 1: Data Console.WriteLine("Step 1: Data"); Tennis[] tennis = Tennis.GetData(); var descriptor = Descriptor.Create <Tennis>(); // Step 2: Maths Console.WriteLine("\nStep 2: Maths"); var data = descriptor.ToExamples(tennis); var x = data.Item1; var y = data.Item2; Console.WriteLine($"Mathematical feature representation:{x}"); Console.WriteLine($"\nMathematical label representation:{y.T}"); // Step 3: Generate Model Console.WriteLine("\nStep 3: Generate Model"); var generator = new DecisionTreeGenerator(); var model = generator.Generate <Tennis>(descriptor, tennis); Console.WriteLine(model); // Step 4: Prediction Console.WriteLine("\nStep 4: Prediction"); Tennis t = new Tennis { Outlook = Outlook.Sunny, Temperature = Temperature.Hot, Windy = false }; Tennis p = model.Predict(t); Console.WriteLine($"Play: {p.Play}"); // Step 5: Testing Accuracy Console.WriteLine("\nStep 5: Testing Accuracy"); ((DecisionTreeGenerator)generator).SetHint(0); var learned = Learner.Learn(tennis, 0.80, 100, generator); var m = learned.Model; double accuracy = learned.Accuracy; Console.WriteLine($"Learned {m.GetType().Name} model with {accuracy*100}% accuracy"); Console.WriteLine(m); Tennis h = new Tennis { Outlook = Outlook.Sunny, Temperature = Temperature.Hot, Windy = false }; Tennis o = m.Predict(h); Console.WriteLine($"Play: {o.Play}"); }
public static Tennis[] GetData() { return(new Tennis[] { Tennis.Make(Outlook.Sunny, Temperature.Hot, Humidity.High, false, false), Tennis.Make(Outlook.Sunny, Temperature.Hot, Humidity.High, true, false), Tennis.Make(Outlook.Overcast, Temperature.Hot, Humidity.High, false, true), Tennis.Make(Outlook.Rainy, Temperature.Mild, Humidity.High, false, true), Tennis.Make(Outlook.Rainy, Temperature.Cool, Humidity.Normal, false, true), Tennis.Make(Outlook.Rainy, Temperature.Cool, Humidity.Normal, true, false), Tennis.Make(Outlook.Overcast, Temperature.Cool, Humidity.Normal, true, true), Tennis.Make(Outlook.Sunny, Temperature.Mild, Humidity.High, false, false), Tennis.Make(Outlook.Sunny, Temperature.Cool, Humidity.Normal, false, true), Tennis.Make(Outlook.Rainy, Temperature.Mild, Humidity.Normal, false, true), Tennis.Make(Outlook.Sunny, Temperature.Mild, Humidity.Normal, true, true), Tennis.Make(Outlook.Overcast, Temperature.Mild, Humidity.High, true, true), Tennis.Make(Outlook.Overcast, Temperature.Hot, Humidity.Normal, false, true), Tennis.Make(Outlook.Rainy, Temperature.Mild, Humidity.High, true, false) }); }