Skip to content

Commit

Permalink
Task: conditional probability for single features
Browse files Browse the repository at this point in the history
For some reason, when classifying a document that consists only of one
feature, the hierarchical classifier only labels the document as neutral
or positive, even when the confidence values are less than 0.5.

I'm still not sure why this is the case, however I am addressing the
issue for the part of the web interface that shows the influence of each
of the individual features that make up the query by just using the
conditional probability of the feature across the labels instead of
trying to classify it. In the mean time, this addresses issue gh-27.
  • Loading branch information
bwbaugh committed Mar 25, 2013
1 parent 1c8545e commit 407c862
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions infertweet/ui/web/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ def predict(self, features):

def conditional(self, feature):
"""Get the contribution of an individual feature."""
label, probability = self.subjective_classify(feature)
if label == 'neutral':
probability = self.subjective_conditional(feature, 'neutral')
total = probability + self.subjective_conditional(feature, 'subjective')
return label, probability / total
probability = self.subjective_conditional(feature, 'neutral')
total = probability + self.subjective_conditional(feature, 'subjective')
probability /= total
if probability < 0.5:
return 'neutral', 1 - probability
else:
label, probability = self.polarity_classify(feature)
if label == 'positive':
probability = self.polarity_conditional(feature, 'positive')
total = probability + self.polarity_conditional(feature, 'negative')
probability = self.polarity_conditional(feature, 'positive')
total = probability + self.polarity_conditional(feature, 'negative')
probability /= total
if probability < 0.5:
return 'negative', 1 - probability
else:
probability = self.polarity_conditional(feature, 'negative')
total = probability + self.polarity_conditional(feature, 'positive')
return label, probability / total
return 'positive', probability

def log_query(self, label, probability, query):
"""Log the query to a file."""
Expand Down

0 comments on commit 407c862

Please sign in to comment.