Predicting the probability of conversion from features using BigQuery ML.
To predict the probability of conversion using BigQuery ML, you would need to adjust your problem formulation and use logistic regression instead of linear regression. Here's how you can modify the previous example:
Ensure your table schema includes a binary conversion outcome (1 for converted, 0 for not converted):
season (STRING)
num_clicks (INTEGER)
feature_1 (FLOAT64)
feature_2 (FLOAT64)
converted (INTEGER)
Create a logistic regression model using BigQuery ML:
CREATE OR REPLACE MODEL `your_project_id.your_dataset.conversion_probability_model`
OPTIONS(model_type="logistic_reg") AS
SELECT
season,
num_clicks,
feature_1,
feature_2,
converted
FROM
`your_project_id.your_dataset.your_table`;
- Evaluate the model's performance using the
ML.EVALUATE
function:
SELECT
*
FROM
ML.EVALUATE(MODEL `your_project_id.your_dataset.conversion_probability_model`,
(
SELECT
season,
num_clicks,
feature_1,
feature_2,
converted
FROM
`your_project_id.your_dataset.your_table`));
- Use the
ML.PREDICT
function to predict the probability of conversion:
SELECT
season,
num_clicks,
feature_1,
feature_2,
predicted_converted_probs
FROM
ML.PREDICT(MODEL `your_project_id.your_dataset.conversion_probability_model`,
(
SELECT
season,
num_clicks,
feature_1,
feature_2
FROM
`your_project_id.your_dataset.your_table`));
This will return the predicted probability of conversion for each row in your table, along with the input features. Remember to replace your_project_id
, your_dataset
, and your_table
with the appropriate values from your Google BigQuery environment.