[TestFixture]//telling NUnit that this class contains test functions using System; using System.Collections.Generic; using System.Text; using NUnit.Framework; using System.IO; using System.Xml.Serialization; namespace Morcinek.Machine_Learning { [TestFixture]//telling NUnit that this class contains test functions public class NUnitClass { private const string TESTS = "Tests.xml"; [Test] public void Thermostat_252_2016() { int randValue; object[][] everything; object[][] testing; object[][] learning; DecisionTree decisionTree; int goodClassified = 0; int learningLength = 126; everything = Common.BinaryDeSerialize("Thermostat_2016.bin"); string[] attributeNames = new string[] { "Day", "Hour", "Month" }; Random rand = new Random(); List learningIndexes = new List(); List testingIndexes = new List(); for (int i = 0; i < learningLength; i++) { randValue = rand.Next(2015); if (!learningIndexes.Contains(randValue)) learningIndexes.Add(randValue); else --i; } learningIndexes.Sort(); for (int i = 0; i < 2016; i++) { if (!learningIndexes.Contains(i)) testingIndexes.Add(i); } testing = IndexesToArray(everything, testingIndexes); learning = IndexesToArray(everything, learningIndexes); decisionTree = new DecisionTree(); decisionTree.Initialize(learning, attributeNames); foreach (object[] row in testing) { if (decisionTree.FindCategory(row) == (int)row[3]) goodClassified++; } StringBuilder sb = new StringBuilder(); sb.Append("Everything is "); sb.Append(goodClassified.ToString()); sb.Append("/"); sb.Append(testing.Length.ToString()); Console.Write(sb.ToString()); UpdateCorrect(goodClassified); // Funkcja zapisuje kolejne ilości dobrze sklasyfikowanych przykładów } private object[][] IndexesToArray(object[][] everything, List indexesList) { List testingList = new List(); foreach (int index in indexesList) { testingList.Add(everything[index]); } return testingList.ToArray(); } } }