本文整理汇总了Java中weka.classifiers.rules.ZeroR类的典型用法代码示例。如果您正苦于以下问题:Java ZeroR类的具体用法?Java ZeroR怎么用?Java ZeroR使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZeroR类属于weka.classifiers.rules包,在下文中一共展示了ZeroR类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resetOptions
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
protected void resetOptions() {
m_trainInstances = null;
m_Evaluation = null;
m_BaseClassifier = new ZeroR();
m_folds = 5;
m_seed = 1;
m_threshold = 0.01;
}
示例2: buildClassifier
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
/**
* 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_NumClasses = instances.numClasses();
m_ClassType = instances.classAttribute().type();
m_Train = new Instances(instances, 0, instances.numInstances());
// Throw away initial instances until within the specified window size
if ((m_WindowSize > 0) && (instances.numInstances() > m_WindowSize)) {
m_Train = new Instances(m_Train,
m_Train.numInstances()-m_WindowSize,
m_WindowSize);
}
m_NumAttributesUsed = 0.0;
for (int i = 0; i < m_Train.numAttributes(); i++) {
if ((i != m_Train.classIndex()) &&
(m_Train.attribute(i).isNominal() ||
m_Train.attribute(i).isNumeric())) {
m_NumAttributesUsed += 1.0;
}
}
m_NNSearch.setInstances(m_Train);
// Invalidate any currently cross-validation selected k
m_kNNValid = false;
m_defaultModel = new ZeroR();
m_defaultModel.buildClassifier(instances);
}
示例3: resetOptions
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
protected void resetOptions () {
m_trainInstances = null;
m_Evaluation = null;
m_BaseClassifier = new ZeroR();
m_folds = 5;
m_seed = 1;
m_threshold = 0.01;
}
示例4: getFilteredClassifier
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
/**
* returns the configured FilteredClassifier. Since the base classifier is
* determined heuristically, derived tests might need to adjust it.
*
* @return the configured FilteredClassifier
*/
protected FilteredClassifier getFilteredClassifier() {
FilteredClassifier result;
result = super.getFilteredClassifier();
((NominalToString) result.getFilter()).setAttributeIndexes("1");
result.setClassifier(new ZeroR());
return result;
}
示例5: resetOptions
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
/**
* reset to defaults
*/
protected void resetOptions () {
m_trainingInstances = null;
m_Evaluation = null;
m_Classifier = new ZeroR();
m_holdOutFile = new File("Click to set hold out or test instances");
m_holdOutInstances = null;
m_useTraining = false;
}
示例6: buildClassifier
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
/**
* Builds the classifiers.
*
* @param insts the training data.
* @throws Exception if a classifier can't be built
*/
public void buildClassifier(Instances insts) throws Exception {
Instances newInsts;
// can classifier handle the data?
getCapabilities().testWithFail(insts);
// remove instances with missing class
insts = new Instances(insts);
insts.deleteWithMissingClass();
if (m_Classifier == null) {
throw new Exception("No base classifier has been set!");
}
m_ZeroR = new ZeroR();
m_ZeroR.buildClassifier(insts);
int numClassifiers = insts.numClasses() - 1;
numClassifiers = (numClassifiers == 0) ? 1 : numClassifiers;
if (numClassifiers == 1) {
m_Classifiers = Classifier.makeCopies(m_Classifier, 1);
m_Classifiers[0].buildClassifier(insts);
} else {
m_Classifiers = Classifier.makeCopies(m_Classifier, numClassifiers);
m_ClassFilters = new MakeIndicator[numClassifiers];
for (int i = 0; i < m_Classifiers.length; i++) {
m_ClassFilters[i] = new MakeIndicator();
m_ClassFilters[i].setAttributeIndex("" + (insts.classIndex() + 1));
m_ClassFilters[i].setValueIndices(""+(i+2)+"-last");
m_ClassFilters[i].setNumeric(false);
m_ClassFilters[i].setInputFormat(insts);
newInsts = Filter.useFilter(insts, m_ClassFilters[i]);
m_Classifiers[i].buildClassifier(newInsts);
}
}
}
示例7: initializeClassifier
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
/**
* Initialize classifier.
*
* @param data the training data
* @throws Exception if the classifier could not be initialized successfully
*/
public void initializeClassifier(Instances data) throws Exception {
// can classifier handle the data?
getCapabilities().testWithFail(data);
// remove instances with missing class
m_Data = new Instances(data);
m_Data.deleteWithMissingClass();
// Add the model for the mean first
m_zeroR = new ZeroR();
m_zeroR.buildClassifier(m_Data);
// only class? -> use only ZeroR model
if (m_Data.numAttributes() == 1) {
System.err.println(
"Cannot build model (only class attribute present in data!), "
+ "using ZeroR model instead!");
m_SuitableData = false;
return;
}
else {
m_SuitableData = true;
}
// Initialize list of classifiers and data
m_Classifiers = new ArrayList<Classifier>(m_NumIterations);
m_Data = residualReplace(m_Data, m_zeroR, false);
// Calculate sum of squared errors
m_SSE = 0;
m_Diff = Double.MAX_VALUE;
for (int i = 0; i < m_Data.numInstances(); i++) {
m_SSE += m_Data.instance(i).weight() *
m_Data.instance(i).classValue() * m_Data.instance(i).classValue();
}
if (m_Debug) {
System.err.println("Sum of squared residuals "
+"(predicting the mean) : " + m_SSE);
}
}
示例8: buildClassifier
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
/**
* Build the classifier on the supplied data
*
* @param data the training data
* @throws Exception if the classifier could not be built successfully
*/
public void buildClassifier(Instances data) throws Exception {
super.buildClassifier(data);
// can classifier handle the data?
getCapabilities().testWithFail(data);
// remove instances with missing class
Instances newData = new Instances(data);
newData.deleteWithMissingClass();
double sum = 0;
double temp_sum = 0;
// Add the model for the mean first
m_zeroR = new ZeroR();
m_zeroR.buildClassifier(newData);
// only class? -> use only ZeroR model
if (newData.numAttributes() == 1) {
System.err.println(
"Cannot build model (only class attribute present in data!), "
+ "using ZeroR model instead!");
m_SuitableData = false;
return;
}
else {
m_SuitableData = true;
}
newData = residualReplace(newData, m_zeroR, false);
for (int i = 0; i < newData.numInstances(); i++) {
sum += newData.instance(i).weight() *
newData.instance(i).classValue() * newData.instance(i).classValue();
}
if (m_Debug) {
System.err.println("Sum of squared residuals "
+"(predicting the mean) : " + sum);
}
m_NumIterationsPerformed = 0;
do {
temp_sum = sum;
// Build the classifier
m_Classifiers[m_NumIterationsPerformed].buildClassifier(newData);
newData = residualReplace(newData, m_Classifiers[m_NumIterationsPerformed], true);
sum = 0;
for (int i = 0; i < newData.numInstances(); i++) {
sum += newData.instance(i).weight() *
newData.instance(i).classValue() * newData.instance(i).classValue();
}
if (m_Debug) {
System.err.println("Sum of squared residuals : "+sum);
}
m_NumIterationsPerformed++;
} while (((temp_sum - sum) > Utils.SMALL) &&
(m_NumIterationsPerformed < m_Classifiers.length));
}
示例9: main
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
public static void main(String[] argv)
{
runClassifier(new ZeroR(), argv);
}
示例10: setOptions
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
/**
* Parses a given list of options. <p/>
*
<!-- options-start -->
* Valid options are: <p/>
*
* <pre> -B <classifier>
* class name of the classifier to use for accuracy estimation.
* Place any classifier options LAST on the command line
* following a "--". eg.:
* -B weka.classifiers.bayes.NaiveBayes ... -- -K
* (default: weka.classifiers.rules.ZeroR)</pre>
*
* <pre> -T
* Use the training data to estimate accuracy.</pre>
*
* <pre> -H <filename>
* Name of the hold out/test set to
* estimate accuracy on.</pre>
*
* <pre>
* Options specific to scheme weka.classifiers.rules.ZeroR:
* </pre>
*
* <pre> -D
* If set, classifier is run in debug mode and
* may output additional info to the console</pre>
*
<!-- options-end -->
*
* @param options the list of options as an array of strings
* @throws Exception if an option is not supported
*/
public void setOptions (String[] options)
throws Exception {
String optionString;
resetOptions();
optionString = Utils.getOption('B', options);
if (optionString.length() == 0)
optionString = ZeroR.class.getName();
setClassifier(Classifier.forName(optionString,
Utils.partitionOptions(options)));
optionString = Utils.getOption('H',options);
if (optionString.length() != 0) {
setHoldOutFile(new File(optionString));
}
setUseTraining(Utils.getFlag('T',options));
}
示例11: setOptions
import weka.classifiers.rules.ZeroR; //导入依赖的package包/类
/**
* Parses a given list of options. <p/>
*
<!-- options-start -->
* Valid options are: <p/>
*
* <pre> -B <base learner>
* class name of base learner to use for accuracy estimation.
* Place any classifier options LAST on the command line
* following a "--". eg.:
* -B weka.classifiers.bayes.NaiveBayes ... -- -K
* (default: weka.classifiers.rules.ZeroR)</pre>
*
* <pre> -F <num>
* number of cross validation folds to use for estimating accuracy.
* (default=5)</pre>
*
* <pre> -R <seed>
* Seed for cross validation accuracy testimation.
* (default = 1)</pre>
*
* <pre> -T <num>
* threshold by which to execute another cross validation
* (standard deviation---expressed as a percentage of the mean).
* (default: 0.01 (1%))</pre>
*
* <pre>
* Options specific to scheme weka.classifiers.rules.ZeroR:
* </pre>
*
* <pre> -D
* If set, classifier is run in debug mode and
* may output additional info to the console</pre>
*
<!-- options-end -->
*
* @param options the list of options as an array of strings
* @throws Exception if an option is not supported
*/
public void setOptions (String[] options)
throws Exception {
String optionString;
resetOptions();
optionString = Utils.getOption('B', options);
if (optionString.length() == 0)
optionString = ZeroR.class.getName();
setClassifier(Classifier.forName(optionString,
Utils.partitionOptions(options)));
optionString = Utils.getOption('F', options);
if (optionString.length() != 0) {
setFolds(Integer.parseInt(optionString));
}
optionString = Utils.getOption('R', options);
if (optionString.length() != 0) {
setSeed(Integer.parseInt(optionString));
}
// optionString = Utils.getOption('S',options);
// if (optionString.length() != 0)
// {
// seed = Integer.parseInt(optionString);
// }
optionString = Utils.getOption('T', options);
if (optionString.length() != 0) {
Double temp;
temp = Double.valueOf(optionString);
setThreshold(temp.doubleValue());
}
}