/
model.py
1533 lines (1401 loc) · 66.5 KB
/
model.py
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import proto # type: ignore
from google.cloud.bigquery_v2.types import encryption_config
from google.cloud.bigquery_v2.types import model_reference as gcb_model_reference
from google.cloud.bigquery_v2.types import standard_sql
from google.cloud.bigquery_v2.types import table_reference
from google.protobuf import timestamp_pb2 # type: ignore
from google.protobuf import wrappers_pb2 # type: ignore
__protobuf__ = proto.module(
package="google.cloud.bigquery.v2",
manifest={
"Model",
"GetModelRequest",
"PatchModelRequest",
"DeleteModelRequest",
"ListModelsRequest",
"ListModelsResponse",
},
)
class Model(proto.Message):
r"""
Attributes:
etag (str):
Output only. A hash of this resource.
model_reference (google.cloud.bigquery_v2.types.ModelReference):
Required. Unique identifier for this model.
creation_time (int):
Output only. The time when this model was
created, in millisecs since the epoch.
last_modified_time (int):
Output only. The time when this model was
last modified, in millisecs since the epoch.
description (str):
Optional. A user-friendly description of this
model.
friendly_name (str):
Optional. A descriptive name for this model.
labels (Sequence[google.cloud.bigquery_v2.types.Model.LabelsEntry]):
The labels associated with this model. You
can use these to organize and group your models.
Label keys and values can be no longer than 63
characters, can only contain lowercase letters,
numeric characters, underscores and dashes.
International characters are allowed. Label
values are optional. Label keys must start with
a letter and each label in the list must have a
different key.
expiration_time (int):
Optional. The time when this model expires,
in milliseconds since the epoch. If not present,
the model will persist indefinitely. Expired
models will be deleted and their storage
reclaimed. The defaultTableExpirationMs
property of the encapsulating dataset can be
used to set a default expirationTime on newly
created models.
location (str):
Output only. The geographic location where
the model resides. This value is inherited from
the dataset.
encryption_configuration (google.cloud.bigquery_v2.types.EncryptionConfiguration):
Custom encryption configuration (e.g., Cloud
KMS keys). This shows the encryption
configuration of the model data while stored in
BigQuery storage. This field can be used with
PatchModel to update encryption key for an
already encrypted model.
model_type (google.cloud.bigquery_v2.types.Model.ModelType):
Output only. Type of the model resource.
training_runs (Sequence[google.cloud.bigquery_v2.types.Model.TrainingRun]):
Output only. Information for all training runs in increasing
order of start_time.
feature_columns (Sequence[google.cloud.bigquery_v2.types.StandardSqlField]):
Output only. Input feature columns that were
used to train this model.
label_columns (Sequence[google.cloud.bigquery_v2.types.StandardSqlField]):
Output only. Label columns that were used to train this
model. The output of the model will have a `predicted_`
prefix to these columns.
best_trial_id (int):
The best trial_id across all training runs.
"""
class ModelType(proto.Enum):
r"""Indicates the type of the Model."""
MODEL_TYPE_UNSPECIFIED = 0
LINEAR_REGRESSION = 1
LOGISTIC_REGRESSION = 2
KMEANS = 3
MATRIX_FACTORIZATION = 4
DNN_CLASSIFIER = 5
TENSORFLOW = 6
DNN_REGRESSOR = 7
BOOSTED_TREE_REGRESSOR = 9
BOOSTED_TREE_CLASSIFIER = 10
ARIMA = 11
AUTOML_REGRESSOR = 12
AUTOML_CLASSIFIER = 13
ARIMA_PLUS = 19
class LossType(proto.Enum):
r"""Loss metric to evaluate model training performance."""
LOSS_TYPE_UNSPECIFIED = 0
MEAN_SQUARED_LOSS = 1
MEAN_LOG_LOSS = 2
class DistanceType(proto.Enum):
r"""Distance metric used to compute the distance between two
points.
"""
DISTANCE_TYPE_UNSPECIFIED = 0
EUCLIDEAN = 1
COSINE = 2
class DataSplitMethod(proto.Enum):
r"""Indicates the method to split input data into multiple
tables.
"""
DATA_SPLIT_METHOD_UNSPECIFIED = 0
RANDOM = 1
CUSTOM = 2
SEQUENTIAL = 3
NO_SPLIT = 4
AUTO_SPLIT = 5
class DataFrequency(proto.Enum):
r"""Type of supported data frequency for time series forecasting
models.
"""
DATA_FREQUENCY_UNSPECIFIED = 0
AUTO_FREQUENCY = 1
YEARLY = 2
QUARTERLY = 3
MONTHLY = 4
WEEKLY = 5
DAILY = 6
HOURLY = 7
PER_MINUTE = 8
class HolidayRegion(proto.Enum):
r"""Type of supported holiday regions for time series forecasting
models.
"""
HOLIDAY_REGION_UNSPECIFIED = 0
GLOBAL = 1
NA = 2
JAPAC = 3
EMEA = 4
LAC = 5
AE = 6
AR = 7
AT = 8
AU = 9
BE = 10
BR = 11
CA = 12
CH = 13
CL = 14
CN = 15
CO = 16
CS = 17
CZ = 18
DE = 19
DK = 20
DZ = 21
EC = 22
EE = 23
EG = 24
ES = 25
FI = 26
FR = 27
GB = 28
GR = 29
HK = 30
HU = 31
ID = 32
IE = 33
IL = 34
IN = 35
IR = 36
IT = 37
JP = 38
KR = 39
LV = 40
MA = 41
MX = 42
MY = 43
NG = 44
NL = 45
NO = 46
NZ = 47
PE = 48
PH = 49
PK = 50
PL = 51
PT = 52
RO = 53
RS = 54
RU = 55
SA = 56
SE = 57
SG = 58
SI = 59
SK = 60
TH = 61
TR = 62
TW = 63
UA = 64
US = 65
VE = 66
VN = 67
ZA = 68
class LearnRateStrategy(proto.Enum):
r"""Indicates the learning rate optimization strategy to use."""
LEARN_RATE_STRATEGY_UNSPECIFIED = 0
LINE_SEARCH = 1
CONSTANT = 2
class OptimizationStrategy(proto.Enum):
r"""Indicates the optimization strategy used for training."""
OPTIMIZATION_STRATEGY_UNSPECIFIED = 0
BATCH_GRADIENT_DESCENT = 1
NORMAL_EQUATION = 2
class FeedbackType(proto.Enum):
r"""Indicates the training algorithm to use for matrix
factorization models.
"""
FEEDBACK_TYPE_UNSPECIFIED = 0
IMPLICIT = 1
EXPLICIT = 2
class SeasonalPeriod(proto.Message):
r"""
"""
class SeasonalPeriodType(proto.Enum):
r""""""
SEASONAL_PERIOD_TYPE_UNSPECIFIED = 0
NO_SEASONALITY = 1
DAILY = 2
WEEKLY = 3
MONTHLY = 4
QUARTERLY = 5
YEARLY = 6
class KmeansEnums(proto.Message):
r"""
"""
class KmeansInitializationMethod(proto.Enum):
r"""Indicates the method used to initialize the centroids for
KMeans clustering algorithm.
"""
KMEANS_INITIALIZATION_METHOD_UNSPECIFIED = 0
RANDOM = 1
CUSTOM = 2
KMEANS_PLUS_PLUS = 3
class RegressionMetrics(proto.Message):
r"""Evaluation metrics for regression and explicit feedback type
matrix factorization models.
Attributes:
mean_absolute_error (google.protobuf.wrappers_pb2.DoubleValue):
Mean absolute error.
mean_squared_error (google.protobuf.wrappers_pb2.DoubleValue):
Mean squared error.
mean_squared_log_error (google.protobuf.wrappers_pb2.DoubleValue):
Mean squared log error.
median_absolute_error (google.protobuf.wrappers_pb2.DoubleValue):
Median absolute error.
r_squared (google.protobuf.wrappers_pb2.DoubleValue):
R^2 score. This corresponds to r2_score in ML.EVALUATE.
"""
mean_absolute_error = proto.Field(
proto.MESSAGE, number=1, message=wrappers_pb2.DoubleValue,
)
mean_squared_error = proto.Field(
proto.MESSAGE, number=2, message=wrappers_pb2.DoubleValue,
)
mean_squared_log_error = proto.Field(
proto.MESSAGE, number=3, message=wrappers_pb2.DoubleValue,
)
median_absolute_error = proto.Field(
proto.MESSAGE, number=4, message=wrappers_pb2.DoubleValue,
)
r_squared = proto.Field(
proto.MESSAGE, number=5, message=wrappers_pb2.DoubleValue,
)
class AggregateClassificationMetrics(proto.Message):
r"""Aggregate metrics for classification/classifier models. For
multi-class models, the metrics are either macro-averaged or
micro-averaged. When macro-averaged, the metrics are calculated
for each label and then an unweighted average is taken of those
values. When micro-averaged, the metric is calculated globally
by counting the total number of correctly predicted rows.
Attributes:
precision (google.protobuf.wrappers_pb2.DoubleValue):
Precision is the fraction of actual positive
predictions that had positive actual labels. For
multiclass this is a macro-averaged metric
treating each class as a binary classifier.
recall (google.protobuf.wrappers_pb2.DoubleValue):
Recall is the fraction of actual positive
labels that were given a positive prediction.
For multiclass this is a macro-averaged metric.
accuracy (google.protobuf.wrappers_pb2.DoubleValue):
Accuracy is the fraction of predictions given
the correct label. For multiclass this is a
micro-averaged metric.
threshold (google.protobuf.wrappers_pb2.DoubleValue):
Threshold at which the metrics are computed.
For binary classification models this is the
positive class threshold. For multi-class
classfication models this is the confidence
threshold.
f1_score (google.protobuf.wrappers_pb2.DoubleValue):
The F1 score is an average of recall and
precision. For multiclass this is a macro-
averaged metric.
log_loss (google.protobuf.wrappers_pb2.DoubleValue):
Logarithmic Loss. For multiclass this is a
macro-averaged metric.
roc_auc (google.protobuf.wrappers_pb2.DoubleValue):
Area Under a ROC Curve. For multiclass this
is a macro-averaged metric.
"""
precision = proto.Field(
proto.MESSAGE, number=1, message=wrappers_pb2.DoubleValue,
)
recall = proto.Field(proto.MESSAGE, number=2, message=wrappers_pb2.DoubleValue,)
accuracy = proto.Field(
proto.MESSAGE, number=3, message=wrappers_pb2.DoubleValue,
)
threshold = proto.Field(
proto.MESSAGE, number=4, message=wrappers_pb2.DoubleValue,
)
f1_score = proto.Field(
proto.MESSAGE, number=5, message=wrappers_pb2.DoubleValue,
)
log_loss = proto.Field(
proto.MESSAGE, number=6, message=wrappers_pb2.DoubleValue,
)
roc_auc = proto.Field(
proto.MESSAGE, number=7, message=wrappers_pb2.DoubleValue,
)
class BinaryClassificationMetrics(proto.Message):
r"""Evaluation metrics for binary classification/classifier
models.
Attributes:
aggregate_classification_metrics (google.cloud.bigquery_v2.types.Model.AggregateClassificationMetrics):
Aggregate classification metrics.
binary_confusion_matrix_list (Sequence[google.cloud.bigquery_v2.types.Model.BinaryClassificationMetrics.BinaryConfusionMatrix]):
Binary confusion matrix at multiple
thresholds.
positive_label (str):
Label representing the positive class.
negative_label (str):
Label representing the negative class.
"""
class BinaryConfusionMatrix(proto.Message):
r"""Confusion matrix for binary classification models.
Attributes:
positive_class_threshold (google.protobuf.wrappers_pb2.DoubleValue):
Threshold value used when computing each of
the following metric.
true_positives (google.protobuf.wrappers_pb2.Int64Value):
Number of true samples predicted as true.
false_positives (google.protobuf.wrappers_pb2.Int64Value):
Number of false samples predicted as true.
true_negatives (google.protobuf.wrappers_pb2.Int64Value):
Number of true samples predicted as false.
false_negatives (google.protobuf.wrappers_pb2.Int64Value):
Number of false samples predicted as false.
precision (google.protobuf.wrappers_pb2.DoubleValue):
The fraction of actual positive predictions
that had positive actual labels.
recall (google.protobuf.wrappers_pb2.DoubleValue):
The fraction of actual positive labels that
were given a positive prediction.
f1_score (google.protobuf.wrappers_pb2.DoubleValue):
The equally weighted average of recall and
precision.
accuracy (google.protobuf.wrappers_pb2.DoubleValue):
The fraction of predictions given the correct
label.
"""
positive_class_threshold = proto.Field(
proto.MESSAGE, number=1, message=wrappers_pb2.DoubleValue,
)
true_positives = proto.Field(
proto.MESSAGE, number=2, message=wrappers_pb2.Int64Value,
)
false_positives = proto.Field(
proto.MESSAGE, number=3, message=wrappers_pb2.Int64Value,
)
true_negatives = proto.Field(
proto.MESSAGE, number=4, message=wrappers_pb2.Int64Value,
)
false_negatives = proto.Field(
proto.MESSAGE, number=5, message=wrappers_pb2.Int64Value,
)
precision = proto.Field(
proto.MESSAGE, number=6, message=wrappers_pb2.DoubleValue,
)
recall = proto.Field(
proto.MESSAGE, number=7, message=wrappers_pb2.DoubleValue,
)
f1_score = proto.Field(
proto.MESSAGE, number=8, message=wrappers_pb2.DoubleValue,
)
accuracy = proto.Field(
proto.MESSAGE, number=9, message=wrappers_pb2.DoubleValue,
)
aggregate_classification_metrics = proto.Field(
proto.MESSAGE, number=1, message="Model.AggregateClassificationMetrics",
)
binary_confusion_matrix_list = proto.RepeatedField(
proto.MESSAGE,
number=2,
message="Model.BinaryClassificationMetrics.BinaryConfusionMatrix",
)
positive_label = proto.Field(proto.STRING, number=3,)
negative_label = proto.Field(proto.STRING, number=4,)
class MultiClassClassificationMetrics(proto.Message):
r"""Evaluation metrics for multi-class classification/classifier
models.
Attributes:
aggregate_classification_metrics (google.cloud.bigquery_v2.types.Model.AggregateClassificationMetrics):
Aggregate classification metrics.
confusion_matrix_list (Sequence[google.cloud.bigquery_v2.types.Model.MultiClassClassificationMetrics.ConfusionMatrix]):
Confusion matrix at different thresholds.
"""
class ConfusionMatrix(proto.Message):
r"""Confusion matrix for multi-class classification models.
Attributes:
confidence_threshold (google.protobuf.wrappers_pb2.DoubleValue):
Confidence threshold used when computing the
entries of the confusion matrix.
rows (Sequence[google.cloud.bigquery_v2.types.Model.MultiClassClassificationMetrics.ConfusionMatrix.Row]):
One row per actual label.
"""
class Entry(proto.Message):
r"""A single entry in the confusion matrix.
Attributes:
predicted_label (str):
The predicted label. For confidence_threshold > 0, we will
also add an entry indicating the number of items under the
confidence threshold.
item_count (google.protobuf.wrappers_pb2.Int64Value):
Number of items being predicted as this
label.
"""
predicted_label = proto.Field(proto.STRING, number=1,)
item_count = proto.Field(
proto.MESSAGE, number=2, message=wrappers_pb2.Int64Value,
)
class Row(proto.Message):
r"""A single row in the confusion matrix.
Attributes:
actual_label (str):
The original label of this row.
entries (Sequence[google.cloud.bigquery_v2.types.Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry]):
Info describing predicted label distribution.
"""
actual_label = proto.Field(proto.STRING, number=1,)
entries = proto.RepeatedField(
proto.MESSAGE,
number=2,
message="Model.MultiClassClassificationMetrics.ConfusionMatrix.Entry",
)
confidence_threshold = proto.Field(
proto.MESSAGE, number=1, message=wrappers_pb2.DoubleValue,
)
rows = proto.RepeatedField(
proto.MESSAGE,
number=2,
message="Model.MultiClassClassificationMetrics.ConfusionMatrix.Row",
)
aggregate_classification_metrics = proto.Field(
proto.MESSAGE, number=1, message="Model.AggregateClassificationMetrics",
)
confusion_matrix_list = proto.RepeatedField(
proto.MESSAGE,
number=2,
message="Model.MultiClassClassificationMetrics.ConfusionMatrix",
)
class ClusteringMetrics(proto.Message):
r"""Evaluation metrics for clustering models.
Attributes:
davies_bouldin_index (google.protobuf.wrappers_pb2.DoubleValue):
Davies-Bouldin index.
mean_squared_distance (google.protobuf.wrappers_pb2.DoubleValue):
Mean of squared distances between each sample
to its cluster centroid.
clusters (Sequence[google.cloud.bigquery_v2.types.Model.ClusteringMetrics.Cluster]):
Information for all clusters.
"""
class Cluster(proto.Message):
r"""Message containing the information about one cluster.
Attributes:
centroid_id (int):
Centroid id.
feature_values (Sequence[google.cloud.bigquery_v2.types.Model.ClusteringMetrics.Cluster.FeatureValue]):
Values of highly variant features for this
cluster.
count (google.protobuf.wrappers_pb2.Int64Value):
Count of training data rows that were
assigned to this cluster.
"""
class FeatureValue(proto.Message):
r"""Representative value of a single feature within the cluster.
Attributes:
feature_column (str):
The feature column name.
numerical_value (google.protobuf.wrappers_pb2.DoubleValue):
The numerical feature value. This is the
centroid value for this feature.
categorical_value (google.cloud.bigquery_v2.types.Model.ClusteringMetrics.Cluster.FeatureValue.CategoricalValue):
The categorical feature value.
"""
class CategoricalValue(proto.Message):
r"""Representative value of a categorical feature.
Attributes:
category_counts (Sequence[google.cloud.bigquery_v2.types.Model.ClusteringMetrics.Cluster.FeatureValue.CategoricalValue.CategoryCount]):
Counts of all categories for the categorical feature. If
there are more than ten categories, we return top ten (by
count) and return one more CategoryCount with category
"*OTHER*" and count as aggregate counts of remaining
categories.
"""
class CategoryCount(proto.Message):
r"""Represents the count of a single category within the cluster.
Attributes:
category (str):
The name of category.
count (google.protobuf.wrappers_pb2.Int64Value):
The count of training samples matching the
category within the cluster.
"""
category = proto.Field(proto.STRING, number=1,)
count = proto.Field(
proto.MESSAGE, number=2, message=wrappers_pb2.Int64Value,
)
category_counts = proto.RepeatedField(
proto.MESSAGE,
number=1,
message="Model.ClusteringMetrics.Cluster.FeatureValue.CategoricalValue.CategoryCount",
)
feature_column = proto.Field(proto.STRING, number=1,)
numerical_value = proto.Field(
proto.MESSAGE,
number=2,
oneof="value",
message=wrappers_pb2.DoubleValue,
)
categorical_value = proto.Field(
proto.MESSAGE,
number=3,
oneof="value",
message="Model.ClusteringMetrics.Cluster.FeatureValue.CategoricalValue",
)
centroid_id = proto.Field(proto.INT64, number=1,)
feature_values = proto.RepeatedField(
proto.MESSAGE,
number=2,
message="Model.ClusteringMetrics.Cluster.FeatureValue",
)
count = proto.Field(
proto.MESSAGE, number=3, message=wrappers_pb2.Int64Value,
)
davies_bouldin_index = proto.Field(
proto.MESSAGE, number=1, message=wrappers_pb2.DoubleValue,
)
mean_squared_distance = proto.Field(
proto.MESSAGE, number=2, message=wrappers_pb2.DoubleValue,
)
clusters = proto.RepeatedField(
proto.MESSAGE, number=3, message="Model.ClusteringMetrics.Cluster",
)
class RankingMetrics(proto.Message):
r"""Evaluation metrics used by weighted-ALS models specified by
feedback_type=implicit.
Attributes:
mean_average_precision (google.protobuf.wrappers_pb2.DoubleValue):
Calculates a precision per user for all the
items by ranking them and then averages all the
precisions across all the users.
mean_squared_error (google.protobuf.wrappers_pb2.DoubleValue):
Similar to the mean squared error computed in
regression and explicit recommendation models
except instead of computing the rating directly,
the output from evaluate is computed against a
preference which is 1 or 0 depending on if the
rating exists or not.
normalized_discounted_cumulative_gain (google.protobuf.wrappers_pb2.DoubleValue):
A metric to determine the goodness of a
ranking calculated from the predicted confidence
by comparing it to an ideal rank measured by the
original ratings.
average_rank (google.protobuf.wrappers_pb2.DoubleValue):
Determines the goodness of a ranking by
computing the percentile rank from the predicted
confidence and dividing it by the original rank.
"""
mean_average_precision = proto.Field(
proto.MESSAGE, number=1, message=wrappers_pb2.DoubleValue,
)
mean_squared_error = proto.Field(
proto.MESSAGE, number=2, message=wrappers_pb2.DoubleValue,
)
normalized_discounted_cumulative_gain = proto.Field(
proto.MESSAGE, number=3, message=wrappers_pb2.DoubleValue,
)
average_rank = proto.Field(
proto.MESSAGE, number=4, message=wrappers_pb2.DoubleValue,
)
class ArimaForecastingMetrics(proto.Message):
r"""Model evaluation metrics for ARIMA forecasting models.
Attributes:
non_seasonal_order (Sequence[google.cloud.bigquery_v2.types.Model.ArimaOrder]):
Non-seasonal order.
arima_fitting_metrics (Sequence[google.cloud.bigquery_v2.types.Model.ArimaFittingMetrics]):
Arima model fitting metrics.
seasonal_periods (Sequence[google.cloud.bigquery_v2.types.Model.SeasonalPeriod.SeasonalPeriodType]):
Seasonal periods. Repeated because multiple
periods are supported for one time series.
has_drift (Sequence[bool]):
Whether Arima model fitted with drift or not.
It is always false when d is not 1.
time_series_id (Sequence[str]):
Id to differentiate different time series for
the large-scale case.
arima_single_model_forecasting_metrics (Sequence[google.cloud.bigquery_v2.types.Model.ArimaForecastingMetrics.ArimaSingleModelForecastingMetrics]):
Repeated as there can be many metric sets
(one for each model) in auto-arima and the
large-scale case.
"""
class ArimaSingleModelForecastingMetrics(proto.Message):
r"""Model evaluation metrics for a single ARIMA forecasting
model.
Attributes:
non_seasonal_order (google.cloud.bigquery_v2.types.Model.ArimaOrder):
Non-seasonal order.
arima_fitting_metrics (google.cloud.bigquery_v2.types.Model.ArimaFittingMetrics):
Arima fitting metrics.
has_drift (bool):
Is arima model fitted with drift or not. It
is always false when d is not 1.
time_series_id (str):
The time_series_id value for this time series. It will be
one of the unique values from the time_series_id_column
specified during ARIMA model training. Only present when
time_series_id_column training option was used.
time_series_ids (Sequence[str]):
The tuple of time_series_ids identifying this time series.
It will be one of the unique tuples of values present in the
time_series_id_columns specified during ARIMA model
training. Only present when time_series_id_columns training
option was used and the order of values here are same as the
order of time_series_id_columns.
seasonal_periods (Sequence[google.cloud.bigquery_v2.types.Model.SeasonalPeriod.SeasonalPeriodType]):
Seasonal periods. Repeated because multiple
periods are supported for one time series.
has_holiday_effect (google.protobuf.wrappers_pb2.BoolValue):
If true, holiday_effect is a part of time series
decomposition result.
has_spikes_and_dips (google.protobuf.wrappers_pb2.BoolValue):
If true, spikes_and_dips is a part of time series
decomposition result.
has_step_changes (google.protobuf.wrappers_pb2.BoolValue):
If true, step_changes is a part of time series decomposition
result.
"""
non_seasonal_order = proto.Field(
proto.MESSAGE, number=1, message="Model.ArimaOrder",
)
arima_fitting_metrics = proto.Field(
proto.MESSAGE, number=2, message="Model.ArimaFittingMetrics",
)
has_drift = proto.Field(proto.BOOL, number=3,)
time_series_id = proto.Field(proto.STRING, number=4,)
time_series_ids = proto.RepeatedField(proto.STRING, number=9,)
seasonal_periods = proto.RepeatedField(
proto.ENUM, number=5, enum="Model.SeasonalPeriod.SeasonalPeriodType",
)
has_holiday_effect = proto.Field(
proto.MESSAGE, number=6, message=wrappers_pb2.BoolValue,
)
has_spikes_and_dips = proto.Field(
proto.MESSAGE, number=7, message=wrappers_pb2.BoolValue,
)
has_step_changes = proto.Field(
proto.MESSAGE, number=8, message=wrappers_pb2.BoolValue,
)
non_seasonal_order = proto.RepeatedField(
proto.MESSAGE, number=1, message="Model.ArimaOrder",
)
arima_fitting_metrics = proto.RepeatedField(
proto.MESSAGE, number=2, message="Model.ArimaFittingMetrics",
)
seasonal_periods = proto.RepeatedField(
proto.ENUM, number=3, enum="Model.SeasonalPeriod.SeasonalPeriodType",
)
has_drift = proto.RepeatedField(proto.BOOL, number=4,)
time_series_id = proto.RepeatedField(proto.STRING, number=5,)
arima_single_model_forecasting_metrics = proto.RepeatedField(
proto.MESSAGE,
number=6,
message="Model.ArimaForecastingMetrics.ArimaSingleModelForecastingMetrics",
)
class EvaluationMetrics(proto.Message):
r"""Evaluation metrics of a model. These are either computed on
all training data or just the eval data based on whether eval
data was used during training. These are not present for
imported models.
Attributes:
regression_metrics (google.cloud.bigquery_v2.types.Model.RegressionMetrics):
Populated for regression models and explicit
feedback type matrix factorization models.
binary_classification_metrics (google.cloud.bigquery_v2.types.Model.BinaryClassificationMetrics):
Populated for binary
classification/classifier models.
multi_class_classification_metrics (google.cloud.bigquery_v2.types.Model.MultiClassClassificationMetrics):
Populated for multi-class
classification/classifier models.
clustering_metrics (google.cloud.bigquery_v2.types.Model.ClusteringMetrics):
Populated for clustering models.
ranking_metrics (google.cloud.bigquery_v2.types.Model.RankingMetrics):
Populated for implicit feedback type matrix
factorization models.
arima_forecasting_metrics (google.cloud.bigquery_v2.types.Model.ArimaForecastingMetrics):
Populated for ARIMA models.
"""
regression_metrics = proto.Field(
proto.MESSAGE, number=1, oneof="metrics", message="Model.RegressionMetrics",
)
binary_classification_metrics = proto.Field(
proto.MESSAGE,
number=2,
oneof="metrics",
message="Model.BinaryClassificationMetrics",
)
multi_class_classification_metrics = proto.Field(
proto.MESSAGE,
number=3,
oneof="metrics",
message="Model.MultiClassClassificationMetrics",
)
clustering_metrics = proto.Field(
proto.MESSAGE, number=4, oneof="metrics", message="Model.ClusteringMetrics",
)
ranking_metrics = proto.Field(
proto.MESSAGE, number=5, oneof="metrics", message="Model.RankingMetrics",
)
arima_forecasting_metrics = proto.Field(
proto.MESSAGE,
number=6,
oneof="metrics",
message="Model.ArimaForecastingMetrics",
)
class DataSplitResult(proto.Message):
r"""Data split result. This contains references to the training
and evaluation data tables that were used to train the model.
Attributes:
training_table (google.cloud.bigquery_v2.types.TableReference):
Table reference of the training data after
split.
evaluation_table (google.cloud.bigquery_v2.types.TableReference):
Table reference of the evaluation data after
split.
"""
training_table = proto.Field(
proto.MESSAGE, number=1, message=table_reference.TableReference,
)
evaluation_table = proto.Field(
proto.MESSAGE, number=2, message=table_reference.TableReference,
)
class ArimaOrder(proto.Message):
r"""Arima order, can be used for both non-seasonal and seasonal
parts.
Attributes:
p (int):
Order of the autoregressive part.
d (int):
Order of the differencing part.
q (int):
Order of the moving-average part.
"""
p = proto.Field(proto.INT64, number=1,)
d = proto.Field(proto.INT64, number=2,)
q = proto.Field(proto.INT64, number=3,)
class ArimaFittingMetrics(proto.Message):
r"""ARIMA model fitting metrics.
Attributes:
log_likelihood (float):
Log-likelihood.
aic (float):
AIC.
variance (float):
Variance.
"""
log_likelihood = proto.Field(proto.DOUBLE, number=1,)
aic = proto.Field(proto.DOUBLE, number=2,)
variance = proto.Field(proto.DOUBLE, number=3,)
class GlobalExplanation(proto.Message):
r"""Global explanations containing the top most important
features after training.
Attributes:
explanations (Sequence[google.cloud.bigquery_v2.types.Model.GlobalExplanation.Explanation]):
A list of the top global explanations. Sorted
by absolute value of attribution in descending
order.
class_label (str):
Class label for this set of global
explanations. Will be empty/null for binary
logistic and linear regression models. Sorted
alphabetically in descending order.
"""
class Explanation(proto.Message):
r"""Explanation for a single feature.
Attributes:
feature_name (str):
Full name of the feature. For non-numerical features, will
be formatted like <column_name>.<encoded_feature_name>.
Overall size of feature name will always be truncated to
first 120 characters.
attribution (google.protobuf.wrappers_pb2.DoubleValue):
Attribution of feature.
"""
feature_name = proto.Field(proto.STRING, number=1,)
attribution = proto.Field(
proto.MESSAGE, number=2, message=wrappers_pb2.DoubleValue,
)
explanations = proto.RepeatedField(
proto.MESSAGE, number=1, message="Model.GlobalExplanation.Explanation",
)
class_label = proto.Field(proto.STRING, number=2,)
class TrainingRun(proto.Message):
r"""Information about a single training query run for the model.
Attributes:
training_options (google.cloud.bigquery_v2.types.Model.TrainingRun.TrainingOptions):
Options that were used for this training run,
includes user specified and default options that
were used.
start_time (google.protobuf.timestamp_pb2.Timestamp):
The start time of this training run.
results (Sequence[google.cloud.bigquery_v2.types.Model.TrainingRun.IterationResult]):
Output of each iteration run, results.size() <=
max_iterations.
evaluation_metrics (google.cloud.bigquery_v2.types.Model.EvaluationMetrics):
The evaluation metrics over training/eval
data that were computed at the end of training.
data_split_result (google.cloud.bigquery_v2.types.Model.DataSplitResult):
Data split result of the training run. Only
set when the input data is actually split.
global_explanations (Sequence[google.cloud.bigquery_v2.types.Model.GlobalExplanation]):
Global explanations for important features of
the model. For multi-class models, there is one
entry for each label class. For other models,
there is only one entry in the list.
"""
class TrainingOptions(proto.Message):
r"""Options used in model training.
Attributes:
max_iterations (int):
The maximum number of iterations in training.
Used only for iterative training algorithms.
loss_type (google.cloud.bigquery_v2.types.Model.LossType):
Type of loss function used during training
run.
learn_rate (float):
Learning rate in training. Used only for
iterative training algorithms.
l1_regularization (google.protobuf.wrappers_pb2.DoubleValue):
L1 regularization coefficient.
l2_regularization (google.protobuf.wrappers_pb2.DoubleValue):
L2 regularization coefficient.
min_relative_progress (google.protobuf.wrappers_pb2.DoubleValue):
When early_stop is true, stops training when accuracy
improvement is less than 'min_relative_progress'. Used only
for iterative training algorithms.
warm_start (google.protobuf.wrappers_pb2.BoolValue):
Whether to train a model from the last
checkpoint.
early_stop (google.protobuf.wrappers_pb2.BoolValue):
Whether to stop early when the loss doesn't improve
significantly any more (compared to min_relative_progress).
Used only for iterative training algorithms.
input_label_columns (Sequence[str]):
Name of input label columns in training data.
data_split_method (google.cloud.bigquery_v2.types.Model.DataSplitMethod):
The data split type for training and
evaluation, e.g. RANDOM.
data_split_eval_fraction (float):
The fraction of evaluation data over the
whole input data. The rest of data will be used
as training data. The format should be double.
Accurate to two decimal places.
Default value is 0.2.
data_split_column (str):
The column to split data with. This column won't be used as
a feature.
1. When data_split_method is CUSTOM, the corresponding
column should be boolean. The rows with true value tag
are eval data, and the false are training data.
2. When data_split_method is SEQ, the first
DATA_SPLIT_EVAL_FRACTION rows (from smallest to largest)
in the corresponding column are used as training data,