Exemplo n.º 1
0
def eval(predictions, type='TWEET', predictToFile='predictionsTmp.json'):
    out_file = open(predictToFile, "w")
    for i in range(predictions.shape[0]):
        id = testIDs[i]
        prediction = predictions[i]
        bestPlace = np.argmax(prediction)
        placeName = colnames[bestPlace]

        my_dict = {
            'hashed_tweet_id': id,
            'city': placeName,
            'lat': placeMedian[placeName][0],  # 20.76
            'lon': placeMedian[placeName][1]  # 69.07
        }
        json.dump(my_dict, out_file)
        out_file.write("\n")
    out_file.close()
    evaluate_submission(predictToFile, goldFile, type)
Exemplo n.º 2
0
def evalMax(predictions, type='USER', predictToFile='predictionsUserTmp.json'):
    out_file = open(predictToFile, "w")
    for userHash in set(testUserIds):
        indices = [i for i, x in enumerate(testUserIds) if x == userHash]

        prediction = predictions[indices]  #Get all predictions for that user
        bestPlace = np.argmax(prediction) % prediction.shape[1]
        placeName = colnames[bestPlace]

        my_dict = {
            'hashed_user_id': userHash,
            'city': placeName,
            'lat': placeMedian[placeName][0],  # 20.76
            'lon': placeMedian[placeName][1]  # 69.07
        }
        # print(placeName +" " +instance.text)
        json.dump(my_dict, out_file)
        out_file.write("\n")
    out_file.close()
    evaluate_submission(predictToFile, goldFile, type)
Exemplo n.º 3
0
out_file = open("predictions.json", "w")
for id in testIDs:
    my_dict = {
        'hashed_tweet_id': id,
        'city': 'jakarta-04-id',
        'lat': lat,  # 20.76
        'lon': lon  # 69.07
    }
    # print(placeName +" " +instance.text)
    json.dump(my_dict, out_file)
    out_file.write("\n")

out_file.close()

from geoEval import evaluate_submission
evaluate_submission('predictions.json', 'test/test_labels/oracle.tweet.json',
                    'TWEET')

###Evaluate simple baseline for User predictions
f = open(testUser)

testUsernames = set()
for line in f:
    instance = parseJsonLine(line)
    testUsernames.add(instance.userName)

out_file = open('predictionsUser.json', "w")
for userHash in testUsernames:
    my_dict = {
        'hashed_user_id': userHash,
        'city': 'jakarta-04-id',
        'lat': lat,