Ejemplo n.º 1
0
def saveSubmission(trainFilePath, testFilePath, submissionFilePath, trainerFunc):

    header, trainData = readCsvData(trainFilePath)
    header, testData = readCsvData(testFilePath)

    trainData = processData1(trainData, False)
    testData = processData1(testData, True)

    output = computePrediction(trainData, testData, trainerFunc)

    open_file_object = csv.writer(open(submissionFilePath, "wb"))
    test_file_object = csv.reader(open(testFilePath, 'rb')) #Load in the csv file

    test_file_object.next()
    i = 0
    for row in test_file_object:
        row.insert(0,output[i].astype(np.uint8))
        open_file_object.writerow(row)
        i += 1

#header, allData = readCsvData('../csv/train.csv')
#print len(allData)
#trainData, validData, testData = splitCsvData(allData)
#print len(trainData)
#print len(validData)
#print len(testData)
#
#print costFunction(np.array([1,0,0,0,1,1,1,0,1]),np.array([1,1,0,1,1,0,1,1,0]))
Ejemplo n.º 2
0
""" Writing my first randomforest code.
Author : AstroDave
Date : 23rd September, 2012
please see packages.python.org/milk/randomforests.html for more

"""
from src.processors import processData1, processData2
from src.validations import validationLOO

import utilities as ut

header, trainSet = ut.readCsvData("../csv/train.csv")

trainSet1 = processData1(trainSet.copy())
validationLOO(trainSet1, True)

trainSet2 = processData2(trainSet.copy())
validationLOO(trainSet2, True)

# if cumErr/N < 0.10:
#    print "writing file..."
#    ut.saveSubmission('../csv/train.csv', '../csv/test.csv', '../csv/submission.csv', trainerFunc)