Пример #1
0
def train(color, trainExamples, syzygy):
    return submission.learnPredictor(trainExamples, trainExamples,
                                     extractWordFeatures, color, syzygy)
Пример #2
0
import sys

maxN = 10
test_error = []

trainExamples = readExamples('polarity.train')
devExamples = readExamples('polarity.dev')

for n in range(maxN):
    sys.stdout.write(
        '\r=== Learning Character Features #{} Predictor ==='.format(n + 1))
    sys.stdout.flush()
    featureExtractor = extractCharacterFeatures(n)
    weights = learnPredictor(trainExamples,
                             devExamples,
                             featureExtractor,
                             numIters=20,
                             eta=0.01)
    devError = evaluatePredictor(
        devExamples, lambda (x):
        (1 if dotProduct(featureExtractor(x), weights) >= 0 else -1))
    test_error.append(devError)

print 'Test Error from #1 to #{}:'.format(maxN)
for e in test_error:
    print '{:.3f}'.format(e),
print

print '=== Learning Reference Word Feature Predictor ==='
featureExtractor = extractWordFeatures
weights = learnPredictor(trainExamples,
Пример #3
0

def featureExtractor(x):
    # x = "took Mauritius into"
    phi = defaultdict(float)
    #phi[x] = 1
    tokens = x.split()
    left, entity, right = tokens[0], tokens[1:-1], tokens[-1]
    phi['entity is ' + ' '.join(entity)] = 1
    phi['left is ' + left] = 1
    phi['right is ' + right] = 1
    for word in entity:
        phi['entity contains ' + word] = 1
        phi['entity contains prefix ' + word[:4]] = 1
        phi['entity contains suffix ' + word[-4:]] = 1
    return phi


# Learn a predictor
weights = submission.learnPredictor(trainExamples, devExamples,
                                    featureExtractor, 30, 0.05)
util.outputWeights(weights, 'weights')
util.outputErrorAnalysis(devExamples, featureExtractor, weights,
                         'error-analysis')

# Test!!!
testExamples = util.readExamples('names.test')
predictor = lambda x: 1 if util.dotProduct(featureExtractor(x), weights
                                           ) > 0 else -1
print 'test error =', util.evaluatePredictor(testExamples, predictor)
# configuration
DATABASE = '/tmp/tweetAnalyzer.db'
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = '******'
PASSWORD = '******'

# create our little application :)
app = Flask(__name__)
app.config.from_object(__name__)

# test the classifier on a large dataset
trainExamples = readExamples('sentiment/polarity.train')
featureExtractor = submission.extractCharacterFeatures(3)
weights = submission.learnPredictor(trainExamples, None, featureExtractor)
print "Training complete"


@app.route('/', methods=['GET', 'POST'])
@app.route('/?hash_tag=<hash_tag>')
def show_entries(hash_tag=""):

    hash_tag = ""
    result = []
    prediction = ('','')
    value = 0

    if len(request.args) != 0:
        print "Evaluating" + request.args.get('hash_tag')
        hash_tag = request.args.get('hash_tag')
Пример #5
0
def train(color, trainExamples, syzygy):
    return submission.learnPredictor(trainExamples, trainExamples, extractWordFeatures,color, syzygy)