()
| 94 | |
| 95 | |
| 96 | def main() -> None: |
| 97 | rounds = 100 |
| 98 | it = IterForDMatrixDemo() |
| 99 | |
| 100 | # Use iterator, must be `QuantileDMatrix`. |
| 101 | |
| 102 | # In this demo, the input batches are created using cupy, and the data processing |
| 103 | # (quantile sketching) will be performed on GPU. If data is loaded with CPU based |
| 104 | # data structures like numpy or pandas, then the processing step will be performed |
| 105 | # on CPU instead. |
| 106 | m_with_it = xgboost.QuantileDMatrix(it) |
| 107 | |
| 108 | # Use regular DMatrix. |
| 109 | m = xgboost.DMatrix( |
| 110 | it.as_array(), it.as_array_labels(), weight=it.as_array_weights() |
| 111 | ) |
| 112 | |
| 113 | assert m_with_it.num_col() == m.num_col() |
| 114 | assert m_with_it.num_row() == m.num_row() |
| 115 | # Tree method must be `hist`. |
| 116 | reg_with_it = xgboost.train( |
| 117 | {"tree_method": "hist", "device": "cuda"}, |
| 118 | m_with_it, |
| 119 | num_boost_round=rounds, |
| 120 | evals=[(m_with_it, "Train")], |
| 121 | ) |
| 122 | predict_with_it = reg_with_it.predict(m_with_it) |
| 123 | |
| 124 | reg = xgboost.train( |
| 125 | {"tree_method": "hist", "device": "cuda"}, |
| 126 | m, |
| 127 | num_boost_round=rounds, |
| 128 | evals=[(m, "Train")], |
| 129 | ) |
| 130 | predict = reg.predict(m) |
| 131 | |
| 132 | |
| 133 | if __name__ == "__main__": |
no test coverage detected