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


Java Model类代码示例

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


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

示例1: getFeatureImportance

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * @param gatherer 
 * @param features 
 * @return an array of feature IDs (>=1), ordered by feature importance, without zero-importance features.
 */
private static <T extends Serializable, G extends Serializable> int[] getFeatureImportance(ExampleGatherer<T, G> gatherer,
        int[] features) {
	ZScoreFeatureNormalizer scaleFn = ZScoreFeatureNormalizer.fromGatherer(gatherer);
	Parameter param = new Parameter(SolverType.L2R_L2LOSS_SVR, 0.01, 0.001);
	Problem problem = gatherer.generateLibLinearProblem(features, scaleFn);
	Model m = Linear.train(problem, param);
	double[] weights = m.getFeatureWeights();

	int[] ftrImportance = Arrays.stream(features).boxed().sorted(new Comparator<Integer>() {
		@Override
		public int compare(Integer fId0, Integer fId1) {
			return Double.compare(Math.abs(weights[ArrayUtils.indexOf(features, fId0)]), Math.abs(ArrayUtils.indexOf(features, fId1)));
		}
	}).filter(fId -> weights[ArrayUtils.indexOf(features, fId)] != 0.0).mapToInt(fId -> fId.intValue()).toArray();

	return ftrImportance;
}
 
开发者ID:marcocor,项目名称:smaph,代码行数:23,代码来源:TuneModelLibSvm.java

示例2: main

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Classifies an input file, given a model
 * @param args optional: input file, model file and the output file
 */
public static void main(String[] args) {

    loadLabelMappings("data/models/relevance_label_mappings.tsv");

    modelFile = "data/models/relevance_model.svm";
    testFile = "dev.tsv";
    predictionFile = "relevance_test_predictions.tsv";

    if (args.length == 3) {
        testFile = args[0];
        modelFile = args[1];
        predictionFile = args[2];
    }

    Vector<FeatureExtractor> features = loadFeatureExtractors();

    Model model = loadModel(modelFile);

    classifyTestSet(testFile, model, features, predictionFile, "relevance");
}
 
开发者ID:uhh-lt,项目名称:GermEval2017-Baseline,代码行数:25,代码来源:Test.java

示例3: main

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Trains the model from an input file
 * @param args optional: input file and optional model file
 */
public static void main(String[] args) {

    trainingFile = "train.tsv";
    modelFile = "data/models/relevance_model.svm";
    labelMappingsFile  = "data/models/relevance_label_mappings.tsv";

    if (args.length == 2) {
        trainingFile = args[0];
        modelFile = args[1];
    } else if (args.length == 1) {
        trainingFile = args[0];
    }

    Vector<FeatureExtractor> features = loadFeatureExtractors();

    Problem problem = buildProblem(trainingFile, features, "relevance");
    Model model = trainModel(problem);
    saveModel(model, modelFile);

    saveLabelMappings(labelMappingsFile);
}
 
开发者ID:uhh-lt,项目名称:GermEval2017-Baseline,代码行数:26,代码来源:Train.java

示例4: main

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Classifies an input file, given a model
 * @param args optional: input file, model file and the output file
 */
public static void main(String[] args) {

    loadLabelMappings("data/models/aspect_label_mappings.tsv");

    modelFile = "data/models/aspect_model.svm";
    testFile = "dev.tsv";
    predictionFile = "aspect_test_predictions.tsv";

    if (args.length == 3) {
        testFile = args[0];
        modelFile = args[1];
        predictionFile = args[2];
    }

    Vector<FeatureExtractor> features = loadFeatureExtractors();

    Model model = loadModel(modelFile);

    classifyTestSet(testFile, model, features, predictionFile, "aspect");
}
 
开发者ID:uhh-lt,项目名称:GermEval2017-Baseline,代码行数:25,代码来源:Test.java

示例5: main

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Classifies an input file, given a model
 * @param args optional: input file, model file and the output file
 */
public static void main(String[] args) {

    loadLabelMappings("data/models/aspect_coarse_label_mappings.tsv");

    testFile = "dev.tsv";
    modelFile = "data/models/aspect_coarse_model.svm";
    predictionFile = "aspect_coarse_test_predictions.tsv";

    if (args.length == 3) {
        testFile = args[0];
        modelFile = args[1];
        predictionFile = args[2];
    }

    Vector<FeatureExtractor> features = loadFeatureExtractors();

    Model model = loadModel(modelFile);

    useCoarseLabels = true;
    classifyTestSet(testFile, model, features, predictionFile, "aspect");
}
 
