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


Java MultiLabelInstances.getDataSet方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: saveDataset

import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
 * Save dataset
 * 
 * @param wr PrintWriter
 * @param dataset Dataset
 * @param relationName Name of the relation
 */
public static void saveDataset(PrintWriter wr, MultiLabelInstances dataset, 
        String relationName)
{
    //relationName = relationName.replaceAll(" ", "_");
    if(relationName.contains("-")){
        wr.write("@relation " + "\'" + relationName + "\'");
    }
    else if(relationName.contains(":")){
        wr.write("@relation " + "\'" + relationName + "\'");
    }
    else{
        wr.write("@relation " + relationName);
    }

    wr.write(System.getProperty("line.separator"));  

    Instances instances = dataset.getDataSet();
   
    Attribute att;
    for (int i=0; i< instances.numAttributes();i++)
    {
        att = instances.attribute(i);
        wr.write(att.toString());
        wr.write(System.getProperty("line.separator")); 
    }   

    String current;
    
    wr.write("@data");
    wr.write(System.getProperty("line.separator"));  
    for(int i=0; i<dataset.getNumInstances();i++)
    {
        current = dataset.getDataSet().get(i).toString();
        wr.write(current);
        wr.write(System.getProperty("line.separator"));  
    }
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:45,代码来源:DataIOUtils.java

示例8: saveDatasetMV

import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
 * Save multi-label multi-view dataset
 * 
 * @param wr PrintWriter
 * @param dataset Dataset
 * @param relationName Name of the relation
 * @param views String with views intervals
 */
public static void saveDatasetMV(PrintWriter wr, MultiLabelInstances 
        dataset, String relationName, String views)
{
    //relationName = relationName.replaceAll(" ", "_");
    
    wr.write("@relation " + "\'" + relationName + " " + views + "\'");
    wr.write(System.getProperty("line.separator"));  
    
    Instances instancias = dataset.getDataSet();
   
    Attribute att;
    for (int i=0; i< instancias.numAttributes();i++)
    {
        att = instancias.attribute(i);
        wr.write(att.toString());
        wr.write(System.getProperty("line.separator")); 
    }   

    String current ;
    
    wr.write("@data");
    wr.write(System.getProperty("line.separator"));  
    for(int i=0; i<dataset.getNumInstances();i++)
    {
        current = dataset.getDataSet().get(i).toString();
        wr.write(current);
        wr.write(System.getProperty("line.separator"));  
    } 
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:38,代码来源:DataIOUtils.java

示例9: getAppearances

import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
public int [] getAppearances(MultiLabelInstances mlData){
	int [] appearances = new int[mlData.getNumLabels()];
	int [] labelIndices = mlData.getLabelIndices();
	
	for(Instance instance : mlData.getDataSet()){
		for(int label=0; label<mlData.getNumLabels(); label++){
			if(instance.value(labelIndices[label]) == 1){
				appearances[label]++;
			}
		}
	}
	
	return appearances;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:15,代码来源:SCUMBLE.java

示例10: makeAttributePairs

import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
 * Generates attribute pairs
 * 
 * @param labelPairs Label pairs
 * @param labelIndices Label indices
 * @param dataset Multi-label dataset
 * @return List of pairs of attributes
 */
private static ArrayList<AttributesPair> makeAttributePairs(int [] 
        labelPairs, int[] labelIndices, MultiLabelInstances dataset)
{
    ArrayList<AttributesPair> list = new ArrayList<>();
    Instances instances = dataset.getDataSet();

    String[] labelNames = DataInfoUtils.getLabelNames(labelIndices, instances);
    AttributesPair current;

    ImbalancedFeature[] imbalancedData = MetricUtils.getImbalancedDataByAppearances(dataset);
    int app_i, app_j;

    int labelPairsIndex = 0;
    int value;

    for(int i = 0; i<labelIndices.length; i++)
    {
        for(int j=i+1; j<labelIndices.length; j++)
        {
            value = labelPairs[labelPairsIndex];

            labelPairsIndex++; 

            if(value ==0) {
                continue;
            }

            app_i = DataInfoUtils.getLabelAppearancesByName(imbalancedData, labelNames[i]);
            app_j = DataInfoUtils.getLabelAppearancesByName(imbalancedData, labelNames[j]);

            current = new AttributesPair(labelNames[i], labelNames[j],value,i,j,app_i,app_j);
            list.add(current);   
        }
    }
    
    return list;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:46,代码来源:AttributePairsUtils.java

示例11: stratify

import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
 * Split in k folds stratified
 * 
 * @param data Dataset
 * @param folds Number of folds
 * @return Array of datasets with all folds
 */
public MultiLabelInstances[] stratify(MultiLabelInstances data, int folds) {
    try {
        MultiLabelInstances[] segments = new MultiLabelInstances[folds];
        LabelPowersetTransformation transformation = new LabelPowersetTransformation();
        Instances transformed;

        // transform to single-label
        transformed = transformation.transformInstances(data);
        
        // add id 
        Add add = new Add();
        add.setAttributeIndex("first");
        add.setAttributeName("instanceID");
        add.setInputFormat(transformed);
        transformed = Filter.useFilter(transformed, add);
        for (int i=0; i<transformed.numInstances(); i++) {
            transformed.instance(i).setValue(0, i);
        }            
        transformed.setClassIndex(transformed.numAttributes()-1);
        
        // stratify
        transformed.randomize(new Random(seed));
        transformed.stratify(folds);
        
        for (int i = 0; i < folds; i++) {
            //System.out.println("Fold " + (i + 1) + "/" + folds);
            Instances temp = transformed.testCV(folds, i);
            Instances test = new Instances(data.getDataSet(), 0);
            for (int j=0; j<temp.numInstances(); j++) {
                test.add(data.getDataSet().instance((int) temp.instance(j).value(0)));
            }                
            segments[i] = new MultiLabelInstances(test, data.getLabelsMetaData());
        }
        return segments;
    } catch (Exception ex) {
        Logger.getLogger(LabelPowersetTrainTest.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:47,代码来源:LabelPowersetTrainTest.java

示例12: 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){        
	Instances instances = mlData.getDataSet();
       
	int nLabels = mlData.getNumLabels();
       int [] labels = mlData.getLabelIndices();
       
       double [] entropies = new double[nLabels];
       
       for(int i=0; i<nLabels; i++){
           AttributeStats attStats = instances.attributeStats(labels[i]);
           
           if(attStats.nominalCounts != null){
               entropies[i] = Utils.entropy(attStats.nominalCounts);
           }
       }
       
       double maxEntropy = Double.MIN_VALUE;
       for(double e : entropies){
           if(e > maxEntropy){
               maxEntropy = e;
           }
       }
       
       this.value = maxEntropy;
       
       return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:34,代码来源:MaxEntropy.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){        
	Instances instances = mlData.getDataSet();
       
	int nLabels = mlData.getNumLabels();
       int [] labels = mlData.getLabelIndices();
       
       double [] entropies = new double[nLabels];
       
       for(int i=0; i<nLabels; i++){
           AttributeStats attStats = instances.attributeStats(labels[i]);
           
           if(attStats.nominalCounts != null){
               entropies[i] = Utils.entropy(attStats.nominalCounts);
           }
       }

       double meanEntropy = 0;
       for(double e : entropies){
           meanEntropy += e;
       }
       meanEntropy /= entropies.length;
       
       this.value = meanEntropy;
       
       return value;
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:33,代码来源:MeanEntropy.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){
       Instances instances = mlData.getDataSet();
       int nInstances = mlData.getNumInstances();
       
       Set<Attribute> attributesSet = mlData.getFeatureAttributes();
       
       int nNumeric = 0;
       double mean = 0;
       double avg;
       double var;
       double stdev;
       
       for(Attribute att : attributesSet){
           if(att.isNumeric()){
               nNumeric++;
               avg = instances.meanOrMode(att);
               var = 0;
               for(Instance inst : instances){
                   var += Math.pow(inst.value(att) - avg, 3);
               }
               stdev = Math.sqrt(instances.variance(att));
               mean += nInstances*var / ((nInstances-1)*(nInstances-2)*Math.pow(stdev, 3));
           }
       }
       
       if(nNumeric > 0){
       	this.value = mean / nNumeric;
       }
       else{
       	this.value = Double.NaN;
       }

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

示例15: saveMVMekaDataset

import mulan.data.MultiLabelInstances; //导入方法依赖的package包/类
/**
 * Save multi-view multi-label meka dataset
 * 
 * @param wr PrintWriter
 * @param dataset Dataset
 * @param relationName Name of the relation
 * @param views String with views intervals
 */
public static void saveMVMekaDataset(PrintWriter wr, MultiLabelInstances dataset, 
        String relationName, String views)
{
    int maxAttIndex;
    int minAttIndex;
    
    String c;
    c = "-C ";
    
    int [] attIndex = dataset.getFeatureIndices();
    
    maxAttIndex = getMax(attIndex);
    minAttIndex = getMin(attIndex);
    
    int [] labelIndices = dataset.getLabelIndices();
    
    boolean areLabelMaxIndices = true;
    boolean areLabelMinIndices = false;
    
    for(int i=0; i<labelIndices.length && areLabelMaxIndices; i++){
        if(labelIndices[i] < maxAttIndex){
            areLabelMaxIndices = false;
        }
    }
    
    if(!areLabelMaxIndices){
        areLabelMinIndices = true;
        for(int i=0; i<labelIndices.length && areLabelMinIndices; i++){
            if(labelIndices[i] > minAttIndex){
                areLabelMinIndices = false;
            }
        }
    }
    
    if((!areLabelMaxIndices) && (!areLabelMinIndices)){
        JOptionPane.showMessageDialog(null, "Cannot save as meka.", "alert", JOptionPane.ERROR_MESSAGE);
        return;
    }
    else if(areLabelMaxIndices){
        c = c + "-" + labelIndices.length;
    }
    else{
        c = c + labelIndices.length;
    }
    
    
    wr.write("@relation " + "\'" + relationName + ": " + c + " " + views + "\'");
    wr.write(System.getProperty("line.separator"));  

    Instances instances = dataset.getDataSet();
   
    Attribute att;
    for (int i=0; i< instances.numAttributes();i++)
    {
        att = instances.attribute(i);
        wr.write(att.toString());
        wr.write(System.getProperty("line.separator")); 
    }   

    String current;
    
    wr.write("@data");
    wr.write(System.getProperty("line.separator"));  
    for(int i=0; i<dataset.getNumInstances();i++)
    {
        current = dataset.getDataSet().get(i).toString();
        wr.write(current);
        wr.write(System.getProperty("line.separator"));  
    }
}
 
开发者ID:i02momuj,项目名称:MLDA,代码行数:79,代码来源:DataIOUtils.java


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