From 221374b979c185b92aee2487797c626cee47c3fd Mon Sep 17 00:00:00 2001 From: Daniela Date: Thu, 14 Nov 2024 18:25:10 +0000 Subject: [PATCH 1/4] must verify evaluation_data and edit Output --- .../classification_boosted_tree_model_test.py | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/samples/snippets/classification_boosted_tree_model_test.py b/samples/snippets/classification_boosted_tree_model_test.py index fbc9369dde..6f41aa2ca0 100644 --- a/samples/snippets/classification_boosted_tree_model_test.py +++ b/samples/snippets/classification_boosted_tree_model_test.py @@ -14,7 +14,7 @@ def test_boosted_tree_model(random_model_id: str) -> None: - # your_model_id = random_model_id + your_model_id = random_model_id # [START bigquery_dataframes_bqml_boosted_tree_prepare] import bigframes.pandas as bpd @@ -38,5 +38,28 @@ def test_boosted_tree_model(random_model_id: str) -> None: ] ) del input_data["functional_weight"] - # [END bigquery_dataframes_bqml_boosted_tree_prepare] + # [END bigquery_dataframes_bqml_boosted_tree_prepare] # [START bigquery_dataframes_bqml_boosted_tree_explain] + # Select model you'll use for predictions. `read_gbq_model` loads model + # data from BigQuery, but you could also use the `tree_model` object + # from previous steps. + tree_model = bpd.read_gbq_model( + your_model_id, # For example: "your-project.bqml_tutorial.tree_model" + ) + + # input_data is defined in an earlier step. + evaluation_data = input_data[input_data["dataframe"] == "evaluation"] + X = evaluation_data.drop(columns=["income_bracket", "dataframe"]) + y = evaluation_data["income_bracket"] + + # The score() method evaluates how the model performs compared to the + # actual data. Output DataFrame matches that of ML.EVALUATE(). + score = tree_model.score(X, y) + score.peek() + # Output: + # precision recall accuracy f1_score log_loss roc_auc + # 0 0.671924 0.578804 0.839429 0.621897 0.344054 0.887335 + # [END bigquery_dataframes_bqml_boosted_tree_explain] assert input_data is not None + assert tree_model is not None + assert evaluation_data is not None + assert score is not None From 265bfd61214baaf7ccd8ea8a1c9a2af113fa0f5c Mon Sep 17 00:00:00 2001 From: Daniela Date: Thu, 14 Nov 2024 18:31:03 +0000 Subject: [PATCH 2/4] line edit --- samples/snippets/classification_boosted_tree_model_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/snippets/classification_boosted_tree_model_test.py b/samples/snippets/classification_boosted_tree_model_test.py index 6f41aa2ca0..faecc21f0d 100644 --- a/samples/snippets/classification_boosted_tree_model_test.py +++ b/samples/snippets/classification_boosted_tree_model_test.py @@ -38,7 +38,8 @@ def test_boosted_tree_model(random_model_id: str) -> None: ] ) del input_data["functional_weight"] - # [END bigquery_dataframes_bqml_boosted_tree_prepare] # [START bigquery_dataframes_bqml_boosted_tree_explain] + # [END bigquery_dataframes_bqml_boosted_tree_prepare] + # [START bigquery_dataframes_bqml_boosted_tree_explain] # Select model you'll use for predictions. `read_gbq_model` loads model # data from BigQuery, but you could also use the `tree_model` object # from previous steps. From 17e7170b5554e826a3e46e9ad9e08b4d183ff5b0 Mon Sep 17 00:00:00 2001 From: Daniela Date: Thu, 14 Nov 2024 18:33:02 +0000 Subject: [PATCH 3/4] edit desc --- samples/snippets/classification_boosted_tree_model_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/classification_boosted_tree_model_test.py b/samples/snippets/classification_boosted_tree_model_test.py index faecc21f0d..b7c644e2d8 100644 --- a/samples/snippets/classification_boosted_tree_model_test.py +++ b/samples/snippets/classification_boosted_tree_model_test.py @@ -42,7 +42,7 @@ def test_boosted_tree_model(random_model_id: str) -> None: # [START bigquery_dataframes_bqml_boosted_tree_explain] # Select model you'll use for predictions. `read_gbq_model` loads model # data from BigQuery, but you could also use the `tree_model` object - # from previous steps. + # from the previous step. tree_model = bpd.read_gbq_model( your_model_id, # For example: "your-project.bqml_tutorial.tree_model" ) From 6a70279f51db5be9bef900eb8c1596042e8a3124 Mon Sep 17 00:00:00 2001 From: Daniela Date: Wed, 20 Nov 2024 14:40:21 +0000 Subject: [PATCH 4/4] correct model info --- .../snippets/classification_boosted_tree_model_test.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/samples/snippets/classification_boosted_tree_model_test.py b/samples/snippets/classification_boosted_tree_model_test.py index 87df456abe..715c9d1098 100644 --- a/samples/snippets/classification_boosted_tree_model_test.py +++ b/samples/snippets/classification_boosted_tree_model_test.py @@ -48,17 +48,17 @@ def test_boosted_tree_model(random_model_id: str) -> None: y = training_data["income_bracket"] # create and train the model - census_model = ensemble.XGBClassifier( + tree_model = ensemble.XGBClassifier( n_estimators=1, booster="gbtree", tree_method="hist", max_iterations=1, # For a more accurate model, try 50 iterations. subsample=0.85, ) - census_model.fit(X, y) + tree_model.fit(X, y) - census_model.to_gbq( - your_model_id, # For example: "your-project.census.census_model" + tree_model.to_gbq( + your_model_id, # For example: "your-project.bqml_tutorial.tree_model" replace=True, ) # [END bigquery_dataframes_bqml_boosted_tree_create] @@ -87,4 +87,3 @@ def test_boosted_tree_model(random_model_id: str) -> None: assert evaluation_data is not None assert score is not None assert input_data is not None - assert census_model is not None