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

Java MultiLabelInstances类代码示例

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

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



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

示例1: main

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
//        String arffFilename = Utils.getOption("arff", args); // e.g. -arff emotions.arff
//        String xmlFilename = Utils.getOption("xml", args); // e.g. -xml emotions.xml
        String dataSetName = "facet";
        String arffFilename = "M:\\我是研究生\\任务\\分面树的生成\\Facet\\experiment\\baseline\\引用最高的\\dataset\\" + dataSetName + "\\" + dataSetName + ".arff"; // e.g. -arff emotions.arff
        String xmlFilename = "M:\\我是研究生\\任务\\分面树的生成\\Facet\\experiment\\baseline\\引用最高的\\dataset\\" + dataSetName + "\\" + dataSetName + ".xml"; // e.g. -xml emotions.xml

        MultiLabelInstances dataset = new MultiLabelInstances(arffFilename, xmlFilename);

        RAkEL learner1 = new RAkEL(new LabelPowerset(new J48()));

        MLkNN learner2 = new MLkNN();

        Evaluator eval = new Evaluator();
        MultipleEvaluation results;

        int numFolds = 10;
        results = eval.crossValidate(learner1, dataset, numFolds);
        System.out.println(results);
        System.out.println("=========================================.");
        results = eval.crossValidate(learner2, dataset, numFolds);
        System.out.println(results);
        System.out.println("done.");
    }
 
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:25,代码来源:MulanExp1.java


示例2: saveXMLFile

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Save mulan xml file
 * 
 * @param wr PrintWriter
 * @param dataset Multi-label dataset
 * @throws IOException 
 */
