コード例 #1
0
def threadPredict(model,test_data,test_Xc,start_index,end_index,test_loc_dic):
    start_time = time.time()
    pre_result = predict(model, test_Xc[start_index:end_index])
    end_time = time.time()

    print "predict from %d to %d. \n cost time :%lf s\n" % (start_index, end_index, end_time - start_time)
    start_time1 = time.time()
    result = transformResult(pre_result, test_loc_dic)
    if mu.acquire(True):
        wr = WriteResult()
        wr.WriteResultAnswer(test_data[start_index:end_index], result,Config.ResultDataPath+"submission_1.csv")
        mu.release()
    end_time1 = time.time()
    print "transform index from %d to %d. \n cost time :%lf s\n" % (start_index, end_index, end_time1 - start_time1)
コード例 #2
0
def main():
    print "Start......"
    rf = ReadCsvFile()
    # train_data = rf.ReadTrainFile()
    preP = PreProcess()
    # train_X,train_lab,loc_dic = preP.preProcessTrainData(train_data)
    # train_Xc = preP.getFeatureScaler(train_X)
    # print "Train model"
    # TrainModel(train_Xc,train_lab)
    # train_lab = None
    # loc_dic = None
    # train_data = None
    # train_X = None
    # train_Xc = None
    # with open(Config.ResultDataPath+"result.csv","w") as fp:
    #     print "清空文件","result.csv"
    model = LoadModel()
    # print "Read data predict ... ... "
    test_data = rf.ReadTestFile()
    test_X,test_loc_dic = preP.preProcessTestData(test_data)
    test_Xc = preP.getFeatureScaler(test_X)
    test_X = None
    length = len(test_Xc)
    print "test data len:",length
    print "predict result ... ... "
    for i in xrange(104,length):
        pre_result = None
        start_index = i * 100
        end_index = (i+1) * 100
        if end_index > length:
            end_index = length
        start_time = time.time()
        pre_result = predict(model,test_Xc[start_index:end_index])
        end_time = time.time()
        print "predict from %d to %d. \n cost time :%lf s\n" % (start_index, end_index,end_time-start_time)
        start_time = time.time()
        result = transformResult(pre_result, test_loc_dic)
        logging.info("predict from %d to %d. \ncost time :%lf s" % (start_index, end_index,end_time-start_time))
        wr = WriteResult()
        wr.WriteResultAnswer(test_data[start_index:end_index], result,Config.ResultDataPath+"result_1.csv")
        end_time = time.time()
        logging.info("transform index from %d to %d. \ncost time :%lf s" % (start_index, end_index,end_time-start_time))
        print "transform index from %d to %d. \n cost time :%lf s\n" % (start_index, end_index,end_time-start_time)