【新浪微博互動預測大賽】比賽鏈接http://tianchi.aliyun.com/competition/introduction.htm?spm=5176.100071.5678.1.7cNsYr&raceId=5
第一季和第二季是有區別的,所以只說說第二季。
因為練車,面試等等占用了大量時間,所以第二季我也沒花多少時間做,拿了36名,大概總結下吧。
第二季的題目與其說是預測微博一天后的互動數之和,不如說是分類問題,因為我們只要預測出他所在的那一類就算正確。比如實際是25,你預測11和49都算正確的,因為三個都是屬於第三個檔位。
由於模型的迭代計算都是以准確率為score的,但是第一類的數目巨大,所以將一條微博預測為第一類的可能性也大些。但是題目給了權重值,一個第二類相當於10個第一類了,所以,要解決這個問題,要么改評價函數,要么就對訓練樣本采樣。
采樣率的選擇也是有講究的。我們對二三月的每類個數乘以權重進行統計,計算每類的占比。然后我們確定取300000的樣本,計算每類需要的樣本數。
每類個數和 | 42659513 | 561360 | 594222 | 123765 | 160248 |
每類權重和 | 42659513 | 5613600 | 29711100 | 12376500 | 32049600 |
權重和比例 | 0.348496 | 0.045859 | 0.242717 | 0.101107 | 0.261821 |
每類實際需要個數 | 104549 | 13758 | 72815 | 30332 | 78546 |
每類采樣率 | 0.005 | 0.047 | 0.227 | 0.450 | 0.908 |
微調后的采樣率 | 0.003 | 0.03 | 0.17 | 0.4 | 1 |
微調后每類采樣個數 | 103584 | 14333 | 78233 | 33759 | 70091 |
由於平台的權重采樣得到的個數達不到我們設計的每個類別個數的要求,所以要對采樣率進行微調,使得采樣得到的每個類別的個數和我們設計的接近,微調后的采樣率見上表(空着的還沒寫,數據在寢室)。事實表明這樣可以提升成績。
確定了樣本,接下來就是特征選擇了,我提取的特征包括用戶特征和博文特征。
用戶特征包括用戶的月份互動的平均數,中位數,微博個數,粉絲數。博文特征包括時間特征,微博長度,微博中詞語的平均出現次數,微博的#個數,@格式,url個數,下面代碼可以看到這些特征(uid_avg_xx(_yy) 該用戶的xx月(到yy月)的微博轉贊評和的平均值,word_avg_times 微博中每個詞出現的平均次數,blog_time_week 星期幾,blog_time_hour 一天分為8個時間段,每個時間段3個小時,word_length 微博的博文單詞的個數,blog_jinghao,blog_at,blog_http,分別是#,@,有http的url出現的次數)。
select a.uid,a.mid,a.blog_time,a.blog,a.mid_count,a.ratio,a.blog_time_week,a.blog_time_hour,a.blog_weekdays,a.blog_weekends,a.blog_time_1,a.blog_time_2,a.blog_time_3,a.blog_time_4,a.blog_time_5,a.blog_time_6,a.blog_time_7,a.blog_time_8, b.uid_avg_11_2,b.uid_median_11_2,b.uid_count_11_2,b.uid_avg_1_2,b.uid_median_1_2,b.uid_count_1_2,b.uid_avg_11_12,b.uid_median_11_12,b.uid_count_11_12,b.uid_avg_2,b.uid_median_2,b.uid_count_2,b.uid_avg_1,b.uid_median_1,b.uid_count_1,b.uid_avg_12,b.uid_median_12,b.uid_count_12,b.uid_avg_11,b.uid_median_11,b.uid_count_11,b.uid_avg_15days,b.uid_median_15days,b.uid_count_15days,b.uid_avg_7days,b.uid_median_7days,b.uid_count_7days, c.word_length,c.word_avg_times,c.blog_jinghao,c.blog_at,c.blog_http,c.blog_wenhao,c.blog_hongbao,c.blog_shishi,c.blog_dianji,c.blog_shouqi,c.blog_daijinquan,c.blog_zhuanfa,c.blog_p1,c.blog_p2,c.blog_p3,c.blog_p4,c.blog_p5,c.blog_p6,d.fans_count,a.real_label from ${t1} a left outer join ${t2} b on a.uid=b.uid left outer join ${t3} c on a.mid=c.mid left outer join ${t4} d on a.uid=d.uid;
模型選用的是平台的RF模型。這次比賽的不足包括特征的選擇,平台也沒有特征選取的工具,我基本是人工試的。哪些特征放在一起得分高。由於時間有限,所以實驗的組合也很少,目前測試的得分最高的是使用了17個特征(下圖打鈎的,雖然我提取了50多個特征)。
調用平台的RF隨機森林算法,訓練出RF模型。
模型的評價是對3月份的所有微博做預測,然后計算得分。得分計算sql語句如下。
select sum(case when prediction_result=real_label and real_label=1 then 1 when prediction_result=real_label and real_label=2 then 10 when prediction_result=real_label and real_label=3 then 50 when prediction_result=real_label and real_label=4 then 100 when prediction_result=real_label and real_label=5 then 200 else 0 end)/sum(case when real_label=1 then 1 when real_label=2 then 10 when real_label=3 then 50 when real_label=4 then 100 when real_label=5 then 200 else 0 end) as score, sum(case when prediction_result=real_label and real_label=1 then 1 else 0 end) as right_1, sum(case when real_label=1 then 1 else 0 end) as total_1, sum(case when prediction_result=real_label and real_label=1 then 1 else 0 end)/sum(case when real_label=1 then 1 else 0 end) as score_1, sum(case when prediction_result=real_label and real_label=2 then 10 else 0 end) as right_2, sum(case when real_label=2 then 10 else 0 end) as total_2, sum(case when prediction_result=real_label and real_label=2 then 10 else 0 end)/sum(case when real_label=2 then 10 else 0 end) as score_2, sum(case when prediction_result=real_label and real_label=3 then 50 else 0 end) as right_3, sum(case when real_label=3 then 50 else 0 end) as total_3, sum(case when prediction_result=real_label and real_label=3 then 50 else 0 end)/sum(case when real_label=3 then 50 else 0 end) as score_3, sum(case when prediction_result=real_label and real_label=4 then 100 else 0 end) as right_4, sum(case when real_label=4 then 100 else 0 end) as total_4, sum(case when prediction_result=real_label and real_label=4 then 100 else 0 end)/sum(case when real_label=4 then 100 else 0 end) as score_4, sum(case when prediction_result=real_label and real_label=5 then 200 else 0 end) as right_5, sum(case when real_label=5 then 200 else 0 end) as total_5, sum(case when prediction_result=real_label and real_label=5 then 200 else 0 end)/sum(case when real_label=5 then 200 else 0 end) as score_5 from ${t1}
可以計算每一類的得分哦。
然后調參,RF的主要參數一個是樹的個數,我這設的是500,一個是樹的深度,我這設的是50。
最后想說的就是一個人做比賽太累,最后也缺乏動力,所以最好能組個隊吧。