List of usage examples for org.apache.mahout.classifier OnlineLearner train
void train(int actual, Vector instance);
From source file:gov.llnl.ontology.mains.ExtendWordNet.java
License:Open Source License
/** * Trains the {@code hypernymPredictor} using the evidence from an {@link * EvidenceMap} and the class labels for each data point in that map. * //from w w w .ja v a 2s.co m * @param map The raw {@link Map} holding {@link Evidence} instances * @param model The model to be trained * @param classLabel the class label to be applied to all data in {@code * map} */ private void trainHypernyms(Map<String, Map<String, Evidence>> map, OnlineLearner model, int classLabel) { for (Map<String, Evidence> value : map.values()) for (Evidence e : value.values()) model.train(classLabel, new MahoutSparseVector(e.vector, basis.numDimensions())); }
From source file:gov.llnl.ontology.mains.ExtendWordNet.java
License:Open Source License
/** * Trains the {@code cousinPredictor} using the evidence from an {@link * EvidenceMap} and the similarity scores for each data point in that map. * // w ww .ja v a2 s.c o m * @param map The raw {@link Map} holding {@link Evidence} instances * @param model The model to be trained */ private void trainCousins(Map<String, Map<String, Evidence>> map, OnlineLearner model) { for (Map.Entry<String, Map<String, Evidence>> entry : map.entrySet()) { for (Map.Entry<String, Evidence> ev : entry.getValue().entrySet()) { // Determine whether or not the two terms are cousins. // Initially assume that they arent. Pair<Integer> cousinDepth = SynsetRelations.getCousinDistance( reader.getSynsets(entry.getKey(), PartsOfSpeech.NOUN), reader.getSynsets(ev.getKey(), PartsOfSpeech.NOUN), 7); // If the two terms are cousins, use 1 as the class label, // otherwise use 0. int classLabel = 0; if (cousinDepth.x != Integer.MAX_VALUE && cousinDepth.y != Integer.MAX_VALUE) classLabel = 1; // Train the model with this data point. model.train(classLabel, new DenseVector(ev.getValue().similarityScores)); } } }
From source file:opennlp.addons.mahout.AbstractOnlineLearnerTrainer.java
License:Apache License
protected void trainOnlineLearner(DataIndexer indexer, org.apache.mahout.classifier.OnlineLearner pa) { int cardinality = indexer.getPredLabels().length; int outcomes[] = indexer.getOutcomeList(); for (int i = 0; i < indexer.getContexts().length; i++) { Vector vector = new RandomAccessSparseVector(cardinality); int features[] = indexer.getContexts()[i]; for (int fi = 0; fi < features.length; fi++) { vector.set(features[fi], indexer.getNumTimesEventsSeen()[i]); }//from w ww. j av a2s. co m pa.train(outcomes[i], vector); } }