本文整理汇总了Java中weka.core.OptionHandler类的典型用法代码示例。如果您正苦于以下问题:Java OptionHandler类的具体用法?Java OptionHandler怎么用?Java OptionHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OptionHandler类属于weka.core包,在下文中一共展示了OptionHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: predictInstanceDistribution
import weka.core.OptionHandler; //导入依赖的package包/类
public double[] predictInstanceDistribution(Reader reader) throws Exception {
// assume that the file contains only 1 instance
// load instances
Instances data = new Instances(reader);
// remove reportID attribute
String[] options = weka.core.Utils.splitOptions("-R 1"); // removes the first attribute in instances (should be the document id?)
String filterName = "weka.filters.unsupervised.attribute.Remove";
Filter filter = (Filter) Class.forName(filterName).newInstance();
if (filter instanceof OptionHandler) {
((OptionHandler) filter).setOptions(options);
}
filter.setInputFormat(data);
// make the instances
Instances unlabeled = Filter.useFilter(data, filter);
double[][] dist = this.predictDataDistribution(unlabeled);
return dist[0];
}
示例2: trainModelFromFile
import weka.core.OptionHandler; //导入依赖的package包/类
public void trainModelFromFile(String fnTrainData) throws Exception {
// load instances
Instances data = new Instances(new BufferedReader(new FileReader(fnTrainData)));
// preprocess instances
String[] options = weka.core.Utils.splitOptions("-R 1");
String filterName = "weka.filters.unsupervised.attribute.Remove";
Filter filter = (Filter) Class.forName(filterName).newInstance();
if (filter instanceof OptionHandler) {
((OptionHandler) filter).setOptions(options);
}
filter.setInputFormat(data);
// make the instances
Instances unlabeled = Filter.useFilter(data, filter);
// train model
this.trainModel(unlabeled);
}
示例3: loadClassifierAndSetJobName
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Loads the user-supplied model and sets the job name based on the classifier
* and its options.
*
* @param is InputStream to read the model from
* @throws IOException if a problem occurs
*/
protected void loadClassifierAndSetJobName(InputStream is) throws IOException {
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new BufferedInputStream(is));
Object model = ois.readObject();
String className = model.getClass().toString();
String options = "";
if (model instanceof OptionHandler) {
options = " " + Utils.joinOptions(((OptionHandler) model).getOptions());
}
setJobName("Scoring job: " + className + options);
} catch (Exception ex) {
throw new IOException(ex);
} finally {
if (ois != null) {
ois.close();
}
}
}
示例4: getOptions
import weka.core.OptionHandler; //导入依赖的package包/类
@Override
public String[] getOptions() {
Vector<String> result = new Vector<String>();
result.add("-dest"); //$NON-NLS-1$
result.add(getHDFSPath());
if (!DistributedJobConfig.isEmpty(getDFSReplicationFactor())) {
result.add("-dfs-replication"); //$NON-NLS-1$
result.add(getDFSReplicationFactor());
}
result.add("-saver"); //$NON-NLS-1$
String saverSpec = m_delegate.getClass().getName();
if (m_delegate != null) {
saverSpec += " " //$NON-NLS-1$
+ Utils.joinOptions(((OptionHandler) m_delegate).getOptions());
}
result.add(saverSpec);
for (String s : m_config.getOptions()) {
result.add(s);
}
return result.toArray(new String[result.size()]);
}
示例5: getOptions
import weka.core.OptionHandler; //导入依赖的package包/类
@Override
public String[] getOptions() {
Vector<String> result = new Vector<String>();
result.add("-source");
result.add(getHDFSPath());
result.add("-loader");
String loaderSpec = m_delegate.getClass().getName();
if (m_delegate instanceof OptionHandler) {
loaderSpec += " "
+ Utils.joinOptions(((OptionHandler) m_delegate).getOptions());
}
result.add(loaderSpec);
for (String s : m_config.getOptions()) {
result.add(s);
}
return result.toArray(new String[result.size()]);
}
示例6: setOptions
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Set the options for this filter
*
* @param options the options
* @throws Exception if a problem occurs
*/
public void setOptions(String[] options) throws Exception {
String filterSpec = Utils.getOption("filter", options);
if (!DistributedJobConfig.isEmpty(filterSpec)) {
String[] spec = Utils.splitOptions(filterSpec);
String filterClass = spec[0];
spec[0] = "";
Filter base = (Filter) Class.forName(filterClass).newInstance();
if (base instanceof OptionHandler) {
((OptionHandler) base).setOptions(spec);
}
setBaseFilter(base);
}
}
示例7: setOptions
import weka.core.OptionHandler; //导入依赖的package包/类
@Override
public void setOptions(String[] options) throws Exception {
setDontReplaceMissingValues(Utils.getFlag("dont-replace-missing", options));
m_filtersToUse = new ArrayList<Filter>();
while (true) {
String filterString = Utils.getOption("filter", options);
if (DistributedJobConfig.isEmpty(filterString)) {
break;
}
String[] spec = Utils.splitOptions(filterString);
if (spec.length == 0) {
throw new IllegalArgumentException(
"Invalid filter specification string");
}
String filterClass = spec[0];
Filter f = (Filter) Class.forName(filterClass).newInstance();
spec[0] = "";
if (f instanceof OptionHandler) {
((OptionHandler) f).setOptions(spec);
}
m_filtersToUse.add(f);
}
}
示例8: getOptions
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Gets the current settings of the clusterer.
*
* @return an array of strings suitable for passing to setOptions()
*/
@Override
public String[] getOptions() {
Vector<String> options = new Vector<String>();
options.add("-M");
options.add("" + getMinStdDev());
if (getClusterer() != null) {
options.add("-W");
options.add(getClusterer().getClass().getName());
if (m_wrappedClusterer instanceof OptionHandler) {
String[] clustererOptions = ((OptionHandler) m_wrappedClusterer)
.getOptions();
if (clustererOptions.length > 0) {
options.add("--");
Collections.addAll(options, clustererOptions);
}
}
}
Collections.addAll(options, super.getOptions());
return options.toArray(new String[0]);
}
示例9: listOptions
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Returns an enumeration describing the available options.
*
* @return an enumeration of all the available options.
*/
@Override
public Enumeration<Option> listOptions() {
Vector<Option> result = new Vector<Option>();
result.addElement(new Option("\tFull name of base clusterer.\n"
+ "\t(default: " + defaultClustererString() + ")", "W", 1, "-W"));
result.addAll(Collections.list(super.listOptions()));
if (m_Clusterer instanceof OptionHandler) {
result.addElement(new Option("", "", 0,
"\nOptions specific to clusterer " + m_Clusterer.getClass().getName()
+ ":"));
result.addAll(Collections.list(((OptionHandler) m_Clusterer)
.listOptions()));
}
return result.elements();
}
示例10: getOptions
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Gets the current settings of the clusterer.
*
* @return an array of strings suitable for passing to setOptions
*/
@Override
public String[] getOptions() {
Vector<String> result = new Vector<String>();
result.add("-W");
result.add(getClusterer().getClass().getName());
Collections.addAll(result, super.getOptions());
if (getClusterer() instanceof OptionHandler) {
String[] options = ((OptionHandler) getClusterer()).getOptions();
if (options.length > 0) {
result.add("--");
}
Collections.addAll(result, options);
}
return result.toArray(new String[result.size()]);
}
示例11: getOptions
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Gets the current settings of the CheckClusterer.
*
* @return an array of strings suitable for passing to setOptions
*/
@Override
public String[] getOptions() {
Vector<String> result = new Vector<String>();
if (getClusterer() != null) {
result.add("-W");
result.add(getClusterer().getClass().getName());
}
Collections.addAll(result, super.getOptions());
if ((m_Clusterer != null) && (m_Clusterer instanceof OptionHandler)) {
String[] options = ((OptionHandler) m_Clusterer).getOptions();
if (options.length > 0) {
result.add("--");
Collections.addAll(result, options);
}
}
return result.toArray(new String[result.size()]);
}
示例12: canTakeOptions
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Checks whether the scheme can take command line options.
*
* @return index 0 is true if the clusterer can take options
*/
protected boolean[] canTakeOptions() {
boolean[] result = new boolean[2];
print("options...");
if (m_Clusterer instanceof OptionHandler) {
println("yes");
if (m_Debug) {
println("\n=== Full report ===");
Enumeration<Option> enu = ((OptionHandler) m_Clusterer).listOptions();
while (enu.hasMoreElements()) {
Option option = enu.nextElement();
print(option.synopsis() + "\n" + option.description() + "\n");
}
println("\n");
}
result[0] = true;
} else {
println("no");
result[0] = false;
}
return result;
}
示例13: getOptions
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Gets the current settings of the CheckAssociator.
*
* @return an array of strings suitable for passing to setOptions
*/
@Override
public String[] getOptions() {
Vector<String> result = new Vector<String>();
Collections.addAll(result, super.getOptions());
if (getAssociator() != null) {
result.add("-W");
result.add(getAssociator().getClass().getName());
}
if ((m_Associator != null) && (m_Associator instanceof OptionHandler)) {
String[] options = ((OptionHandler) m_Associator).getOptions();
if (options.length > 0) {
result.add("--");
Collections.addAll(result, options);
}
}
return result.toArray(new String[result.size()]);
}
示例14: canTakeOptions
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Checks whether the scheme can take command line options.
*
* @return index 0 is true if the associator can take options
*/
protected boolean[] canTakeOptions() {
boolean[] result = new boolean[2];
print("options...");
if (m_Associator instanceof OptionHandler) {
println("yes");
if (m_Debug) {
println("\n=== Full report ===");
Enumeration<Option> enu = ((OptionHandler) m_Associator).listOptions();
while (enu.hasMoreElements()) {
Option option = enu.nextElement();
print(option.synopsis() + "\n" + option.description() + "\n");
}
println("\n");
}
result[0] = true;
} else {
println("no");
result[0] = false;
}
return result;
}
示例15: listOptions
import weka.core.OptionHandler; //导入依赖的package包/类
/**
* Returns an enumeration describing the available options.
*
* @return an enumeration of all the available options.
*/
@Override
public Enumeration<Option> listOptions() {
Vector<Option> result = new Vector<Option>();
result.addElement(new Option("\tFull name of base associator.\n"
+ "\t(default: " + defaultAssociatorString() + ")", "W", 1, "-W"));
if (m_Associator instanceof OptionHandler) {
result.addElement(new Option("", "", 0,
"\nOptions specific to associator " + m_Associator.getClass().getName()
+ ":"));
result.addAll(Collections.list(((OptionHandler) m_Associator)
.listOptions()));
}
return result.elements();
}