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


Java SerializationHelper.write方法代码示例

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


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

示例1: train

import weka.core.SerializationHelper; //导入方法依赖的package包/类
public void train(String datasetFilename, boolean serialise)
{
    String[] lines = Utils.readLines(datasetFilename);
    int i = 1; // skip legend
    try
    {            
        for(i = 1; i < lines.length; i++) // skip legend
        {
            dataset.add(createFeatureVector(lines[i].split(","), true));
        }
        model = (Classifier) new LinearRegression();
        ((LinearRegression)model).setRidge(1.0e-10);
        model.buildClassifier(dataset);
        if(serialise)
        {                
            SerializationHelper.write(new FileOutputStream(modelFilename), model);
        }
    }
    catch(Exception e)
    {
        System.err.println("Error in line " + i + ": " + lines[i]);
        e.printStackTrace();
    }
}
 
开发者ID:sinantie,项目名称:Generator,代码行数:25,代码来源:LinearRegressionWekaWrapper.java

示例2: train

import weka.core.SerializationHelper; //导入方法依赖的package包/类
@Override
public void train(List<MLExample> pTrainExamples) throws Exception {
	ConfigurationUtil.TrainingMode = true;
	setPaths();

	//This part added since the session was so slow
	List<Integer> train_example_ids = new ArrayList<Integer>();
	for(MLExample example : pTrainExamples)
	{
		train_example_ids.add(example.getExampleId());
	}
	WekaFormatConvertor.writeToFile(train_example_ids, trainFile,taskName, new String[]{"1", "2"});

	DataSource source = new DataSource(trainFile);
	Instances data = source.getDataSet();
	// setting class attribute if the data format does not provide this information
	if (data.classIndex() == -1)
		data.setClassIndex(data.numAttributes() - 1);

	if(options!=null)
		wekaAlgorithm.setOptions(options);     // set the options
	wekaAlgorithm.buildClassifier(data);   // build classifier
	
	 // serialize model
	 SerializationHelper.write(modelFile, wekaAlgorithm);
}
 
开发者ID:ehsane,项目名称:rainbownlp,代码行数:27,代码来源:WekaClassifier.java

示例3: saveModel

