1. 程式人生 > >阿里天池大資料競賽——口碑商家客流量預測 A

阿里天池大資料競賽——口碑商家客流量預測 A

阿里天池大資料競賽——口碑商家客流量預測的競賽已經結束了,作為一個剛參加這種專案競賽的純小白來說,走了不少的彎路,在資料處理的過程上花費了大量的時間和功夫,最後得到的效果也不好,不過從這個過程還是學習到了很多。
下面貼一個阿里官方給的一個demo,程式碼非常清晰簡單,沒有多餘的資料處理和演算法處理的過程,僅僅使用了pandas就把預測結果給得到了,而且得分還是較高的,參考意義非常大:

#coding=utf-8
import numpy as np
import pandas as pd

# your path to table user_pay
user_pay = 'user_pay.txt'
# load data print('loading data...') user_pay_df = pd.read_table(user_pay, sep=',', header=None, names=['user_id', 'shop_id', 'time_stamp'], dtype={'user_id':'str', 'shop_id':'str', 'time_stamp':'str'}) # generate customer flow print('generating customer flow...') user_pay_df['time_stamp'] = user_pay_df['time_stamp'
].str[:10] customer_flow = user_pay_df.groupby(['shop_id','time_stamp']).size() # predict fid = open('prediction_example.csv', 'w') for shop_id in xrange(1, 2001): print('predicting: %4d/2000'%shop_id) weekly_flow = pd.Series(np.zeros(7, dtype=int), [d.strftime('%Y-%m-%d') for d in pd.date_range('10/25/2016'
, periods=7)]) flow = customer_flow.loc[str(shop_id), '2016-10-25':'2016-10-31'] weekly_flow[flow.index.get_level_values(1)] = flow # use latest week's customer flow to predict following 2 weeks' customer flow predictons = ','.join([str(x) for x in list(weekly_flow)*2]) fid.write('%d,%s\n'%(shop_id, predictons)) fid.close() print('Finish')

繼續努力。