public override void buildClassifier(Instances instances) { // can classifier handle the data? getCapabilities().testWithFail(instances); // remove instances with missing class instances = new Instances(instances); instances.deleteWithMissingClass(); double sum = 0; int cnt = 0; foreach (Instance instance in instances) { if (!instance.classIsMissing()) { sum += instance.value(idxAttribute); cnt++; } } mean = sum / cnt; sum = 0; foreach (Instance instance in instances) { if (!instance.classIsMissing()) { sum += (instance.value(idxAttribute) - mean) * (instance.value(idxAttribute) - mean); } } sigma2 = sum / cnt; epsilon = SelectBestEpsilon(instances, mean, sigma2); }
/// /// <summary> * Generates the classifier. /// * </summary> /// * <param name="instances"> set of instances serving as training data </param> /// * <exception cref="Exception"> if the classifier has not been generated successfully </exception> /// public override void buildClassifier(Instances instances) { // can classifier handle the data? getCapabilities().testWithFail(instances); // remove instances with missing class instances = new Instances(instances); instances.deleteWithMissingClass(); double sumOfWeights = 0; WekaUtils.DebugAssert(instances.numClasses() == 3, "instance's numClasses should be 3."); m_counts = new double[instances.numClasses()]; m_normalCounts = new double[instances.numClasses()]; for (int i = 0; i < m_counts.Length; i++) { m_counts[i] = 0; m_normalCounts[i] = 0; } double c = m_tp / m_sl; foreach (Instance instance in instances) { int v = (int)instance.classValue(); if (v == 2) { m_counts[v] += instance.weight() * c; sumOfWeights += instance.weight() * c; } else { m_counts[v] += instance.weight(); sumOfWeights += instance.weight(); } } double start = 0; for (int i = 0; i < m_counts.Length; ++i) { m_normalCounts[i] = (double)m_counts[i] / sumOfWeights + start; start = m_normalCounts[i]; } }
/// /// <summary> * Generates the classifier. /// * </summary> /// * <param name="instances"> set of instances serving as training data </param> /// * <exception cref="Exception"> if the classifier has not been generated successfully </exception> /// public override void buildClassifier(Instances instances) { // can classifier handle the data? getCapabilities().testWithFail(instances); // remove instances with missing class var trainInstances = new Instances(instances); trainInstances.deleteWithMissingClass(); WekaUtils.DebugAssert(instances.numClasses() == 3, "instance's numClasses should be 3."); m_counts = new double[instances.numClasses()]; for (int i = 0; i < m_counts.Length; i++) { m_counts[i] = 0; } //double c = m_tp / m_sl; foreach (Instance instance in instances) { int v = (int)instance.classValue(); m_counts[v] += 1; sumOfWeights += 1; } }