import weka.core.SerializationHelper; //导入方法依赖的package包/类
public void saveModel(Classifier model, String modelpath) {
    try {
        SerializationHelper.write(modelpath, model);
    } catch (Exception ex) {
        Logger.getLogger(ModelGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:sfahadahmed,项目名称:hungrydragon,代码行数:8,代码来源:ModelGenerator.java

示例4: trainAndSerializeClassifier

import weka.core.SerializationHelper; //导入方法依赖的package包/类
/**
  * creates a classifier, trains and serializes it
  * 
  * @param data	the data to use (J48 with nominal class, M5P with
  * 			numeric class)
  * @return		the results for the data
  */
 protected double[] trainAndSerializeClassifier(Instances data) {
   Classifier	classifier;
   double[]	result;
   int		i;
   
   try {
     // build
     if (data.classAttribute().isNominal())
classifier = new weka.classifiers.trees.J48();
     else
classifier = new weka.classifiers.trees.M5P();
     classifier.buildClassifier(data);
     
     // record predictions
     result = new double[data.numInstances()];
     for (i = 0; i < result.length; i++)
result[i] = classifier.classifyInstance(data.instance(i));
     
     // save
     SerializationHelper.write(MODEL_FILENAME, classifier);
   }
   catch (Exception e) {
     fail("Training base classifier failed: " + e);
     return null;
   }
   
   return result;
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:36,代码来源:SerializedClassifierTest.java

示例5: trainAndSerializeClassifier

import weka.core.SerializationHelper; //导入方法依赖的package包/类
/**
 * creates a classifier, trains and serializes it
 * 
 * @param data the data to use (J48 with nominal class, M5P with numeric
 *          class)
 * @return the results for the data
 */
protected double[] trainAndSerializeClassifier(Instances data) {
  Classifier classifier;
  double[] result;
  int i;

  try {
    // build
    if (data.classAttribute().isNominal()) {
      classifier = new weka.classifiers.trees.J48();
    } else {
      classifier = new weka.classifiers.trees.M5P();
    }
    classifier.buildClassifier(data);

    // record predictions
    result = new double[data.numInstances()];
    for (i = 0; i < result.length; i++) {
      result[i] = classifier.classifyInstance(data.instance(i));
    }

    // save
    SerializationHelper.write(MODEL_FILENAME, classifier);
  } catch (Exception e) {
    fail("Training base classifier failed: " + e);
    return null;
  }

  return result;
}
 
开发者ID:umple,项目名称:umple,代码行数:37,代码来源:SerializedClassifierTest.java

示例6: forwardlinkTraining

import weka.core.SerializationHelper; //导入方法依赖的package包/类
public synchronized LinkClassifier forwardlinkTraining(Set<String> relUrls, int levels,
           String className) throws Exception {
	
    List<Sampler<LinkNeighborhood>> instances = loadTrainingInstances(relUrls, levels);
	
	String wekaInputAsString = createWekaInput(instances, false);
       
	logger.info("Training new link classifier...");
	Classifier classifier = trainWekaClassifier(wekaInputAsString);

       String modelFile = linkClassifierFolder.resolve("link_classifier.model").toString();
       String featuresFile = linkClassifierFolder.resolve("link_classifier.features").toString();
       
       logger.info("Link Clasifier model file: "+modelFile);
       logger.info("Link Clasifier features file: "+featuresFile);
       
       SerializationHelper.write(modelFile, classifier);
       writeFeaturesFile(featuresFile, features);

       String[] classValues = null;
       if (levels == 0) {
           classValues = new String[] {"POS", "NEG"};
       } else {
           classValues = new String[] {"0", "1", "2"};
       }
       
       return createLinkClassifierImpl(features, classValues, classifier, className, levels);
}
 
开发者ID:ViDA-NYU,项目名称:ache,代码行数:29,代码来源:LinkClassifierBuilder.java

示例7: saveSC

import weka.core.SerializationHelper; //导入方法依赖的package包/类
public Classifiers saveSC(String filename1, String filename2, String filename3, String filename4, String filename5) throws Exception
{
	SerializationHelper.write(filename1, SCA);
	SerializationHelper.write(filename2, SCB);
	SerializationHelper.write(filename3, SCC1);
	SerializationHelper.write(filename4, SCC2);
	SerializationHelper.write(filename5, SCC3);
	return this;
}
 
开发者ID:tbluche,项目名称:MERStructure,代码行数:10,代码来源:Classifiers.java

示例8: writeClassifier

import weka.core.SerializationHelper; //导入方法依赖的package包/类
/**
 *
 * @param classifier
 * @param file
 */
public void writeClassifier(final String file, final String lang) {
  final String name = getName(lang);
  LOG.info("writeClassifier: " + name);
  final String path = FilenameUtils.getPath(name);
  try {
    FileUtils.forceMkdir(new File(path));
    SerializationHelper.write(name, classifier);
  } catch (final Exception e) {
    LOG.error(e.getLocalizedMessage(), e);
  }
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:17,代码来源:FoxClassifier.java

示例9: main

import weka.core.SerializationHelper; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

		String modelName = "models/wiki_scoring_noun10conjarg2_sim5log-gopt_SVMRankC10_RepDisc";

		String modelFile = modelName + ".model";
		FilteredClassifier clf = (FilteredClassifier) SerializationHelper.read(modelFile);

		RankingSVM svm = new RankingSVM();
		svm.setWeights(modelName + ".weights");

		clf.setClassifier(svm);
		System.out.println(clf);

		SerializationHelper.write(modelName + ".model_new", clf);

	}
 
开发者ID:UKPLab,项目名称:ijcnlp2017-cmaps,代码行数:17,代码来源:ConvertModel.java

示例10: convert

import weka.core.SerializationHelper; //导入方法依赖的package包/类
public void convert() throws Exception {
	
	if( ! new File( getInputModel() ).exists() ) {
		throw new FileNotFoundException( "Input model " + getInputModel() + " does not exist!");
	}
	
	if( ! new File( getScriptPath() ).exists() ) {
		throw new FileNotFoundException( "Python script " + getScriptPath() + " does not exist!");
	}
	
	PyScriptClassifier cls = (PyScriptClassifier) SerializationHelper.read( getInputModel() );
	
	System.err.println( cls.getModelString() + "\nCurrent script path: " +
			cls.getPythonFile().getAbsolutePath() );		
	
	System.err.println("Changing script path to: " + getScriptPath() );
	
	cls.setPythonFile( new File( getScriptPath() ) );
	
	SerializationHelper.write( getOutputModel(), cls);
	
}
 
开发者ID:christopher-beckham,项目名称:weka-pyscript,代码行数:23,代码来源:ChangeScriptPath.java

示例11: saveRC

import weka.core.SerializationHelper; //导入方法依赖的package包/类
public Classifiers saveRC(String filename) throws Exception
{
	SerializationHelper.write(filename, RC);
	return this;
}
 
开发者ID:tbluche,项目名称:MERStructure,代码行数:6,代码来源:Classifiers.java

示例12: saveYNC

import weka.core.SerializationHelper; //导入方法依赖的package包/类
public Classifiers saveYNC(String filename) throws Exception
{
	SerializationHelper.write(filename, YNC);
	return this;
}
 
开发者ID:tbluche,项目名称:MERStructure,代码行数:6,代码来源:Classifiers.java

示例13: saveModel

import weka.core.SerializationHelper; //导入方法依赖的package包/类
public static void saveModel(Classifier model, File dest) throws Exception {

        SerializationHelper.write(dest.getAbsolutePath(), model);
    }
 
开发者ID:wittawatj,项目名称:ctwt,代码行数:5,代码来源:Actions.java


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