iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 21
0
Google Developers Machine Learning

ML Study Jam -機器學習系列 第 21

Day 21 Preprocessing and Feature Creation part 2 (實作資料預處理)

Feature Enginnering

Preprocessing and Feature Creation part 2

Computing Time-Windowed Features in Cloud Dataprep

又出現一個新的東西了Dataprep,這邊先簡單講一下他有點像是能夠圖像化呈現數值,並且找到一些關鍵的統計數據,在這實驗當中我們會仔細去做使用,那這次的實驗是使用之前常用到的出租車的數據集利用Dataprep來做量化,並且透過各種篩選的方式來取的我們所需的數值

  1. 第一步先創建做為儲存使用的Bucket
    https://ithelp.ithome.com.tw/upload/images/20190920/201202894WQOwrKj03.png

  2. 接著創建到BigQuery頁面選擇創造一個新的Dataset
    https://ithelp.ithome.com.tw/upload/images/20190920/20120289q0e0dYVqw7.png

  3. 連接到Dataprep,並且予許Dataprep做存取

    • 進入到畫面後必須選擇存放資料的位置(選擇Bucket位置)

    • 建置完成後接著創建flows,並給予名稱與描述
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289752z9fo2UT.pnghttps://ithelp.ithome.com.tw/upload/images/20190920/20120289yuYeMDbjvB.png

    • 新增dataset,這邊選擇GCS裡面有搜尋asl-ml-immersion/nyctaxicab選擇要的檔案做加入,這邊選擇2015、2016年的資料,點選加入資料
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289oj5QlOKlnM.pnghttps://ithelp.ithome.com.tw/upload/images/20190920/20120289tOUeX6CqHw.png
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289tgrGexwxKW.png
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289h625yvhWD6.png

    • 匯入進來後選擇Add new Recipe,就可以進行編輯動作了
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289o3JhgxcB2a.png

  4. 接著要將兩筆資料集作加入,這邊看到的是兩筆分開的資料
    https://ithelp.ithome.com.tw/upload/images/20190920/20120289MlLBOnVSq4.png

    • 選擇Add Step,輸入union,選擇要加入的檔案,我們可以從pickup_day可以看到變成兩筆了確定有正確匯入
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289AvX2xOxUfw.png
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289WJd03AoYOF.png

    • 接著可以利用merge把年份跟時間連結起來,變成新的colunm
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289gCX7RIjfB7.png

    • 加入derive進行運算,這邊將日期與時間中間的符號拿掉,生成新的一欄,,為了識別為DATETIME同時可以增加分、秒
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289AOiL0IIXPP.png

    • 利用AVERAGE來計算fare_amount的平均
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289BzZLe9HL4H.png

    • 輸入window來計算他的移動平均數,這邊設定三小時
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289nPu3GfPklN.png

  5. 做完上述的動作後,啟動這個工作按下run job

    • 在這邊可以把剛剛更改好的資料集放到我們一開始創建的BigQuery中
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289L1tCnb9atp.pnghttps://ithelp.ithome.com.tw/upload/images/20190920/20120289sJDUBxQYom.png
    • 開始run之後我們可以看利用dataflow來看我們現在建置的介面
      https://ithelp.ithome.com.tw/upload/images/20190920/20120289gdPzowA4iZ.png
  6. 最後若是希望在BigQuery做查詢

    • 也可用SQL語法查詢所需要的資訊,可以在BigQuery創建資料意味著可以在python中進行開發了
#standardSQL
SELECT
  pickup_hour,
  FORMAT("$%.2f",ROUND(average_3hr_rolling_fare,2)) AS avg_recent_fare,
  ROUND(average_trip_distance,2) AS average_trip_distance_miles,
  FORMAT("%'d",sum_passenger_count) AS total_passengers_by_hour
FROM
  `asl-ml-immersion.demo.nyc_taxi_reporting`
ORDER BY
  pickup_hour DESC;

https://ithelp.ithome.com.tw/upload/images/20190920/20120289esAS44WdKL.png

這邊最主要的觀念就是透過視覺化的架構建構出屬於自己的資料集
而Dataprep在這邊就是非常好用的一套系統
在GCP平台上進行特徵的選擇、製作,比起人工的方式上述這些方法是會比較容易去理解與使用


上一篇
Day 20 Preprocessing and Feature Creation part 1 (資料預處理)
下一篇
Day 22 Feature Crosses part 1(特徵組合)
系列文
ML Study Jam -機器學習30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言