Model selection guied
spatial queries
https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions
date queries
https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions
hyperparameter tuning
https://cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-hyperparameter-tuning
model export
https://cloud.google.com/bigquery/docs/exporting-models#export_model_formats_and_samples
code
{CREATE MODEL | CREATE MODEL IF NOT EXISTS | CREATE OR REPLACE MODEL}
model_name
[OPTIONS(MODEL_TYPE = { 'LINEAR_REG' | 'LOGISTIC_REG' },
INPUT_LABEL_COLS = string_array,
OPTIMIZE_STRATEGY = { 'AUTO_STRATEGY' | 'BATCH_GRADIENT_DESCENT' | 'NORMAL_EQUATION' },
L1_REG = float64_value,
L2_REG = float64_value,
MAX_ITERATIONS = int64_value,
LEARN_RATE_STRATEGY = { 'LINE_SEARCH' | 'CONSTANT' },
LEARN_RATE = float64_value,
EARLY_STOP = { TRUE | FALSE },
MIN_REL_PROGRESS = float64_value,
DATA_SPLIT_METHOD = { 'AUTO_SPLIT' | 'RANDOM' | 'CUSTOM' | 'SEQ' | 'NO_SPLIT' },
DATA_SPLIT_EVAL_FRACTION = float64_value,
DATA_SPLIT_COL = string_value,
LS_INIT_LEARN_RATE = float64_value,
WARM_START = { TRUE | FALSE },
AUTO_CLASS_WEIGHTS = { TRUE | FALSE },
CLASS_WEIGHTS = struct_array,
ENABLE_GLOBAL_EXPLAIN = { TRUE | FALSE },
CALCULATE_P_VALUES = { TRUE | FALSE },
FIT_INTERCEPT = { TRUE | FALSE },
CATEGORY_ENCODING_METHOD = { 'ONE_HOT_ENCODING`, 'DUMMY_ENCODING' }
)];
limitations
- applicable to only numerical attributes
- not perform well when clusters are varying sizes and density
- needs clipping of the outliers
tips
- anormally detection
code
{CREATE MODEL | CREATE MODEL IF NOT EXISTS | CREATE OR REPLACE MODEL}
model_name
[OPTIONS(MODEL_TYPE = { 'KMEANS' },
NUM_CLUSTERS = int64_value,
KMEANS_INIT_METHOD = { 'RANDOM' | 'KMEANS++' | 'CUSTOM' },
KMEANS_INIT_COL = string_value,
DISTANCE_TYPE = { 'EUCLIDEAN' | 'COSINE' },
STANDARDIZE_FEATURES = { TRUE | FALSE },
MAX_ITERATIONS = int64_value,
EARLY_STOP = { TRUE | FALSE },
MIN_REL_PROGRESS = float64_value,
WARM_START = { TRUE | FALSE }
)];
types
- adaptive boosting
- gradient boosting
- XGBoost
tips
- no need to do feature selection but have to do feature engineering
XGBoost parameter
https://xgboost.readthedocs.io/en/latest/parameter.html#parameters-for-tree-booster
code
{CREATE MODEL | CREATE MODEL IF NOT EXISTS | CREATE OR REPLACE MODEL} model_name
[OPTIONS(MODEL_TYPE = { 'BOOSTED_TREE_CLASSIFIER' | 'BOOSTED_TREE_REGRESSOR' },
BOOSTER_TYPE = {'GBTREE' | 'DART'},
NUM_PARALLEL_TREE = int64_value,
DART_NORMALIZE_TYPE = {'TREE' | 'FOREST'},
TREE_METHOD = {'AUTO' | 'EXACT' | 'APPROX' | 'HIST'},
MIN_TREE_CHILD_WEIGHT = int64_value,
COLSAMPLE_BYTREE = float64_value,
COLSAMPLE_BYLEVEL = float64_value,
COLSAMPLE_BYNODE = float64_value,
MIN_SPLIT_LOSS = float64_value,
MAX_TREE_DEPTH = int64_value,
SUBSAMPLE = float64_value,
AUTO_CLASS_WEIGHTS = { TRUE | FALSE },
CLASS_WEIGHTS = struct_array,
INSTANCE_WEIGHT_COL = string_value,
L1_REG = float64_value,
L2_REG = float64_value,
EARLY_STOP = { TRUE | FALSE },
LEARN_RATE = float64_value,
INPUT_LABEL_COLS = string_array,
MAX_ITERATIONS = int64_value,
MIN_REL_PROGRESS = float64_value,
DATA_SPLIT_METHOD = { 'AUTO_SPLIT' | 'RANDOM' | 'CUSTOM' | 'SEQ' | 'NO_SPLIT' },
DATA_SPLIT_EVAL_FRACTION = float64_value,
DATA_SPLIT_COL = string_value,
ENABLE_GLOBAL_EXPLAIN = { TRUE | FALSE },
XGBOOST_VERSION = { '0.9' | '1.1' }
)];
Sigmoid function
- vanishing gradient problem
RELU function
- less vulnerable vanishing pradient problem
{CREATE MODEL | CREATE MODEL IF NOT EXISTS | CREATE OR REPLACE MODEL} model_name
[OPTIONS(MODEL_TYPE = { 'DNN_CLASSIFIER' | 'DNN_REGRESSOR' },
ACTIVATION_FN = { 'RELU' | 'RELU6' | 'CRELU' | 'ELU' | 'SELU' | 'SIGMOID' | 'TANH' },
AUTO_CLASS_WEIGHTS = { TRUE | FALSE },
BATCH_SIZE = int64_value,
CLASS_WEIGHTS = struct_array,
DROPOUT = float64_value,
EARLY_STOP = { TRUE | FALSE },
HIDDEN_UNITS = int_array,
L1_REG = float64_value,
L2_REG = float64_value,
LEARN_RATE = float64_value,
INPUT_LABEL_COLS = string_array,
MAX_ITERATIONS = int64_value,
MIN_REL_PROGRESS = float64_value,
OPTIMIZER = { 'ADAGRAD' | 'ADAM' | 'FTRL' | 'RMSPROP' | 'SGD' },
WARM_START = { TRUE | FALSE },
DATA_SPLIT_METHOD = { 'AUTO_SPLIT' | 'RANDOM' | 'CUSTOM' | 'SEQ' | 'NO_SPLIT' },
DATA_SPLIT_EVAL_FRACTION = float64_value,
DATA_SPLIT_COL = string_value,
ENABLE_GLOBAL_EXPLAIN = { TRUE | FALSE },
INTEGRATED_GRADIENTS_NUM_STEPS = int64_value,
TF_VERSION = { '1.15' | '2.8.0' }
)];
concept
- lower the demiesion to avoid overfitting
{CREATE MODEL | CREATE MODEL IF NOT EXISTS | CREATE OR REPLACE MODEL}
model_name
[OPTIONS(MODEL_TYPE = { 'PCA' },
NUM_PRINCIPAL_COMPONENTS = int64_value,
PCA_EXPLAINED_VARIANCE_RATIO = float64_value,
SCALE_FEATURES = { TRUE | FALSE }
PCA_SOLVER = { 'FULL' | 'RANDOMIZED' | 'AUTO' },
)];