public static void saveXMLFile(PrintWriter wr, MultiLabelInstances dataset) 
        throws IOException
{       
    wr.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    wr.write(System.getProperty("line.separator")); 
    wr.write("<labels xmlns=\"http://mulan.sourceforge.net/labels\">");
    wr.write(System.getProperty("line.separator")); 

    String [] labelNames = dataset.getLabelNames();

    for(int i=0; i<labelNames.length; i++){
        wr.write("<label name=\"" + labelNames[i] + "\"></label>");
        wr.write(System.getProperty("line.separator")); 
    }

    wr.write("</labels>");
    wr.write(System.getProperty("line.separator"));    
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:26,代码来源:DataIOUtils.java


示例3: saveMVDatasets

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Save multi-view multi-label datasets
 * 
 * @param datasets List of datasets
 * @param path Path to store
 * @param dataName Dataset name
 * @param type Type
 * @throws IOException 
 */
public static void saveMVDatasets(ArrayList<MultiLabelInstances> datasets, 
        String path, String dataName, String type) throws IOException
{
    BufferedWriter  bwCurrent;
    PrintWriter wr;        

    int index = 1;
    String currentPath;

    for(MultiLabelInstances currentData : datasets)
    {
        currentPath = path + "/"+ dataName + type + index + ".arff";

        bwCurrent = new BufferedWriter(new FileWriter(currentPath));
        wr = new PrintWriter(bwCurrent);

        saveDataset(wr, currentData, dataName);

        wr.close();
        bwCurrent.close();

        index++;
    }
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:34,代码来源:DataIOUtils.java


示例4: saveMekaDatasets

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Save meka datasets
 * 
 * @param datasets List of datasets
 * @param path Path to store
 * @param dataName Dataset name
 * @param type Type
 * @param relationName Name of the relation
 * @throws IOException 
 */
public static void saveMekaDatasets(ArrayList<MultiLabelInstances> datasets, 
        String path, String dataName, String type, String relationName) 
        throws IOException
{
    BufferedWriter  bwCurrent;
    PrintWriter wr;        

    int index = 1;
    String currentPath;

    for(MultiLabelInstances currentData : datasets)
    {
        currentPath = path + "/" + dataName + type + index + ".arff";

        bwCurrent = new BufferedWriter(new FileWriter(currentPath));
        wr = new PrintWriter(bwCurrent);

        saveMekaDataset(wr, currentData);

        wr.close();
        bwCurrent.close();

        index++;
    }
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:36,代码来源:DataIOUtils.java


示例5: saveMekaDatasetsNoViews

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Save meka datasets with no views
 * 
 * @param datasets List of datasets
 * @param path Path to store
 * @param dataName Dataset name
 * @param type Type
 * @param relationName Name of the relation
 * @throws IOException 
 */
public static void saveMekaDatasetsNoViews(ArrayList<MultiLabelInstances> 
        datasets, String path, String dataName, String type, String 
                relationName) throws IOException
{
    BufferedWriter  bwCurrent;
    PrintWriter wr;        

    int index = 1;
    String currentPath;

    for(MultiLabelInstances currentData : datasets)
    {
        currentPath = path + "/" + dataName + "-" + type + index + ".arff";

        bwCurrent = new BufferedWriter(new FileWriter(currentPath));
        wr = new PrintWriter(bwCurrent);

        saveMekaDataset(wr, currentData, dataName);

        wr.close();
        bwCurrent.close();

        index++;
    }
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:36,代码来源:DataIOUtils.java


示例6: saveMetricsCsv

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Save metrics as .csv file
 * 
 * @param wr PrintWriter
 * @param metricsList List with metric names
 * @param dataset Dataset
 * @param tableMetrics Table with metrics and values
 */
public static void saveMetricsCsv(PrintWriter wr, ArrayList<String> 
        metricsList, MultiLabelInstances dataset, Hashtable<String, String> 
        tableMetrics)
{
    wr.write("Relation Name"+ ";" + dataset.getDataSet().relationName());
    wr.write(System.getProperty("line.separator"));  

    wr.write(System.getProperty("line.separator"));   
    
    String value;
    for(String metric : metricsList)
    {
        value = MetricUtils.getValueFormatted(metric, tableMetrics.get(metric));
        if(value.equals("---")){
           wr.write(metric + ";" + "NaN"); 
        }
        else{
            wr.write(metric + ";" + value);
        }
        
        wr.write(System.getProperty("line.separator"));  
    }
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:32,代码来源:ResultsIOUtils.java


示例7: getAttributePairs

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Get pairs of attributes
 * 
 * @param dataset Dataset
 * @return List of pairs
 */
public static ArrayList<AttributesPair> getAttributePairs(
        MultiLabelInstances dataset)
{       
    Instances instances = dataset.getDataSet();
   
    //Return possible combinations among labels
    int possibleCombinations = getPossibleCombinations(dataset.getNumLabels());
    
    int [] labelPairAppearances = new int[possibleCombinations];
    int [] currentLabelValues;
    int[] labelIndices = dataset.getLabelIndices();
            
    for(int i=0; i<instances.size(); i++)
    {
        currentLabelValues = DataInfoUtils.getCurrentValueLabels(instances, i, labelIndices);
        labelPairAppearances = updateAttributePairs(labelPairAppearances, currentLabelValues);
    }            
    
    return makeAttributePairs(labelPairAppearances, labelIndices, dataset);
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:27,代码来源:AttributePairsUtils.java


示例8: getLabelNamesByLabelset

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Obtain label names from a labelset
 * 
 * @param dataset Dataset
 * @param labelset Labelset
 * @return List with label names
 */
public static ArrayList<String> getLabelNamesByLabelset(MultiLabelInstances
        dataset, String labelset)
{
    ArrayList<String> labelNames = new ArrayList();
    
    for(int i=0; i<labelset.length();i++)
    {
        if(labelset.charAt(i)=='1')
        {
            labelNames.add(getLabelByIndex(dataset, i).name());
        }
    }
    
    return labelNames;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:23,代码来源:DataInfoUtils.java


示例9: getLabelFrequency

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Get label frequency given the index
 * 
 * @param dataset Dataset
 * @param labelIndex Label index
 * @return Frequency of label
 */
public static double getLabelFrequency(MultiLabelInstances dataset, 
        int labelIndex)
{
    double value = 0.0;
    
    Instances instances = dataset.getDataSet();
    
    double  isLabel;
    
    for(int i=0; i<instances.size();i++)
    {
        isLabel=instances.instance(i).value(labelIndex);                
        if(isLabel==1.0) {
            value++;
        }
    }         
            
    return value/dataset.getNumInstances();
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:27,代码来源:DataInfoUtils.java


示例10: getChiPhiCoefficients

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Get Chi and Phi coefficients
 * 
 * @param dataset Multi-label dataset
 * @return Matrix of doubles with Chi and Phi values
 */
public static double[][] getChiPhiCoefficients (MultiLabelInstances dataset)
{
    double[][] coefficients = new double[dataset.getNumLabels()][dataset.getNumLabels()];
    double phi, chi;
    
    try {                
        UnconditionalChiSquareIdentifier depid = new UnconditionalChiSquareIdentifier();
        LabelsPair[] pairs = depid.calculateDependence(dataset);
        Statistics stat = new Statistics();
        double [][] phiMatrix = stat.calculatePhi(dataset);
            
        for (LabelsPair pair : pairs) {
            chi = pair.getScore();
            phi = phiMatrix[pair.getPair()[0]][pair.getPair()[1]];
            coefficients[pair.getPair()[0]][pair.getPair()[1]] = chi;
            coefficients[pair.getPair()[1]][pair.getPair()[0]] = phi;
        }   
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    
    return coefficients;  
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:31,代码来源:ChartUtils.java


示例11: calculateCoocurrences

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Calculate co-ocurrences of labels
 * 
 * @param mldata Multi-label dataset
 * @return Matrix of double with co-ocurrence values
 */
public static double[][] calculateCoocurrences(MultiLabelInstances mldata)
{        
    int nLabels = mldata.getNumLabels();
    Instances data = mldata.getDataSet();
        
    double [][] coocurrenceMatrix = new double[nLabels][nLabels];
    
    int [] labelIndices = mldata.getLabelIndices();
        
    Instance temp = null;
    for(int k=0; k<data.numInstances(); k++){   
        temp = data.instance(k);
            
        for(int i=0; i<nLabels; i++){
            for(int j=i+1; j<nLabels; j++){
                if((temp.value(labelIndices[i]) == 1.0) && (temp.value(labelIndices[j]) == 1.0)){
                    coocurrenceMatrix[i][j]++;
                }
            }
        }
    }
        
    return coocurrenceMatrix;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:31,代码来源:ChartUtils.java


示例12: split

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/** Returns a array with two multi-label stratified datasets corresponding to
 * the train and test datasets respectively.
 *
 * @param data
 *          A multi-label dataset.
 * @param percentage
 *          Percentage of train dataset.
 * @return MultiLabelInstances */
public MultiLabelInstances[] split(MultiLabelInstances data, double percentage)
  {
  int folds = 2;
  MultiLabelInstances[] segments = new MultiLabelInstances[folds];
  double[] splitRatio = new double[folds];
  splitRatio[0] = percentage / 100;
  splitRatio[1] = 1.0 - splitRatio[0];
  Instances[] singleSegments = foldsCreation(data.getDataSet(), new Random(seed), splitRatio, data.getNumLabels(), data.getLabelIndices(), data.getNumInstances());
  for (int i = 0; i < folds; i++)
    {
    try
      {
      segments[i] = new MultiLabelInstances(singleSegments[i], data.getLabelsMetaData());
      }
    catch (InvalidDataFormatException ex)
      {
      Logger.getLogger(IterativeStratification.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  return segments;
  }
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:30,代码来源:IterativeTrainTest.java


示例13: calculate

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Calculate metric value
 * 
 * @param mlData Multi-label dataset to which calculate the metric
 * @return Value of the metric
 */
public double calculate(MultiLabelInstances mlData){
	double stdv = 0;
	
	Cardinality card = new Cardinality();
	double avg = card.calculate(mlData);
       
       try{
           int [] labelsForInstance = Utils.labelsForInstance(mlData);
           double sum = 0;
           
           for(int i=0; i<labelsForInstance.length; i++){
               sum += Math.pow((double)labelsForInstance[i] - avg, 2);
           }
           
           stdv = Math.sqrt(sum / (labelsForInstance.length - 1));
       }
       catch(Exception e){
       	stdv = 0;
           e.printStackTrace();
       }
       
       this.value = stdv;
       return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:31,代码来源:StdvCardinality.java


示例14: calculate

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Calculate metric value
 * 
 * @param mlData Multi-label dataset to which calculate the metric
 * @return Value of the metric
 */
public double calculate(MultiLabelInstances mlData){
	double mean = 0.0;
       
	Instances instances = mlData.getDataSet();
       
       int countNominal = 0;
       int [] featureIndices = mlData.getFeatureIndices();
       
       for(int fIndex : featureIndices){
           AttributeStats attStats = instances.attributeStats(fIndex);
           if(attStats.nominalCounts != null){
               countNominal++;
               mean += Utils.entropy(attStats.nominalCounts);
           }
       }
       
       mean = mean/countNominal;
	
	this.value = mean;
	return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:28,代码来源:MeanEntropiesNominalAttributes.java


示例15: calculate

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Calculate metric value
 * 
 * @param mlData Multi-label dataset to which calculate the metric
 * @return Value of the metric
 */
public double calculate(MultiLabelInstances mlData){
	double mean = 0.0;
       int nNumeric = 0;
       
       Instances instances = mlData.getDataSet();
       
       Set<Attribute> attributeSet = mlData.getFeatureAttributes();
       for(Attribute att : attributeSet){
           if(att.isNumeric()){
               nNumeric++;
               mean += instances.meanOrMode(att);
           }
       }
       
       mean = mean/nNumeric;
	
	this.value = mean;
	return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:26,代码来源:MeanOfMeanOfNumericAttributes.java


示例16: calculate

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Calculate metric value
 * 
 * @param mlData Multi-label dataset to which calculate the metric
 * @return Value of the metric
 */
public double calculate(MultiLabelInstances mlData){
	double res = 0.0;
       
       try{
           ASEvaluation ase = new InfoGainAttributeEval();
       
           BinaryRelevanceAttributeEvaluator eval = new BinaryRelevanceAttributeEvaluator(ase, mlData, "avg", "none", "eval");

           int [] featureIndices = mlData.getFeatureIndices();

           for(int i : featureIndices){
               res += eval.evaluateAttribute(i);
           }

           res = res / featureIndices.length;
       }
       catch(Exception e){
           e.printStackTrace();
       	res = Double.NaN;
       }
	
	this.value = res;
	return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:31,代码来源:AvgGainRatio.java


示例17: calculate

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Calculate metric value
 * 
 * @param mlData Multi-label dataset to which calculate the metric
 * @return Value of the metric
 */
public double calculate(MultiLabelInstances mlData){
	double mean = 0;
       int nNumeric = 0;
       
       Instances instances = mlData.getDataSet();
       
       Set<Attribute> attributeSet = mlData.getFeatureAttributes();
       for(Attribute att : attributeSet){
           if(att.isNumeric()){
               nNumeric++;
               mean += Math.sqrt(instances.variance(att));
           }
       }
       
       if(nNumeric > 0){
       	this.value = mean / nNumeric;
       }
       else{
       	this.value = Double.NaN;
       }
	
	//this.value = mean;
	return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:31,代码来源:MeanStdvNumericAttributes.java


示例18: calculate

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Calculate metric value
 * 
 * @param mlData Multi-label dataset to which calculate the metric
 * @return Value of the metric
 */
public double calculate(MultiLabelInstances mlData){
	UnconditionalChiSquareIdentifier chi2Identifier = new UnconditionalChiSquareIdentifier();
       LabelsPair[] pairs = chi2Identifier.calculateDependence(mlData);
       
       int dep = 0;
       double score = 0.0;
       
       for (LabelsPair pair : pairs) {
           score = pair.getScore();
           if(score > 6.635){
               dep++;
           }
           else{
               break;
           }
       }
       
	this.value = ((double) dep)/pairs.length;
	return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:27,代码来源:RatioUnconditionalDependentLabelPairsByChiSquare.java


示例19: calculate

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Calculate metric value
 * 
 * @param mlData Multi-label dataset to which calculate the metric
 * @return Value of the metric
 */
public double calculate(MultiLabelInstances mlData){
	UnconditionalChiSquareIdentifier chi2Identifier = new UnconditionalChiSquareIdentifier();
       LabelsPair[] pairs = chi2Identifier.calculateDependence(mlData);
       
       int dep = 0;
       double score;
       
       for (LabelsPair pair : pairs) {
           score = pair.getScore();
           if(score > 6.635){
               dep++;
           }
           else{
               break;
           }
       }
	
	this.value = dep;
	return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:27,代码来源:NumUnconditionalDependentLabelPairsByChiSquare.java


示例20: calculate

import mulan.data.MultiLabelInstances; //导入依赖的package包/类
/**
 * Calculate metric value
 * 
 * @param mlData Multi-label dataset to which calculate the metric
 * @return Value of the metric
 */
public double calculate(MultiLabelInstances mlData){

	Statistics stat = new Statistics();
	stat.calculateStats(mlData);
	
	HashMap<LabelSet,Integer> labelsets = stat.labelCombCount();
       int nValues = labelsets.values().size();
       double mean = 0;
       
       for(int n : labelsets.values()){
           mean += n;
       }
       mean = mean/nValues;

	this.value = mean;
	return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:24,代码来源:MeanExamplesPerLabelset.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java MySqlMetadataHandler类代码示例发布时间:2022-05-22
下一篇:
Java Receiver类代码示例发布时间: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