Blog อันนี้เป็นบันทึกจาก Challenge จาก หนีจาก Azure มาลองเรียน Google Cloud โดยก่อนจะลองทำ challenge แนะนำว่าควรดูก่อนครับ
Task 1: Clean your training data
- อันนี้ใช้ Data Prep ก็ได้นะ ทำ Recipe เอา แต่บทล่าสุดใช้ BigQuery ML ยาวมา เลยลอง BigQuery ML
Data Cleaning Tasks:
- Ensure
trip_distanceis greater thanNumber. - Remove rows were
fare_amountis very small (less thanValuefor example). - Ensure that the latitudes and longitudes are reasonable for the use case.
- Ensure
passenger_countis greater thanNumber. - Be sure to add
tolls_amountandfare_amounttoFare amountas the target variable since total_amount includes tips. - Because the source dataset is large (>1 Billion rows), sample the dataset to less than 1 Million rows.
- Only copy fields that will be used in your model (
report_prediction_datais a good guide).
Select -- taxirides.report_prediction_data schema pickup_datetime, pickup_longitude AS pickuplon, pickup_latitude AS pickuplat, dropoff_longitude AS dropofflon, dropoff_latitude AS dropofflat, passenger_count AS passengers, -- taxirides.report_prediction_data schema ( tolls_amount + fare_amount ) AS fare_amount_871 --Be sure to add tolls_amount and fare_amount to fare_amount_871 as the target variable since total_amount includes tips. FROM `taxirides.historical_taxi_rides_raw` WHERE trip_distance > 0 AND fare_amount >= 2.5 -- GSP246 limiting of the distance the taxis travel out AND pickup_longitude > -75 AND pickup_longitude < -73 AND dropoff_longitude > -75 AND dropoff_longitude < -73 AND pickup_latitude > 40 AND pickup_latitude < 42 AND dropoff_latitude > 40 AND dropoff_latitude < 42 -- GSP246 limiting of the distance the taxis travel out AND passenger_count > 0 AND RAND() < 0.001 -- สุ่ม Row ที่จะเอาไป Training
Task 2: Create a BQML model
- ตอนสร้าง Model Feature เนื่องจากเวลาจำกัด
- ผมใช้วิธีเอาทั้งหมดก่อนตอน Transform *
- มันมี Guideline ว่าให้ทำ euclidean distance เติมเข้าไป
- เลยได้ Script มาประมาณนี้ครับ
CREATE OR REPLACE MODEL taxirides.fare_model_969
TRANSFORM(
*
, ST_Distance(ST_GeogPoint(pickuplon, pickuplat), ST_GeogPoint(dropofflon, dropofflat)) AS euclidean
)
OPTIONS(input_label_cols=['fare_amount_871'], model_type='linear_reg')
AS
SELECT * FROM taxirides.taxi_training_data_919- ตรวจสอบ Root Mean Squre
#standardSQL
SELECT
SQRT(mean_squared_error) AS rmse
FROM
ML.EVALUATE(MODEL taxirides.fare_model_969,
(
WITH
taxitrips AS (
SELECT
*,
ST_Distance(ST_GeogPoint(pickuplon, pickuplat), ST_GeogPoint(dropofflon, dropofflat)) AS euclidean
FROM
`taxirides.taxi_training_data_919` )
SELECT
*
FROM
taxitrips ))Task 3: Perform a batch prediction on new data
ผมลองง่ายๆ ตอนทำ Model เอาอะไรเป็น Input ตอน Test เอาแบบนั้น
CREATE OR REPLACE TABLE taxirides.2015_fare_amount_predictions
AS
SELECT * FROM ML.PREDICT(MODEL taxirides.fare_model_969,(
SELECT *
, ST_Distance(ST_GeogPoint(pickuplon, pickuplat), ST_GeogPoint(dropofflon, dropofflat)) AS euclidean
FROM taxirides.report_prediction_data)
)แต่ผมลองดู Result ใน BigQuery และมันแปลกๆ คิดว่า Model น่าจะมีปัญหาแล้ว ตัวระบบเหมือนจะดักว่ามี BigQuery ตามชื่อที่กำหนดเลยให้ผ่าน หรือจุดประสงค์ของ Challenge นี้ อาจจะเน้นการใช้งานเครื่องมือมากกว่าครับ และหลังจากลอง Google ไปเรื่อยๆ มี Lab ที่คล้ายกับ Challenge นี้ด้วย Predict Taxi Fare with a BigQuery ML Forecasting Model | Qwiklabs อันนี้เค้าจะลงพวก Feature ขัดเจน
Reference
Discover more from naiwaen@DebuggingSoft
Subscribe to get the latest posts sent to your email.



