def predict_timestamps(): if not flask.request.json: flask.abort(400) dp.setHours2Predict(TU.parseHours(flask.request.json)) hours = list(TU.formatHours(dp.getHours2Predict())) pred = dp.getPredictions() return json.dumps(TU.outStr(hours,pred)), 201
fig3 = plt.figure() plt.boxplot(aDays.values()) plt.title('Demand vs day of week') plt.xlabel('Day') plt.ylabel('Demand') plt.show() def writeCSV(filename, data): out = csv.writer(open(filename, 'wb'), delimiter=',') for d in data: print d out.writerow(d.split(',')) #reload(DP) #reload(TU) fd = open('uber_demand_prediction_challenge.json') jsonData = json.load(fd) fd.close() dp = DP.DemandPrediction() dp.setTrainingData(jsonData) dp.train() mayHours = DP.genHours('2012-05-01T00:00:00+00:00', '2012-06-01T00:00:00+00:00') dp.setHours2Predict(mayHours) pred = dp.getPredictions() writeCSV('mayPredictions2.csv',TU.outStr(TU.formatHours(mayHours),pred) )
import requests import json import timeUtils as TU def apiCall(cmd,data): if (cmd!='train' and cmd!='predict' and cmd!='index'): raise Exception("invalid command") url = "http://localhost:5000/"+cmd+"/" print url headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} r = requests.post(url, data=json.dumps(data), headers=headers) return r # load data fd = open('uber_demand_prediction_challenge.json') jsonData = json.load(fd) fd.close() # train model r = apiCall('train',jsonData) # predict demand hours = TU.genHours('2012-05-01T00:00:00+00:00', '2012-06-01T00:00:00+00:00') r =apiCall('predict',TU.formatHours(hours))