Esempio n. 1
0
 def test_submission(self):
     train_data = extract_features(load_adult_train_data())
     valid_data = extract_features(load_adult_valid_data())
     model = submission(train_data)
     predictions = [predict(model, p) for p in train_data]
     print
     print
     print "Training Accuracy:", accuracy(train_data, predictions)
     predictions = [predict(model, p) for p in valid_data]
     print "Validation Accuracy:", accuracy(valid_data, predictions)
     print
Esempio n. 2
0
 def test_submission(self):
     train_data = extract_features(load_adult_train_data())
     valid_data = extract_features(load_adult_valid_data())
     model = submission(train_data)
     predictions = [predict(model, p) for p in train_data]
     print()
     print()
     print("Training Accuracy:", accuracy(train_data, predictions))
     predictions = [predict(model, p) for p in valid_data]
     print("Validation Accuracy:", accuracy(valid_data, predictions))
     print()
 def test_submission(self):
     """Overall test.
     """
     train_data = extract_features(load_adult_train_data())
     valid_data = extract_features(load_adult_valid_data())
     model = submission(train_data)
     predictions = [predict(model, p) for p in train_data]
     print("Training Accuracy: {0}".format(
         accuracy(train_data, predictions)))
     predictions = [predict(model, p) for p in valid_data]
     print("Validation Accuracy: {0}".format(
         accuracy(valid_data, predictions)))
Esempio n. 4
0
def test_submission():
    valid_data = test_data
    model = submission(train_data)
    predictions = [predict(model, p) for p in train_data]
    print
    print
    # print predictions
    train_accuracy = accuracy(train_data, predictions)
    print "Training Accuracy:", train_accuracy
    # print train_data
    predictions = [predict(model, p) for p in valid_data]
    valid_accuracy = accuracy(valid_data, predictions)
    print "Validation Accuracy:", valid_accuracy
    print
    return train_accuracy, valid_accuracy
Esempio n. 5
0
def getPredictions(username, input_address):
    # read all filenames in the input folder
    data_list = compute_for_username(username)
    max_num_faces = 0
    # predictions for all pictures
    predictions_all = []

    # filename should be in format: <unique filename>_<number of faces in picture>
    for data in data_list:
        print(data)
        item_dict = json.loads(data)
        max_num_faces = max(max_num_faces, len(item_dict))

        # predict for result of one picture
        predictions = []
        for i in range(0, len(item_dict)):
            face = {}
            face["faceRectangle"] = item_dict[i]["faceRectangle"]
            face["result"] = (predict(
                model, extract_features_single_point(item_dict[i]["scores"]))
                              >= 0.5)
            predictions.append(face)
        predictions_all.append(predictions)

    print max_num_faces
    return predictions_all, max_num_faces
Esempio n. 6
0
 def test_predict(self):
     """Tests the predict function.
     """
     model = [1, 2, 1, 0, 1]
     point = {'features': [.4, 1, 3, .01, .1], 'label': 1}
     p = predict(model, point)
     self.assertAlmostEqual(p, 0.995929862284)
Esempio n. 7
0
 def test_predict(self):
     model = [1,2,1,0,1]
     point = {'features':[.4,1,3,.01,.1], 'label': 1}
     p = predict(model, point)
     self.assertAlmostEqual(p, 0.995929862284)
Esempio n. 8
0
        max_num_faces = max(max_num_faces, len(item_dict))

        # predict for result of one picture
        predictions = []
        for i in range(0, len(item_dict)):
            face = {}
            face["faceRectangle"] = item_dict[i]["faceRectangle"]
            face["result"] = (predict(
                model, extract_features_single_point(item_dict[i]["scores"]))
                              >= 0.5)
            predictions.append(face)
        predictions_all.append(predictions)

    print max_num_faces
    return predictions_all, max_num_faces


if __name__ == "__main__":
    # prepare the model
    train_data = extract_features(load_adult_train_data())
    model = submission(train_data)
    print model
    predictions = [predict(model, p) for p in train_data]
    print
    print
    print "Training Accuracy:", accuracy(train_data, predictions)

    app.run(host='ec2-52-206-17-234.compute-1.amazonaws.com',
            port=8000,
            threaded=True)
Esempio n. 9
0
from sgd import extract_features
from sgd import logistic, dot, predict, accuracy, submission, extract_features
import csv
import random

from test import test_submission, return_train_data, return_test_data

test_submission()


def predict():
    train_data = return_train_data()
    test_data = return_test_data()
    model = submission(train_data)

    print test_data[0]
    # predictions = [predict(model, p) for p in train_data]


predict()