本文整理汇总了Java中weka.classifiers.CostMatrix.FILE_EXTENSION属性的典型用法代码示例。如果您正苦于以下问题:Java CostMatrix.FILE_EXTENSION属性的具体用法?Java CostMatrix.FILE_EXTENSION怎么用?Java CostMatrix.FILE_EXTENSION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类weka.classifiers.CostMatrix
的用法示例。
在下文中一共展示了CostMatrix.FILE_EXTENSION属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: costMatrixSourceTipText
/**
* @return tip text for this property suitable for
* displaying in the explorer/experimenter gui
*/
public String costMatrixSourceTipText() {
return "Sets where to get the cost matrix. The two options are"
+ "to use the supplied explicit cost matrix (the setting of the "
+ "costMatrix property), or to load a cost matrix from a file when "
+ "required (this file will be loaded from the directory set by the "
+ "onDemandDirectory property and will be named relation_name"
+ CostMatrix.FILE_EXTENSION + ").";
}
示例2: saveMatrix
/**
* Prompts the user to save a matrix, and attemps to save it.
*
*/
private void saveMatrix() {
int returnVal = m_fileChooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File selectedFile = m_fileChooser.getSelectedFile();
// append extension if not already present
if (!selectedFile.getName().toLowerCase()
.endsWith(CostMatrix.FILE_EXTENSION)) {
selectedFile = new File(selectedFile.getParent(),
selectedFile.getName() + CostMatrix.FILE_EXTENSION);
}
Writer writer = null;
try {
writer = new BufferedWriter(new FileWriter(selectedFile));
m_matrix.write(writer);
writer.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Error writing file '"
+ selectedFile.getName() + "':\n" + ex.getMessage(), "Save failed",
JOptionPane.ERROR_MESSAGE);
System.out.println(ex.getMessage());
}
}
}
示例3: saveMatrix
/**
* Prompts the user to save a matrix, and attemps to save it.
*
*/
private void saveMatrix() {
int returnVal = m_fileChooser.showSaveDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File selectedFile = m_fileChooser.getSelectedFile();
// append extension if not already present
if (!selectedFile.getName().toLowerCase()
.endsWith(CostMatrix.FILE_EXTENSION)) {
selectedFile = new File(selectedFile.getParent(),
selectedFile.getName()
+ CostMatrix.FILE_EXTENSION);
}
Writer writer = null;
try {
writer = new BufferedWriter(new FileWriter(selectedFile));
m_matrix.write(writer);
writer.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Error writing file '"
+ selectedFile.getName()
+ "':\n" + ex.getMessage(),
"Save failed",
JOptionPane.ERROR_MESSAGE);
System.out.println(ex.getMessage());
}
}
}
示例4: saveMatrix
/**
* Prompts the user to save a matrix, and attemps to save it.
*
*/
private void saveMatrix() {
int returnVal = m_fileChooser.showSaveDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
File selectedFile = m_fileChooser.getSelectedFile();
// append extension if not already present
if (!selectedFile.getName().toLowerCase()
.endsWith(CostMatrix.FILE_EXTENSION)) {
selectedFile = new File(selectedFile.getParent(),
selectedFile.getName()
+ CostMatrix.FILE_EXTENSION);
}
Writer writer = null;
try {
writer = new BufferedWriter(new FileWriter(selectedFile));
m_matrix.write(writer);
writer.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
Messages.getInstance().getString("CostMatrixEditor_SaveMatrix_JOptionPaneShowMessageDialog_Text_First")
+ selectedFile.getName()
+ Messages.getInstance().getString("CostMatrixEditor_SaveMatrix_JOptionPaneShowMessageDialog_Text_Second") + ex.getMessage(),
Messages.getInstance().getString("CostMatrixEditor_SaveMatrix_JOptionPaneShowMessageDialog_Text_Third"),
JOptionPane.ERROR_MESSAGE);
System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() +ex.getMessage());
}
}
}
示例5: buildClassifier
/**
* Builds the model of the base learner.
*
* @param data the training data
* @throws Exception if the classifier could not 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();
if (m_MatrixSource == MATRIX_ON_DEMAND) {
String costName = data.relationName() + CostMatrix.FILE_EXTENSION;
File costFile = new File(getOnDemandDirectory(), costName);
if (!costFile.exists()) {
throw new Exception("On-demand cost file doesn't exist: " + costFile);
}
setCostMatrix(new CostMatrix(new BufferedReader(
new FileReader(costFile))));
}
// Set up the bagger
Bagging bagger = new Bagging();
bagger.setClassifier(getClassifier());
bagger.setSeed(getSeed());
bagger.setNumIterations(getNumIterations());
bagger.setBagSizePercent(getBagSizePercent());
bagger.buildClassifier(data);
// Use the bagger to reassign class values according to minimum expected
// cost
Instances newData = new Instances(data);
for (int i = 0; i < newData.numInstances(); i++) {
Instance current = newData.instance(i);
double [] pred = bagger.distributionForInstance(current);
int minCostPred = Utils.minIndex(m_CostMatrix.expectedCosts(pred));
current.setClassValue(minCostPred);
}
// Build a classifier using the reassigned data
m_Classifier.buildClassifier(newData);
}