-
Notifications
You must be signed in to change notification settings - Fork 1
/
ml-bq-linear-regression.sql
52 lines (50 loc) · 1.52 KB
/
ml-bq-linear-regression.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
create or replace model `analytics-bootcamp-323516.week1.fare_est`
OPTIONS(model_type = 'linear_reg', input_label_cols=['dep_y'],enable_global_explain=TRUE) as
select
vendor_id,
-- trip_distance,
sqrt(POW(dropoff_latitude - pickup_latitude,2 ) + POW(dropoff_longitude - pickup_longitude,2 )) as estimated_distance_euc,
abs(dropoff_latitude - pickup_latitude) + abs(dropoff_longitude - pickup_longitude) as estimated_distance_man,
extract(hour
from
pickup_datetime) as hh24,
payment_type,
dropoff_longitude as lon,
dropoff_latitude as lat,
dropoff_longitude * dropoff_latitude as lonlat,
passenger_count,
fare_amount + tolls_amount as dep_y
from
`analytics-bootcamp-323516.week1.trips_2015`
TABLESAMPLE
SYSTEM(1
PERCENT)
LIMIT
10000;
select
*
from
ML.GLOBAL_EXPLAIN(MODEL `analytics-bootcamp-323516.week1.fare_est`);
select
*
from
ML.EXPLAIN_PREDICT(MODEL `analytics-bootcamp-323516.week1.fare_est`,
(
select
vendor_id,
-- trip_distance,
sqrt(POW(dropoff_latitude - pickup_latitude,2 ) + POW(dropoff_longitude - pickup_longitude,2 )) as estimated_distance_euc,
abs(dropoff_latitude - pickup_latitude) + abs(dropoff_longitude - pickup_longitude) as estimated_distance_man,
extract(hour
from
pickup_datetime) as hh24,
payment_type,
dropoff_longitude as lon,
dropoff_latitude as lat,
dropoff_longitude * dropoff_latitude as lonlat,
passenger_count,
fare_amount + tolls_amount as dep_y
from
`analytics-bootcamp-323516.week1.trips_2015`
limit 10),
STRUCT(3 as top_k_features));