def method(train, validation, silent): trainResults = training(train, silent) #testResults = testFunc(trainResults, test)[0] bidprices = testFunc(trainResults, validation, silent)[1] #saveToFile(testResults, 'data/submissions/test.csv') return evaluate(bidprices, 'data/datasets/validation.csv', 6250)
def predict(constant_bidprices, validation_set): print('Predicting bid prices using constant bidding strategy model:') bids = {} validationDF = pd.read_csv(validation_set) n = len(validationDF) for i in range(0, n): progress(i + 1, n) bidid = validationDF.bidid.values[i] advertiser = validationDF.advertiser.values[i] constBidPrice = constant_bidprices[advertiser] bids[bidid] = constBidPrice return bids clearTerminal() start = time.time() print('Start') const_bidprices = train('train.csv') bids = predict(const_bidprices, 'validation.csv') evaluate(bids, 'validation.csv', 25000) end = time.time() printElapsedTime(start, end) print('Finish')
print('Predicting bid prices using linear bidding strategy model:') for i in range(0, n): progress(i+1, n) bidid = validationDF.bidid.values[i] advertiser = validationDF.advertiser.values[i] baseBidPrice = int(base_bidprices[advertiser] * pctrs[i] / avgCTR) bids[bidid] = baseBidPrice return bids clearTerminal() start = time.time() print('Start') trainingDF = pd.read_csv('train.csv') validationDF = pd.read_csv('validation.csv') transformCategoricalFeatures(trainingDF) transformCategoricalFeatures(validationDF) base_bidprices = train() bids = predict(base_bidprices) evaluate(bids, 'validation.csv', 6250) end = time.time() printElapsedTime(start, end) print('Finish')
if click_valid[i] == 1: print(i, linear_scale_factors[i], logistic_scale_factors[i]) clicked_linear_scale_factors.append(linear_scale_factors[i]) clicked_logistic_scale_factors.append(logistic_scale_factors[i]) linear_scaled_bidprices = scaleBids(bidprice_pred, linear_scale_factors) logistic_scaled_bidprices = scaleBids(bidprice_pred, logistic_scale_factors) unscaled_bids = dict(zip(bidid_valid, bidprice_pred)) linear_scaled_bids = dict(zip(bidid_valid, linear_scaled_bidprices)) logistic_scaled_bids = dict(zip(bidid_valid, logistic_scaled_bidprices)) if SOLUTION: out = open('testing_bidding_price.csv', 'w') out.write('bidid,bidprice\n') for i in range(0, len(linear_scaled_bidprices)): out.write( str(bidid_valid[i]) + ',' + str(ceil(linear_scaled_bidprices[i])) + '\n') out.flush() out.close() else: evaluate(unscaled_bids, 'validation.csv', 6250) evaluate(logistic_scaled_bids, 'validation.csv', 6250) evaluate(linear_scaled_bids, 'validation.csv', 6250) end = time.time() printElapsedTime(start, end) print('Finish')