File tree 1 file changed +25
-1
lines changed
1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 14
14
15
15
16
16
def test_boosted_tree_model (random_model_id : str ) -> None :
17
- # your_model_id = random_model_id
17
+ your_model_id = random_model_id
18
18
# [START bigquery_dataframes_bqml_boosted_tree_prepare]
19
19
import bigframes .pandas as bpd
20
20
@@ -39,4 +39,28 @@ def test_boosted_tree_model(random_model_id: str) -> None:
39
39
)
40
40
del input_data ["functional_weight" ]
41
41
# [END bigquery_dataframes_bqml_boosted_tree_prepare]
42
+ # [START bigquery_dataframes_bqml_boosted_tree_create]
43
+ from bigframes .ml import ensemble
44
+
45
+ # input_data is defined in an earlier step.
46
+ training_data = input_data [input_data ["dataframe" ] == "training" ]
47
+ X = training_data .drop (columns = ["income_bracket" , "dataframe" ])
48
+ y = training_data ["income_bracket" ]
49
+
50
+ # create and train the model
51
+ census_model = ensemble .XGBClassifier (
52
+ n_estimators = 1 ,
53
+ booster = "gbtree" ,
54
+ tree_method = "hist" ,
55
+ max_iterations = 1 , # For a more accurate model, try 50 iterations.
56
+ subsample = 0.85 ,
57
+ )
58
+ census_model .fit (X , y )
59
+
60
+ census_model .to_gbq (
61
+ your_model_id , # For example: "your-project.census.census_model"
62
+ replace = True ,
63
+ )
64
+ # [END bigquery_dataframes_bqml_boosted_tree_create]
42
65
assert input_data is not None
66
+ assert census_model is not None
You can’t perform that action at this time.
0 commit comments