public void Train(ILabeledExampleCollection <LblT, ExT> dataset) { Preconditions.CheckNotNull(dataset); var trainDataset = new LabeledDataset <LblT, ExT>(dataset); for (int i = 0; i < mInnerModels.Length; i++) { if (mInnerModels[i] == null) { mInnerModels[i] = CreateModel(i); } mInnerModels[i].Train(GetTrainSet(i, mInnerModels[i], trainDataset)); } foreach (LabeledExample <LblT, ExT> le in trainDataset) { LabeledExample <LblT, ExT> le_ = le; string key = StringOf(mInnerModels.Select(m => m.Predict(le_.Example).BestClassLabel)); VotingEntry votingEntry = mVotingEntries[key]; votingEntry.LabelCounts[le.Label]++; } foreach (VotingEntry entry in mVotingEntries.Values) { PerformVoting(entry); } IsTrained = true; }
public Prediction <LblT> Predict(ExT example) { Preconditions.CheckState(IsTrained); string key = StringOf(mInnerModels.Select(m => m.Predict(example).BestClassLabel)); VotingEntry entry = mVotingEntries[key]; return(new Prediction <LblT>(new[] { new KeyDat <double, LblT>(1.0, entry.Label) })); }
protected override void PerformVoting(VotingEntry votingEntry) { if (votingEntry.Entropy > 1) { votingEntry.Label = SentimentLabel.Neutral; } else { base.PerformVoting(votingEntry); } }
protected override void PerformVoting(VotingEntry votingEntry) { if (votingEntry.LabelProbs[SentimentLabel.Neutral] == votingEntry.LabelProbs[SentimentLabel.Negative] && votingEntry.LabelProbs[SentimentLabel.Negative] == votingEntry.LabelProbs[SentimentLabel.Positive]) //if (votingEntry.Entropy > 1) { votingEntry.Label = SentimentLabel.Neutral; } else { base.PerformVoting(votingEntry); } }
public override void ParseJObject(Object obj) { Voting voting = (obj as Voting); JArray arr = (this.JsonObject as JArray); voting.Glosy.Clear(); foreach (JObject item in arr) { IVotingEntry votingEntry = new VotingEntry(); votingEntry.Glos = item.Value <JObject> ("glosy").Value <int> ("glos_id"); votingEntry.Glosujacy = item.Value <JObject> ("poslowie").Value <int> ("id"); votingEntry.GlosujacyImieNazwisko = item.Value <JObject> ("poslowie").Value <string> ("nazwa"); votingEntry.MowcaId = item.Value <JObject> ("mowcy").Value <int> ("mowca_id"); voting.Glosy.Add(votingEntry); } }
protected virtual void PerformVoting(VotingEntry votingEntry) { votingEntry.Label = votingEntry.LabelCounts.OrderByDescending(kv => kv.Value).First().Key; }