当前位置: 首页>>代码示例>>Java>>正文


Java CostMatrix类代码示例

本文整理汇总了Java中weka.classifiers.CostMatrix的典型用法代码示例。如果您正苦于以下问题:Java CostMatrix类的具体用法?Java CostMatrix怎么用?Java CostMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CostMatrix类属于weka.classifiers包,在下文中一共展示了CostMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: actionPerformed

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Responds to the user perfoming an action.
 * 
 * @param e the action event that occured
 */
@Override
public void actionPerformed(ActionEvent e) {

  if (e.getSource() == m_defaultButton) {
    m_matrix.initialize();
    matrixChanged();
  } else if (e.getSource() == m_openButton) {
    openMatrix();
  } else if (e.getSource() == m_saveButton) {
    saveMatrix();
  } else if ((e.getSource() == m_classesField)
    || (e.getSource() == m_resizeButton)) {
    try {
      int newNumClasses = Integer.parseInt(m_classesField.getText());
      if (newNumClasses > 0 && newNumClasses != m_matrix.size()) {
        setValue(new CostMatrix(newNumClasses));
      }
    } catch (Exception ex) {
    }
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:27,代码来源:CostMatrixEditor.java

示例2: openMatrix

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Prompts the user to open a matrix, and attemps to load it.
 * 
 */
private void openMatrix() {

  int returnVal = m_fileChooser.showOpenDialog(this);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    File selectedFile = m_fileChooser.getSelectedFile();
    Reader reader = null;
    try {
      reader = new BufferedReader(new FileReader(selectedFile));
      m_matrix = new CostMatrix(reader);
      reader.close();
      matrixChanged();
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(this, "Error reading file '"
        + selectedFile.getName() + "':\n" + ex.getMessage(), "Load failed",
        JOptionPane.ERROR_MESSAGE);
      System.out.println(ex.getMessage());
    }
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:24,代码来源:CostMatrixEditor.java

示例3: actionPerformed

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
    * Responds to the user perfoming an action.
    *
    * @param e the action event that occured
    */
   public void actionPerformed(ActionEvent e) {
     
     if (e.getSource() == m_defaultButton) {
m_matrix.initialize();
matrixChanged();
     } else if (e.getSource() == m_openButton) {
openMatrix();
     } else if (e.getSource() == m_saveButton) {
saveMatrix();
     } else if (    (e.getSource() == m_classesField) 
          || (e.getSource() == m_resizeButton) ) {
try {
  int newNumClasses = Integer.parseInt(m_classesField.getText());
  if (newNumClasses > 0 && newNumClasses != m_matrix.size()) {
    setValue(new CostMatrix(newNumClasses));
  }
} catch (Exception ex) {}
     }
   }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:25,代码来源:CostMatrixEditor.java

示例4: openMatrix

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
    * Prompts the user to open a matrix, and attemps to load it.
    *
    */
   private void openMatrix() {

     int returnVal = m_fileChooser.showOpenDialog(this);
     if(returnVal == JFileChooser.APPROVE_OPTION) {
File selectedFile = m_fileChooser.getSelectedFile();
Reader reader = null;
try {
  reader = new BufferedReader(new FileReader(selectedFile));
  m_matrix = 
    new CostMatrix(reader);
  reader.close();
  matrixChanged();
} catch (Exception ex) {
  JOptionPane.showMessageDialog(this, 
				"Error reading file '"
				+ selectedFile.getName()
				+ "':\n" + ex.getMessage(),
				"Load failed",
				JOptionPane.ERROR_MESSAGE);
  System.out.println(ex.getMessage());
}
     }
   }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:28,代码来源:CostMatrixEditor.java

示例5: getClassifier

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/** Creates a default CostSensitiveClassifier */
public Classifier getClassifier() {

  CostSensitiveClassifier cl = new CostSensitiveClassifier();
  
  // load costmatrix
  try {
    cl.setCostMatrix(
        new CostMatrix(
          new InputStreamReader(ClassLoader.getSystemResourceAsStream(
                "weka/classifiers/data/ClassifierTest.cost"))));
  }
  catch (Exception e) {
    e.printStackTrace();
  }
  
  return cl;
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:19,代码来源:CostSensitiveClassifierTest.java

示例6: openMatrix

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
    * Prompts the user to open a matrix, and attemps to load it.
    *
    */
   private void openMatrix() {

     int returnVal = m_fileChooser.showOpenDialog(this);
     if(returnVal == JFileChooser.APPROVE_OPTION) {
File selectedFile = m_fileChooser.getSelectedFile();
Reader reader = null;
try {
  reader = new BufferedReader(new FileReader(selectedFile));
  m_matrix = 
    new CostMatrix(reader);
  reader.close();
  matrixChanged();
} catch (Exception ex) {
  JOptionPane.showMessageDialog(this, 
		  Messages.getInstance().getString("CostMatrixEditor_OpenMatrix_JOptionPaneShowMessageDialog_Text_First")
				+ selectedFile.getName()
				+ Messages.getInstance().getString("CostMatrixEditor_OpenMatrix_JOptionPaneShowMessageDialog_Text_Second") + ex.getMessage(),
				Messages.getInstance().getString("CostMatrixEditor_OpenMatrix_JOptionPaneShowMessageDialog_Text_Third"),
				JOptionPane.ERROR_MESSAGE);
  System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() +ex.getMessage());
}
     }
   }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:28,代码来源:CostMatrixEditor.java

示例7: getEvalResultbyCost

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/***
	 * <p>To get 10-fold cross validation in one single arff in <b>path</b></p>
	 * <p>Use C4.5 and <b>Cost-sensitive learning</b> to classify the dataset.</p>
	 * @param path dataset path
	 * @throws Exception
	 */
	public static void getEvalResultbyCost(String path, int index) throws Exception{
		
		Instances ins = DataSource.read(path);
		int numAttr = ins.numAttributes();
		ins.setClassIndex(numAttr - 1);
		
		/**Classifier setting*/
		J48 j48 = new J48();
//		j48.setConfidenceFactor(0.4f);
		j48.buildClassifier(ins);
		
		CostSensitiveClassifier csc = new CostSensitiveClassifier();
		csc.setClassifier(j48);
		csc.setCostMatrix(new CostMatrix(new BufferedReader(new FileReader("files/costm"))));
		
		Evaluation eval = new Evaluation(ins);
		
		eval.crossValidateModel(csc, ins, 10, new Random(1));
		
//		System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(0), eval.recall(0), eval.fMeasure(0));
//		System.out.printf(" %4.3f %4.3f %4.3f", eval.precision(1), eval.recall(1), eval.fMeasure(1));
//		System.out.printf(" %4.3f \n\n", (1-eval.errorRate()));
		results[index][0] = eval.precision(0);
		results[index][1] = eval.recall(0);
		results[index][2] = eval.fMeasure(0);
		results[index][3] = eval.precision(1);
		results[index][4] = eval.recall(1);
		results[index][5] = eval.fMeasure(1);
		results[index][6] = 1-eval.errorRate();
			
	}
 
开发者ID:Gu-Youngfeng,项目名称:CraTer,代码行数:38,代码来源:ImbalanceProcessingAve.java

示例8: costMatrixSourceTipText

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * @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 + ").";
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:14,代码来源:CostSensitiveClassifier.java

示例9: makeWeighted

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Makes a copy of this ConfusionMatrix after applying the supplied CostMatrix
 * to the cells. The resulting ConfusionMatrix can be used to get
 * cost-weighted statistics.
 * 
 * @param costs the CostMatrix.
 * @return a ConfusionMatrix that has had costs applied.
 * @exception Exception if the CostMatrix is not of the same size as this
 *              ConfusionMatrix.
 */
public ConfusionMatrix makeWeighted(CostMatrix costs) throws Exception {

  if (costs.size() != size()) {
    throw new Exception("Cost and confusion matrices must be the same size");
  }
  ConfusionMatrix weighted = new ConfusionMatrix(m_ClassNames);
  for (int row = 0; row < size(); row++) {
    for (int col = 0; col < size(); col++) {
      weighted.set(row, col, get(row, col) * costs.getElement(row, col));
    }
  }
  return weighted;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:24,代码来源:ConfusionMatrix.java

示例10: saveMatrix

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * 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());
    }
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:31,代码来源:CostMatrixEditor.java

示例11: CostMatrixEditor

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Constructs a new CostMatrixEditor.
 * 
 */
public CostMatrixEditor() {

  m_matrix = new CostMatrix(2);
  m_propSupport = new PropertyChangeSupport(this);
  m_customEditor = new CustomEditor();
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:11,代码来源:CostMatrixEditor.java

示例12: setValue

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Sets the value of the CostMatrix to be edited.
 * 
 * @param value a CostMatrix object to be edited
 */
@Override
public void setValue(Object value) {

  m_matrix = (CostMatrix) value;
  m_customEditor.matrixChanged();
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:12,代码来源:CostMatrixEditor.java

示例13: makeWeighted

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Makes a copy of this ConfusionMatrix after applying the
 * supplied CostMatrix to the cells. The resulting ConfusionMatrix
 * can be used to get cost-weighted statistics.
 *
 * @param costs the CostMatrix.
 * @return a ConfusionMatrix that has had costs applied.
 * @exception Exception if the CostMatrix is not of the same size
 * as this ConfusionMatrix.
 */
public ConfusionMatrix makeWeighted(CostMatrix costs) throws Exception {

  if (costs.size() != size()) {
    throw new Exception("Cost and confusion matrices must be the same size");
  }
  ConfusionMatrix weighted = new ConfusionMatrix(m_ClassNames);
  for (int row = 0; row < size(); row++) {
    for (int col = 0; col < size(); col++) {
      weighted.setElement(row, col, getElement(row, col) * 
                          costs.getElement(row, col));
    }
  }
  return weighted;
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:25,代码来源:ConfusionMatrix.java

示例14: saveMatrix

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
    * 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());
}
     }
   }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:35,代码来源:CostMatrixEditor.java

示例15: CostMatrixEditor

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Constructs a new CostMatrixEditor.
 *
 */
public CostMatrixEditor() {

  m_matrix = new CostMatrix(2);
  m_propSupport = new PropertyChangeSupport(this);
  m_customEditor = new CustomEditor();
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:11,代码来源:CostMatrixEditor.java


注:本文中的weka.classifiers.CostMatrix类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。