Example #1
0
		/// <summary> Creates a cost matrix that is a copy of another.
		/// 
		/// </summary>
		/// <param name="toCopy">the matrix to copy.
		/// </param>
		public CostMatrix(CostMatrix toCopy):base(toCopy.size(), toCopy.size())
		{
			
			for (int x = 0; x < toCopy.size(); x++)
				for (int y = 0; y < toCopy.size(); y++)
					setXmlElement(x, y, toCopy.getXmlElement(x, y));
		}
Example #2
0
		/// <summary> Initializes all the counters for the evaluation and also takes a
		/// cost matrix as parameter.
		/// Use <code>useNoPriors()</code> if the dataset is the test set and you
		/// can't initialize with the priors from the training set via 
		/// <code>setPriors(Instances)</code>.
		/// 
		/// </summary>
		/// <param name="data">	set of training instances, to get some header 
		/// information and prior class distribution information
		/// </param>
		/// <param name="costMatrix">	the cost matrix---if null, default costs will be used
		/// </param>
		/// <throws>  Exception 	if cost matrix is not compatible with  </throws>
		/// <summary> 			data, the class is not defined or the class is numeric
		/// </summary>
		/// <seealso cref="useNoPriors()">
		/// </seealso>
		/// <seealso cref="setPriors(Instances)">
		/// </seealso>
		public Evaluation(Instances data, CostMatrix costMatrix)
		{
			
			m_NumClasses = data.numClasses();
			m_NumFolds = 1;
			m_ClassIsNominal = data.classAttribute().Nominal;
			
			if (m_ClassIsNominal)
			{
				double[][] tmpArray = new double[m_NumClasses][];
				for (int i = 0; i < m_NumClasses; i++)
				{
					tmpArray[i] = new double[m_NumClasses];
				}
				m_ConfusionMatrix = tmpArray;
				m_ClassNames = new System.String[m_NumClasses];
				for (int i = 0; i < m_NumClasses; i++)
				{
					m_ClassNames[i] = data.classAttribute().value_Renamed(i);
				}
			}
			m_CostMatrix = costMatrix;
			if (m_CostMatrix != null)
			{
				if (!m_ClassIsNominal)
				{
					throw new System.Exception("Class has to be nominal if cost matrix " + "given!");
				}
				if (m_CostMatrix.size() != m_NumClasses)
				{
					throw new System.Exception("Cost matrix not compatible with data!");
				}
			}
			m_ClassPriors = new double[m_NumClasses];
			Priors = data;
			m_MarginCounts = new double[k_MarginResolution + 1];
		}