• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CostMatrix类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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, 
		  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());
}
     }
   }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:35,代码来源:CostMatrixEditor.java


示例17: setCostMatrix

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Sets the misclassification cost matrix.
 *
 * @param newCostMatrix the cost matrix
 */
public void setCostMatrix(CostMatrix newCostMatrix) {
  
  m_CostMatrix = newCostMatrix;
  m_MatrixSource = MATRIX_SUPPLIED;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:11,代码来源:CostSensitiveClassifier.java


示例18: setValue

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Sets the value of the CostMatrix to be edited.
 *
 * @param value a CostMatrix object to be edited
 */
public void setValue(Object value) {
  
  m_matrix = (CostMatrix) value;
  m_customEditor.matrixChanged();
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:11,代码来源:CostMatrixEditor.java


示例19: buildClassifier

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


示例20: AggregateableEvaluationWithPriors

import weka.classifiers.CostMatrix; //导入依赖的package包/类
/**
 * Constructs a new AggregateableEvaluationWithPriors object
 * 
 * @param data the Instances to use
 * @param costMatrix the cost matrix to use
 * @throws Exception if a problem occurs
 */
public AggregateableEvaluationWithPriors(Instances data, CostMatrix costMatrix)
  throws Exception {
  super(data, costMatrix);
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:12,代码来源:AggregateableEvaluationWithPriors.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Language类代码示例发布时间:2022-05-22
下一篇:
Java JSON类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap