top of page

Python-陳O璉-未來銷售預測

  • 作家相片: Tw Tedu
    Tw Tedu
  • 2021年9月6日
  • 讀畢需時 2 分鐘

Kaggle競賽 :未來銷售預測


Kaggle competition : Predict Future Sales介紹:

由俄羅斯 1C Company提供2013/01 ~ 2015/10商品銷售資料,預測2015/11商品銷售數量


專案製作動機:

1.Kaggle是世界性數據分析競賽平台,參賽者多鑑別度也較高


2.Kaggle提供平常較難取得的真實數據


3.商品銷售預測對公司來說是常見且重要的主題


4.題目具有一定的難度




重點技術 - 箱型圖

快速判斷有無偏離值


mp.boxplot(train.item_cnt_day)

mp.show(block = False)






重點技術 - String Split

將字串切割,從中提取特徵

shops["city"] = shops.shop_name.str.split(" ").str[0]

shops["category"] = shops.shop_name.str.split(" ").str[1]


重點技術 - Label Encoder(標籤編碼)

字串切割出的特徵進行標籤化


shops["shop_category"] = LabelEncoder().fit_transform( shops.category )


shops["shop_city"] = LabelEncoder().fit_transform( shops.city )




重點技術 - 自定義時間性特徵函數

def lag(df, lags, merge_cols, col):

for i in lags:

shift = df[merge_cols+[col]].copy()

shift.columns = merge_cols + [col+"_lag_"+str(i)]

shift["date_block_num"] = shift.date_block_num + i

shift = shift.drop_duplicates()

df = pd.merge(df, shift, on = merge_cols, how = "left")

return df


以月份、商店ID、商品ID為例

merge_cols = ["date_block_num","shop_id", "item_id"]

col = "date_shop_item_item_cnt_mean"

data = matrix.groupby(merge_cols).agg({"item_cnt_month" : ["mean"]})

data.columns = [col]

data.reset_index(inplace = True)

matrix = pd.merge(matrix, data, on = merge_cols, how = "left")

matrix = lag(matrix, [1,2,3], merge_cols, col)

matrix.drop([col], axis = 1, inplace = True)


重點技術 - XGBoost演算法

boosting演算法的一種


核心思想類似:

三個臭皮匠勝過一個諸葛亮




優點 :

(1)使用二階泰勒展開,精準度更高

(2)添加正則化,針對葉子節點、權重進行L2正則,降低模型複雜度

(3)對特徵進行排序並儲存,並重複使用此結構,達到各特徵增益計算的多進行處理


數據分析專案報告:

技能收穫:

1.構思數據分析流程


2.依主題不同需補足該領域相關知識、定義需要的函數

Comentários


bottom of page