Refine search
/** * Build the classifier * * @param data the training data to be used for generating the bagged * classifier. * @throws Exception if the classifier could not be built successfully */ @Override public void buildClassifier(Instances data) throws Exception { if (!m_initialTestStructureKnown) { m_inputHeader = new Instances(data, 0); } m_attributeMap = null; if (m_modelPath != null && m_modelPath.length() > 0) { return; // Don't build a classifier if a path has been specified } // can classifier handle the data? getCapabilities().testWithFail(data); m_Classifier.buildClassifier(data); // m_loadedClassifier = m_Classifier; m_modelHeader = new Instances(data, 0); }
/** * Build the classifier * * @param data the training data to be used for generating the bagged * classifier. * @throws Exception if the classifier could not be built successfully */ @Override public void buildClassifier(Instances data) throws Exception { if (!m_initialTestStructureKnown) { m_inputHeader = new Instances(data, 0); } m_attributeMap = null; if (m_modelPath != null && m_modelPath.length() > 0) { return; // Don't build a classifier if a path has been specified } // can classifier handle the data? getCapabilities().testWithFail(data); m_Classifier.buildClassifier(data); // m_loadedClassifier = m_Classifier; m_modelHeader = new Instances(data, 0); }
/** * Need to override this to deal with InputMappedClassifier case. * (If InputMappedClassifier is applied to test data that is different in some important aspects: we * need to test capabilities with respect to format of data used to train the classifier.) * * @param instanceInfo the data to test * @throws Exception if the test fails */ protected void testInputFormat(Instances instanceInfo) throws Exception { Classifier classifier = getActualClassifier(); if (classifier instanceof InputMappedClassifier) { Instances trainingData = ((InputMappedClassifier)classifier).getModelHeader(new Instances(instanceInfo, 0)); getCapabilities(trainingData).testWithFail(trainingData); } else { getCapabilities(instanceInfo).testWithFail(instanceInfo); } }
/** * Need to override this to deal with InputMappedClassifier case. * (If InputMappedClassifier is applied to test data that is different in some important aspects: we * need to test capabilities with respect to format of data used to train the classifier.) * * @param instanceInfo the data to test * @throws Exception if the test fails */ protected void testInputFormat(Instances instanceInfo) throws Exception { Classifier classifier = getActualClassifier(); if (classifier instanceof InputMappedClassifier) { Instances trainingData = ((InputMappedClassifier)classifier).getModelHeader(new Instances(instanceInfo, 0)); getCapabilities(trainingData).testWithFail(trainingData); } else { getCapabilities(instanceInfo).testWithFail(instanceInfo); } }
/** * Builds Id3 decision tree classifier. * * @param data the training data * @exception Exception if classifier can't be built successfully */ public void buildClassifier(Instances data) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(data); // remove instances with missing class data = new Instances(data); data.deleteWithMissingClass(); makeTree(data); }
/** * Generates the classifier. * * @param instances set of instances serving as training data * @throws Exception if the classifier has not been generated successfully */ public void buildClassifier(Instances instances) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(instances); // remove instances with missing class instances = new Instances(instances); instances.deleteWithMissingClass(); m_Train = new Instances(instances, 0, instances.numInstances()); // initializes class attributes ** java-speaking! :-) ** init_m_Attributes(); }
/** * Generates the classifier. * * @param instances set of instances serving as training data * @throws Exception if the classifier has not been generated successfully */ public void buildClassifier(Instances instances) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(instances); // remove instances with missing class instances = new Instances(instances); instances.deleteWithMissingClass(); m_Train = new Instances(instances, 0, instances.numInstances()); // initializes class attributes ** java-speaking! :-) ** init_m_Attributes(); }
/** * Sets up the classifier before any actual instances are processed. */ protected void initializeClassifier(Instances instances) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(instances); m_headerInfo = new Instances(instances, 0); m_numClasses = instances.numClasses(); m_numAttributes = instances.numAttributes(); m_probOfWordGivenClass = new double[m_numClasses][]; // Initialize the matrix of word counts for (int c = 0; c < m_numClasses; c++) { m_probOfWordGivenClass[c] = new double[m_numAttributes]; for (int att = 0; att < m_numAttributes; att++) { m_probOfWordGivenClass[c][att] = 1.0; } } // Initialize class counts m_probOfClass = new double[m_numClasses]; for (int i = 0; i < m_numClasses; i++) { m_probOfClass[i] = 1.0; } }
/** * Sets up the classifier before any actual instances are processed. */ protected void initializeClassifier(Instances instances) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(instances); m_headerInfo = new Instances(instances, 0); m_numClasses = instances.numClasses(); m_numAttributes = instances.numAttributes(); m_probOfWordGivenClass = new double[m_numClasses][]; // Initialize the matrix of word counts for (int c = 0; c < m_numClasses; c++) { m_probOfWordGivenClass[c] = new double[m_numAttributes]; for (int att = 0; att < m_numAttributes; att++) { m_probOfWordGivenClass[c][att] = 1.0; } } // Initialize class counts m_probOfClass = new double[m_numClasses]; for (int i = 0; i < m_numClasses; i++) { m_probOfClass[i] = 1.0; } }
/** * Buildclassifier selects a classifier from the set of classifiers by * minimising error on the training data. * * @param data the training data to be used for generating the boosted * classifier. * @throws Exception if the classifier could not be built successfully */ @Override public void buildClassifier(Instances data) throws Exception { // remove instances with missing class Instances newData = new Instances(data); newData.deleteWithMissingClass(); m_structure = new Instances(newData, 0); if (m_classifiersToLoad.size() > 0) { m_preBuiltClassifiers.clear(); loadClassifiers(data); if (m_Classifiers.length == 1 && m_Classifiers[0] instanceof weka.classifiers.rules.ZeroR) { // remove the single ZeroR m_Classifiers = new Classifier[0]; } } // can classifier handle the data? getCapabilities().testWithFail(data); for (int i = 0; i < m_Classifiers.length; i++) { getClassifier(i).buildClassifier(newData); } }
/** * Buildclassifier selects a classifier from the set of classifiers by * minimising error on the training data. * * @param data the training data to be used for generating the boosted * classifier. * @throws Exception if the classifier could not be built successfully */ @Override public void buildClassifier(Instances data) throws Exception { // remove instances with missing class Instances newData = new Instances(data); newData.deleteWithMissingClass(); m_structure = new Instances(newData, 0); if (m_classifiersToLoad.size() > 0) { m_preBuiltClassifiers.clear(); loadClassifiers(data); if (m_Classifiers.length == 1 && m_Classifiers[0] instanceof weka.classifiers.rules.ZeroR) { // remove the single ZeroR m_Classifiers = new Classifier[0]; } } // can classifier handle the data? getCapabilities().testWithFail(data); for (int i = 0; i < m_Classifiers.length; i++) { getClassifier(i).buildClassifier(newData); } }
/** * Builds the classifier * * @param train the training data to be used for generating the boosted * classifier. * @throws Exception if the classifier could not be built successfully */ @Override public void buildClassifier(Instances train) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(train); // remove instances with missing class train = new Instances(train); train.deleteWithMissingClass(); if (m_Classifier == null) { throw new Exception("A base classifier has not been specified!"); } if (getDebug()) { System.out.println("Start training ..."); } Instances data = transform(train); data.deleteAttributeAt(0); // delete the bagID attribute m_Classifier.buildClassifier(data); if (getDebug()) { System.out.println("Finish building model"); } }
/** * Generates the classifier. * * @param instances set of instances serving as training data * @throws Exception if the classifier has not been generated successfully */ public void buildClassifier(Instances instances) throws Exception { // can classifier handle the data? getCapabilities().testWithFail(instances); // remove instances with missing class instances = new Instances(instances); instances.deleteWithMissingClass(); m_Train = new Instances(instances, 0, instances.numInstances()); m_MinArray = new double [m_Train.numAttributes()]; m_MaxArray = new double [m_Train.numAttributes()]; for (int i = 0; i < m_Train.numAttributes(); i++) { m_MinArray[i] = m_MaxArray[i] = Double.NaN; } Enumeration enu = m_Train.enumerateInstances(); while (enu.hasMoreElements()) { updateMinMax((Instance) enu.nextElement()); } }
getCapabilities().testWithFail(instances); instances = new Instances(instances); instances.deleteWithMissingClass(); m_Train = new Instances(instances, 0, instances.numInstances());
getCapabilities().testWithFail(instances); instances = new Instances(instances); instances.deleteWithMissingClass(); m_Train = new Instances(instances, 0, instances.numInstances());
getCapabilities().testWithFail(data); m_data = new Instances(data); super.buildClassifier(m_data);
getCapabilities().testWithFail(data); Instances newData = new Instances(data); m_BaseFormat = new Instances(data, 0); newData.deleteWithMissingClass();
getCapabilities().testWithFail(data); m_data = new Instances(data, 0); data = new Instances(data);
/** * Generates a classifier. * * @param data set of instances serving as training data * @throws Exception if the classifier has not been * generated successfully */ public void buildClassifier(Instances data) throws Exception { this.instanceConverter = new WekaToSamoaInstanceConverter(); getCapabilities().testWithFail(data); data = new Instances(data); data.deleteWithMissingClass(); m_ActualClassifier.resetLearning(); for (int i = 0; i < data.numInstances(); i++) updateClassifier(data.instance(i)); }
/** * Builds the classifier. * * @param data the data to train with * @throws Exception if classifier can't be built successfully */ @Override public void buildClassifier(Instances data) throws Exception { reset(); m_header = new Instances(data, 0); if (m_selectedSplitMetric == GINI_SPLIT) { m_splitMetric = new GiniSplitMetric(); } else { m_splitMetric = new InfoGainSplitMetric(m_minFracWeightForTwoBranchesGain); } data = new Instances(data); data.deleteWithMissingClass(); for (int i = 0; i < data.numInstances(); i++) { updateClassifier(data.instance(i)); } // can classifier handle the data? getCapabilities().testWithFail(data); }