[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<int> learningIndexes = new List<int>();
			List<int> testingIndexes = new List<int>();
			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<int> indexesList)
		{
			List<object[]> testingList = new List<object[]>();
			foreach (int index in indexesList)
			{
				testingList.Add(everything[index]);
			}
			return testingList.ToArray();
		}
        }
}
pl/miw/miw08_rbs_ml/nunittests.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0