-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpredictions.view.lkml
206 lines (198 loc) · 6.53 KB
/
predictions.view.lkml
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
######################## TRAINING/TESTING INPUTS #############################
view: training_input {
derived_table: {
explore_source: ga_sessions {
column: visitId {}
column: fullVisitorId {}
column: medium { field: trafficSource.medium }
column: channelGrouping {}
column: isMobile { field: device.isMobile }
column: country { field: geoNetwork.country }
column: bounces_total { field: totals.bounces_total }
column: pageviews_total { field: totals.pageviews_total }
column: transactions_count { field: totals.transactions_count }
column: first_time_visitors {}
column: will_purchase_in_future {}
filters: {
field: ga_sessions.partition_date
value: "900 days ago for 360 days"
}
filters: {
field: ga_sessions.prediction_window_days
value: "180"
}
}
}
}
view: testing_input {
derived_table: {
explore_source: ga_sessions {
column: visitId {}
column: fullVisitorId {}
column: medium { field: trafficSource.medium }
column: channelGrouping {}
column: isMobile { field: device.isMobile }
column: country { field: geoNetwork.country }
column: bounces_total { field: totals.bounces_total }
column: pageviews_total { field: totals.pageviews_total }
column: transactions_count { field: totals.transactions_count }
column: first_time_visitors {}
column: will_purchase_in_future {}
filters: {
field: ga_sessions.partition_date
value: "540 days ago for 180 days"
}
filters: {
field: ga_sessions.prediction_window_days
value: "180"
}
}
}
}
######################## MODEL #############################
view: future_purchase_model {
derived_table: {
datagroup_trigger: bqml_datagroup
sql_create:
CREATE OR REPLACE MODEL ${SQL_TABLE_NAME}
OPTIONS(model_type='logistic_reg'
, labels=['will_purchase_in_future']
) AS
SELECT
* EXCEPT(fullVisitorId, visitId)
FROM ${training_input.SQL_TABLE_NAME};;
}
}
######################## TRAINING INFORMATION #############################
explore: future_purchase_model_evaluation {}
explore: future_purchase_model_training_info {}
explore: roc_curve {}
# VIEWS:
view: future_purchase_model_evaluation {
derived_table: {
sql: SELECT * FROM ml.EVALUATE(
MODEL ${future_purchase_model.SQL_TABLE_NAME},
(SELECT * FROM ${testing_input.SQL_TABLE_NAME}));;
}
dimension: recall {type: number value_format_name:percent_2}
dimension: accuracy {type: number value_format_name:percent_2}
dimension: f1_score {type: number value_format_name:percent_3}
dimension: log_loss {type: number}
dimension: roc_auc {type: number}
}
view: roc_curve {
derived_table: {
sql: SELECT * FROM ml.ROC_CURVE(
MODEL ${future_purchase_model.SQL_TABLE_NAME},
(SELECT * FROM ${testing_input.SQL_TABLE_NAME}));;
}
dimension: threshold {
type: number
link: {
label: "Likely Customers to Purchase"
url: "/explore/bqml_ga_demo/ga_sessions?fields=ga_sessions.fullVisitorId,future_purchase_prediction.max_predicted_score&f[future_purchase_prediction.predicted_will_purchase_in_future]=%3E%3D{{value}}"
icon_url: "http://www.looker.com/favicon.ico"
}
}
dimension: recall {type: number value_format_name: percent_2}
dimension: false_positive_rate {type: number}
dimension: true_positives {type: number }
dimension: false_positives {type: number}
dimension: true_negatives {type: number}
dimension: false_negatives {type: number }
dimension: precision {
type: number
value_format_name: percent_2
sql: ${true_positives} / NULLIF((${true_positives} + ${false_positives}),0);;
}
measure: total_false_positives {
type: sum
sql: ${false_positives} ;;
}
measure: total_true_positives {
type: sum
sql: ${true_positives} ;;
}
dimension: threshold_accuracy {
type: number
value_format_name: percent_2
sql: 1.0*(${true_positives} + ${true_negatives}) / NULLIF((${true_positives} + ${true_negatives} + ${false_positives} + ${false_negatives}),0);;
}
dimension: threshold_f1 {
type: number
value_format_name: percent_3
sql: 2.0*${recall}*${precision} / NULLIF((${recall}+${precision}),0);;
}
}
view: future_purchase_model_training_info {
derived_table: {
sql: SELECT * FROM ml.TRAINING_INFO(MODEL ${future_purchase_model.SQL_TABLE_NAME});;
}
dimension: training_run {type: number}
dimension: iteration {type: number}
dimension: loss_raw {sql: ${TABLE}.loss;; type: number hidden:yes}
dimension: eval_loss {type: number}
dimension: duration_ms {label:"Duration (ms)" type: number}
dimension: learning_rate {type: number}
measure: total_iterations {
type: count
}
measure: loss {
value_format_name: decimal_2
type: sum
sql: ${loss_raw} ;;
}
measure: total_training_time {
type: sum
label:"Total Training Time (sec)"
sql: ${duration_ms}/1000 ;;
value_format_name: decimal_1
}
measure: average_iteration_time {
type: average
label:"Average Iteration Time (sec)"
sql: ${duration_ms}/1000 ;;
value_format_name: decimal_1
}
}
########################################## PREDICT FUTURE ############################
view: future_input {
derived_table: {
explore_source: ga_sessions {
column: visitId {}
column: fullVisitorId {}
column: medium { field: trafficSource.medium }
column: channelGrouping {}
column: isMobile { field: device.isMobile }
column: country { field: geoNetwork.country }
column: bounces_total { field: totals.bounces_total }
column: pageviews_total { field: totals.pageviews_total }
column: transactions_count { field: totals.transactions_count }
column: first_time_visitors {}
filters: {
field: ga_sessions.partition_date
value: "360 days"
}
}
}
}
view: future_purchase_prediction {
derived_table: {
sql: SELECT * FROM ml.PREDICT(
MODEL ${future_purchase_model.SQL_TABLE_NAME},
(SELECT * FROM ${future_input.SQL_TABLE_NAME}));;
}
dimension: predicted_will_purchase_in_future {type: number}
dimension: visitId {type: number hidden:yes}
dimension: fullVisitorId {type: number hidden: yes}
measure: max_predicted_score {
type: max
value_format_name: percent_2
sql: ${predicted_will_purchase_in_future} ;;
}
measure: average_predicted_score {
type: average
value_format_name: percent_2
sql: ${predicted_will_purchase_in_future} ;;
}
}