开发者ID:uhh-lt,项目名称:GermEval2017-Baseline,代码行数:26,代码来源:TestCoarse.java

示例6: main

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Trains the model from an input file
 * @param args optional: input file and optional model file
 */
public static void main(String[] args) {

    trainingFile = "train.tsv";
    modelFile = "data/models/aspect_model.svm";
    labelMappingsFile = "data/models/aspect_label_mappings.tsv";

    if (args.length == 2) {
        trainingFile = args[0];
        modelFile = args[1];
    } else if (args.length == 1) {
        trainingFile = args[0];
    }

    Vector<FeatureExtractor> features = loadFeatureExtractors();

    Problem problem = buildProblem(trainingFile, features, "aspect");
    Model model = trainModel(problem);
    saveModel(model, modelFile);

    saveLabelMappings(labelMappingsFile);
}
 
开发者ID:uhh-lt,项目名称:GermEval2017-Baseline,代码行数:26,代码来源:Train.java

示例7: main

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Trains the model from an input file
 * @param args optional: input file and optional model file
 */
public static void main(String[] args) {

    trainingFile = "train.tsv";
    modelFile = "data/models/aspect_coarse_model.svm";
    labelMappingsFile = "data/models/aspect_coarse_label_mappings.tsv";

    if (args.length == 2) {
        trainingFile = args[0];
        modelFile = args[1];
    } else if (args.length == 1) {
        trainingFile = args[0];
    }

    Vector<FeatureExtractor> features = loadFeatureExtractors();

    // enable coarse document labels
    useCoarseLabels = true;

    Problem problem = buildProblem(trainingFile, features, "aspect");
    Model model = trainModel(problem);
    saveModel(model, modelFile);

    saveLabelMappings(labelMappingsFile);
}
 
开发者ID:uhh-lt,项目名称:GermEval2017-Baseline,代码行数:29,代码来源:TrainCoarse.java

示例8: main

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Classifies an input file, given a model
 * @param args optional: input file, model file and the output file
 */
public static void main(String[] args) {

    loadLabelMappings("data/models/sentiment_label_mappings.tsv");

    modelFile = "data/models/sentiment_model.svm";
    testFile = "dev.tsv";
    predictionFile = "sentiment_test_predictions.tsv";
    positiveGazeteerFile = "data/dictionaries/positive";
    negativeGazeteerFile = "data/dictionaries/negative";

    if (args.length == 3) {
        testFile = args[0];
        modelFile = args[1];
        predictionFile = args[2];
    }

    Vector<FeatureExtractor> features = loadFeatureExtractors();

    Model model = loadModel(modelFile);

    classifyTestSet(testFile, model, features, predictionFile, "sentiment");

}
 
开发者ID:uhh-lt,项目名称:GermEval2017-Baseline,代码行数:28,代码来源:Test.java

示例9: main

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Trains the model from an input file
 * @param args optional: input file and optional model file
 */
public static void main(String[] args) {

    trainingFile = "train.tsv";
    modelFile = "data/models/sentiment_model.svm";
    labelMappingsFile  = "data/models/sentiment_label_mappings.tsv";
    positiveGazeteerFile = "data/dictionaries/positive";
    negativeGazeteerFile = "data/dictionaries/negative";

    if (args.length == 2) {
        trainingFile = args[0];
        modelFile = args[1];
    } else if (args.length == 1) {
        trainingFile = args[0];
    }

    Vector<FeatureExtractor> features = loadFeatureExtractors();

    Problem problem = buildProblem(trainingFile, features, "sentiment");
    Model model = trainModel(problem);
    saveModel(model, modelFile);

    saveLabelMappings(labelMappingsFile);

}
 
开发者ID:uhh-lt,项目名称:GermEval2017-Baseline,代码行数:29,代码来源:Train.java

示例10: trainSvm

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Train SVM model. Return alpha and w matrix.
 * 
 * */
