File: with_omp_limit.py

package info (click to toggle)
xgboost 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,796 kB
  • sloc: cpp: 67,502; python: 35,503; java: 4,676; ansic: 1,426; sh: 1,320; xml: 1,197; makefile: 204; javascript: 19
file content (27 lines) | stat: -rw-r--r-- 683 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sys

from sklearn.datasets import make_classification
from sklearn.metrics import roc_auc_score

import xgboost as xgb


def run_omp(output_path: str):
    X, y = make_classification(
        n_samples=200, n_features=32, n_classes=3, n_informative=8
    )
    Xy = xgb.DMatrix(X, y, nthread=16)
    booster = xgb.train(
        {"num_class": 3, "objective": "multi:softprob", "n_jobs": 16},
        Xy,
        num_boost_round=8,
    )
    score = booster.predict(Xy)
    auc = roc_auc_score(y, score, average="weighted", multi_class="ovr")
    with open(output_path, "w") as fd:
        fd.write(str(auc))


if __name__ == "__main__":
    out = sys.argv[1]
    run_omp(out)