# How can I improve my predictions? My rank is not going up.
### Feature selection
- try selecting the features that you think are most important to the model

### Model selection and hyperparameter tuning
- have you tried choosing different classification models? have you tried tuning some of its hyperparameters? Check out the docs on each of the models below:
 - [`logistic_reg`](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-create)
 - [`boosted_tree_classifier`](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-create-boosted-tree)
 - [`dnn_classifier`](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-create-dnn-models)
 - [`automl_classifier`](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-create-automl)

### Feature engineering
- could the day of week have an impact on purchasing patterns? use the [EXTRACT](https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#extract) function to retrieve the year/month/day/hour/minute/etc. from a TIMESTAMP column
- can you multiple, divide, add, or subtract numerical features to create new features?
- can you augment the weight of outliers by squaring numerical features, or on the other hand, taking the square root?
- could combinations of features impact purchasing patterns more than individual columns? You can use [ML.FEATURE_CROSS](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-preprocessing-functions#mlfeature_cross) to create interactions on category variables 
- would it help to scale quantitative variables using [ML.STANDARD_SCALER](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-preprocessing-functions#mlstandard_scaler)?
- are numerical features too granular? Could you bucketize them using [ML.QUANTILE_BUCKETIZE](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-preprocessing-functions#quantile_bucketize)?
- check out all of the [pre-processing features built into BigQuery ML](https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-preprocessing-functions)


### Ensembling models
- the combination of multiple model outputs may be better than any single model alone. As a simple example, you can try to take the mean/median of the probability outputs of ML.PREDICT across multiple models. For example, for a specific fullVisitorId, if model_1 and model_2 predict 0.5 and 1.0 respectively, then the averaged prediction would be 0.75.

```
## Ensemble two models (model_a, model_b) by averaging their predictions
WITH pred1 AS (
  SELECT
    sessionId, 
    prob as addedToCart
  FROM
    ML.PREDICT(MODEL bqmlretail.model_a, ## replace model name
      (
      SELECT 
        CONCAT(fullVisitorId, CAST(visitStartTime as string)) as sessionId, 
        *
      FROM
      `kaggleworkshops.google_analytics_sample_eu.test`
    )),
  UNNEST(predicted_addedToCart_probs)
  WHERE label = 1),
  
  pred2 AS (
  
  SELECT
    sessionId, 
    prob as addedToCart
  FROM
    ML.PREDICT(MODEL bqmlretail.model_b, ## replace model name
      (
      SELECT 
        CONCAT(fullVisitorId, CAST(visitStartTime as string)) as sessionId, 
        *
      FROM
      `kaggleworkshops.google_analytics_sample_eu.test`
    )),
  UNNEST(predicted_addedToCart_probs)
  WHERE label = 1)

SELECT
  sessionId,
  AVG(addedToCart) addedToCart
FROM (
  SELECT
    *
  FROM pred1
  UNION ALL
  SELECT
    *
  FROM pred2
  )
GROUP BY sessionId
```
