예제 #1
0
def selfTest(cuisinier):
    # Read and parse JSON data
    recipes = getClassifiedRecipes(TRAINING_FILE)
    cuisinier.addRecipes(recipes)

    success = 0
    for recipe in recipes:
        result = cuisinier.classifyRecipe(Recipe(recipe.id,
                                                 recipe.ingredients))
        if result.cuisine == recipe.cuisine:
            success += 1

    print((cuisinier.getAlgorithmType() + " self-test accuracy: " +
           str(success) + "/" + str(len(recipes)) + " (" +
           "{0:.2f}".format(success / len(recipes) * 100) + "%)"))
예제 #2
0
def selfTest():
    # Read and parse JSON data
    recipes = getClassifiedRecipes(TRAINING_FILE)
    cuisinier = Cuisinier()
    cuisinier.addRecipes(recipes)

    success = 0
    for recipe in recipes:
        result = cuisinier.classifyRecipe(Recipe(recipe.id,
                                                 recipe.ingredients))
        if result.cuisine == recipe.cuisine:
            success += 1
        print(str(result.id) + ":\t" + result.cuisine + " / " + recipe.cuisine)

    print("Self-test: " + str(success) + "/" + str(len(recipes)))
예제 #3
0
def test():
    recipesToClassify = getRecipes(TEST_FILE)
    recipes = getClassifiedRecipes(TRAINING_FILE)
    cuisinier = Cuisinier()
    cuisinier.addRecipes(recipes)

    with open('submissionData.csv', 'wb') as fileToWrite:
        csv_writer = csv.writer(fileToWrite)
        csv_writer = csv.writer(fileToWrite, delimiter=',',
                            quotechar='|', quoting=csv.QUOTE_MINIMAL)
        csv_writer.writerow(["id","cuisine"])

        success = 0
        for recipe in recipesToClassify:
            result = cuisinier.classifyRecipe(Recipe(recipe.id,
                                                     recipe.ingredients))
            csv_writer.writerow([recipe.id, result.cuisine])
예제 #4
0
def getRecipes(file):
    f = open(file)
    recipes = json.loads(f.read())
    f.close()
    return [Recipe(recipe["id"], recipe["ingredients"]) for recipe in recipes]