public StoreAlphaWeight trainSvm(File saveModel) throws Exception{
	StoreAlphaWeight saww=new StoreAlphaWeight();
	this.modelFile=saveModel;
	Problem problem=new Problem();
	problem.l=train; 
	problem.n=dimensions;
	problem.x=vectrain;
	problem.y=trainattr;
	SolverType s=SolverType.MCSVM_CS;  
       Parameter parameter = new Parameter(s, C, eps);
       Model modelg = Linear.train(problem, parameter, saww);
       try {
		modelg.save(saveModel);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
       return saww;
}
 
开发者ID:thunlp,项目名称:MMDW,代码行数:24,代码来源:Evaluate_SVM.java

示例11: evaluateSvm

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
public double[] evaluateSvm() throws Exception{
       	int right=0;
		Model model = Model.load(modelFile);
        for(int t=0;t<test;t++){
            double prediction = Linear.predict(model, vectest[t]);
            if(prediction==testattr[t]){
            	right++;
            }
          }
        double precision=(double)right/test;
        System.err.println("*************Precision = "+precision*100+"%*************");
        double storeResult[]=new double[3];
        storeResult[0]=right;
        storeResult[1]=test;
        storeResult[2]=precision;
        return storeResult;
}
 
开发者ID:thunlp,项目名称:MMDW,代码行数:18,代码来源:Evaluate_SVM.java

示例12: loadModels

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
/**
 * Load models and feature indexers from file
 * @return 
 */
public boolean loadModels()
{
    try
    {
        loadFeatureIndexers();
        labellerModel = Model.load(labellerModelFile);
        identifierModel = Model.load(identifierModelFile);
    } 
    catch (IOException ex)
    {
        LogInfo.error("Error opening classifier models or feature indexers.");
        return false;
    }
    return true;
}
 
开发者ID:sinantie,项目名称:PLTAG,代码行数:20,代码来源:ArgumentClassifier.java

示例13: train

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
public static void train() throws IOException, InvalidInputDataException{
	String file = "output\\svm/book_svm.svm";
	Problem problem = Problem.readFromFile(new File(file),-1);

	SolverType solver = SolverType.L2R_LR; // -s 0
	double C = 1.0;    // cost of constraints violation
	double eps = 0.01; // stopping criteria

	Parameter parameter = new Parameter(solver, C, eps);
	Model model = Linear.train(problem, parameter);
	File modelFile = new File("output/model");
	model.save(modelFile);
	System.out.println(modelFile.getAbsolutePath());
	// load model or use it directly
	model = Model.load(modelFile);

	Feature[] instance = { new FeatureNode(1, 4), new FeatureNode(2, 2) };
	double prediction = Linear.predict(model, instance);
	System.out.println(prediction);
	int nr_fold = 10;
    double[] target = new double[problem.l];
	Linear.crossValidation(problem, parameter, nr_fold, target);
}
 
开发者ID:laozhaokun,项目名称:sentimentclassify,代码行数:24,代码来源:Main.java

示例14: predict2

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
@Deprecated
public static int[] predict2(Model model, Feature[][] data, int[] labels) {

	int N = data.length;
	int[] pre_label = new int[N];

	for ( int i = 0; i < N; i ++ ) {
		pre_label[i] = Linear.predict(model, data[i]);
	}

	if (labels != null) {
		int cnt_correct = 0;
		for ( int i = 0; i < N; i ++ ) {
			if ( pre_label[i] == labels[i] )
				cnt_correct ++;
		}
		double accuracy = (double)cnt_correct / (double)N;
		System.out.println(String.format("Accuracy: %.2f%%\n", accuracy * 100));
	}

	return pre_label;

}
 
开发者ID:MingjieQian,项目名称:JML,代码行数:24,代码来源:MultiClassSVM.java

示例15: FastMarginModel

import de.bwaldvogel.liblinear.Model; //导入依赖的package包/类
public FastMarginModel(ExampleSet headerSet, Model linearModel, boolean useBias) {
	super(headerSet, ExampleSetUtilities.SetsCompareOption.ALLOW_SUPERSET,
			ExampleSetUtilities.TypesCompareOption.ALLOW_SAME_PARENTS);
	this.linearModel = linearModel;
	this.useBias = useBias;
	this.attributeConstructions = com.rapidminer.example.Tools.getRegularAttributeConstructions(headerSet);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:8,代码来源:FastMarginModel.java


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