repo
stringlengths
1
99
file
stringlengths
13
215
code
stringlengths
12
59.2M
file_length
int64
12
59.2M
avg_line_length
float64
3.82
1.48M
max_line_length
int64
12
2.51M
extension_type
stringclasses
1 value
xgboost
xgboost-master/tests/ci_build/change_version.py
""" 1. Modify ``CMakeLists.txt`` in source tree and ``python-package/xgboost/VERSION`` if needed, run CMake . If this is a RC release, the Python version has the form <major>.<minor>.<patch>rc1 2. Modify ``DESCRIPTION`` and ``configure.ac`` in R-package. Run ``autoreconf``. 3. Run ``mvn`` in ``jvm-packages`` If...
5,198
31.49375
88
py
xgboost
xgboost-master/tests/python/test_data_iterator.py
from typing import Callable, Dict, List import numpy as np import pytest from hypothesis import given, settings, strategies from scipy.sparse import csr_matrix import xgboost as xgb from xgboost import testing as tm from xgboost.data import SingleBatchInternalIter as SingleBatch from xgboost.testing import IteratorFo...
5,556
29.201087
89
py
xgboost
xgboost-master/tests/python/test_dmatrix.py
import os import tempfile import numpy as np import pytest import scipy.sparse from hypothesis import given, settings, strategies from scipy.sparse import csr_matrix, rand import xgboost as xgb from xgboost import testing as tm from xgboost.testing.data import np_dtypes rng = np.random.RandomState(1) dpath = 'demo/...
16,765
34.748401
95
py
xgboost
xgboost-master/tests/python/test_survival.py
import json import os from typing import List, Optional, Tuple, cast import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm dpath = tm.data_dir(__file__) @pytest.fixture(scope="module") def toy_data() -> Tuple[xgb.DMatrix, np.ndarray, np.ndarray]: X = np.array([1, 2, 3, 4, 5])...
5,895
33.887574
87
py
xgboost
xgboost-master/tests/python/test_interaction_constraints.py
import numpy as np import pytest import xgboost from xgboost import testing as tm dpath = 'demo/data/' rng = np.random.RandomState(1994) class TestInteractionConstraints: def run_interaction_constraints( self, tree_method, feature_names=None, interaction_constraints='[[0, 1]]' ): x1 = np.ran...
4,864
39.882353
91
py
xgboost
xgboost-master/tests/python/test_cli.py
import json import os import platform import subprocess import tempfile import numpy import xgboost from xgboost import testing as tm class TestCLI: template = ''' booster = gbtree objective = reg:squarederror eta = 1.0 gamma = 1.0 seed = {seed} min_child_weight = 0 max_depth = 3 task = {task} model_in = {model...
7,100
35.603093
79
py
xgboost
xgboost-master/tests/python/test_plotting.py
import json import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm try: import matplotlib matplotlib.use('Agg') from graphviz import Source from matplotlib.axes import Axes except ImportError: pass pytestmark = pytest.mark.skipif(**tm.no_multiple(tm.no_matplotli...
3,420
34.268041
77
py
xgboost
xgboost-master/tests/python/test_callback.py
import json import os import tempfile from contextlib import nullcontext from typing import Union import pytest import xgboost as xgb from xgboost import testing as tm # We use the dataset for tests. pytestmark = pytest.mark.skipif(**tm.no_sklearn()) class TestCallbacks: @classmethod def setup_class(cls): ...
19,424
39.72327
89
py
xgboost
xgboost-master/tests/python/test_tracker.py
import re import sys import numpy as np import pytest import xgboost as xgb from xgboost import RabitTracker, collective from xgboost import testing as tm if sys.platform.startswith("win"): pytest.skip("Skipping dask tests on Windows", allow_module_level=True) def test_rabit_tracker(): tracker = RabitTrack...
3,138
31.030612
87
py
xgboost
xgboost-master/tests/python/test_ranking.py
import itertools import json import os import shutil from typing import Optional import numpy as np import pytest from hypothesis import given, note, settings from scipy.sparse import csr_matrix import xgboost from xgboost import testing as tm from xgboost.testing.data import RelDataCV, simulate_clicks, sort_ltr_samp...
10,581
35.743056
87
py
xgboost
xgboost-master/tests/python/test_model_compatibility.py
import copy import json import os import urllib.request import zipfile import generate_models as gm import pytest import xgboost from xgboost import testing as tm def run_model_param_check(config): assert config['learner']['learner_model_param']['num_feature'] == str(4) assert config['learner']['learner_tra...
5,321
36.744681
89
py
xgboost
xgboost-master/tests/python/test_with_sklearn.py
import json import os import pickle import random import tempfile import warnings from typing import Callable, Optional import numpy as np import pytest from sklearn.utils.estimator_checks import parametrize_with_checks import xgboost as xgb from xgboost import testing as tm from xgboost.testing.ranking import run_ra...
51,130
32.462696
95
py
xgboost
xgboost-master/tests/python/test_basic.py
import json import os import tempfile from pathlib import Path import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm dpath = 'demo/data/' rng = np.random.RandomState(1994) class TestBasic: def test_compat(self): from xgboost.compat import lazy_isinstance a = n...
12,151
35.93617
92
py
xgboost
xgboost-master/tests/python/test_with_modin.py
import numpy as np import pytest from test_dmatrix import set_base_margin_info import xgboost as xgb from xgboost import testing as tm try: import modin.pandas as md except ImportError: pass pytestmark = pytest.mark.skipif(**tm.no_modin()) class TestModin: @pytest.mark.xfail def test_modin(self): ...
5,475
36.506849
82
py
xgboost
xgboost-master/tests/python/test_dt.py
import numpy as np import pytest import xgboost as xgb dt = pytest.importorskip("datatable") pd = pytest.importorskip("pandas") class TestDataTable: def test_dt(self) -> None: df = pd.DataFrame([[1, 2.0, True], [2, 3.0, False]], columns=["a", "b", "c"]) dtable = dt.Frame(df) labels = dt....
1,376
31.785714
88
py
xgboost
xgboost-master/tests/python/test_pickling.py
import json import os import pickle import numpy as np import xgboost as xgb kRows = 100 kCols = 10 def generate_data(): X = np.random.randn(kRows, kCols) y = np.random.randn(kRows) return X, y class TestPickling: def run_model_pickling(self, xgb_params) -> str: X, y = generate_data() ...
1,611
24.1875
82
py
xgboost
xgboost-master/tests/python/test_config.py
import multiprocessing from concurrent.futures import ThreadPoolExecutor import pytest import xgboost as xgb @pytest.mark.parametrize("verbosity_level", [0, 1, 2, 3]) def test_global_config_verbosity(verbosity_level): def get_current_verbosity(): return xgb.get_config()["verbosity"] old_verbosity =...
2,195
32.272727
75
py
xgboost
xgboost-master/tests/python/generate_models.py
import os import numpy as np import xgboost kRounds = 2 kRows = 1000 kCols = 4 kForests = 2 kMaxDepth = 2 kClasses = 3 X = np.random.randn(kRows, kCols) w = np.random.uniform(size=kRows) version = xgboost.__version__ np.random.seed(1994) target_dir = 'models' def booster_bin(model): return os.path.join(targ...
4,998
31.673203
91
py
xgboost
xgboost-master/tests/python/test_with_pandas.py
from typing import Type import numpy as np import pytest from test_dmatrix import set_base_margin_info import xgboost as xgb from xgboost import testing as tm from xgboost.testing.data import pd_arrow_dtypes, pd_dtypes try: import pandas as pd except ImportError: pass pytestmark = pytest.mark.skipif(**tm.n...
14,507
39.188366
88
py
xgboost
xgboost-master/tests/python/test_quantile_dmatrix.py
from typing import Any, Dict, List import numpy as np import pytest from hypothesis import given, settings, strategies from scipy import sparse import xgboost as xgb from xgboost.testing import ( IteratorForTest, make_batches, make_batches_sparse, make_categorical, make_ltr, make_sparse_regres...
11,842
34.142433
86
py
xgboost
xgboost-master/tests/python/test_openmp.py
import os import subprocess import tempfile import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm pytestmark = tm.timeout(10) class TestOMP: def test_omp(self): dtrain, dtest = tm.load_agaricus(__file__) param = {'booster': 'gbtree', 'objecti...
3,285
29.146789
85
py
xgboost
xgboost-master/tests/python/test_eval_metrics.py
import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm from xgboost.testing.metrics import check_precision_score, check_quantile_error rng = np.random.RandomState(1337) class TestEvalMetrics: xgb_params_01 = { 'verbosity': 0, 'nthread': 1, 'eval_metric':...
12,366
36.935583
90
py
xgboost
xgboost-master/tests/python/test_training_continuation.py
import os import tempfile import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm rng = np.random.RandomState(1337) class TestTrainingContinuation: num_parallel_tree = 3 def generate_parameters(self): xgb_params_01_binary = { 'nthread': 1, } ...
5,883
34.878049
79
py
xgboost
xgboost-master/tests/python/test_linear.py
from hypothesis import given, note, settings, strategies import xgboost as xgb from xgboost import testing as tm pytestmark = tm.timeout(20) parameter_strategy = strategies.fixed_dictionaries({ 'booster': strategies.just('gblinear'), 'eta': strategies.floats(0.01, 0.25), 'tolerance': strategies.floats(1...
3,673
35.376238
97
py
xgboost
xgboost-master/tests/python/test_shap.py
import itertools import re import numpy as np import scipy import scipy.special import xgboost as xgb from xgboost import testing as tm class TestSHAP: def test_feature_importances(self) -> None: rng = np.random.RandomState(1994) data = rng.randn(100, 5) target = np.array([0, 1] * 50) ...
10,334
38.903475
102
py
xgboost
xgboost-master/tests/python/test_predict.py
"""Tests for running inplace prediction.""" from concurrent.futures import ThreadPoolExecutor import numpy as np import pandas as pd import pytest from scipy import sparse import xgboost as xgb from xgboost import testing as tm from xgboost.testing.data import np_dtypes, pd_dtypes from xgboost.testing.shared import v...
8,720
31.909434
87
py
xgboost
xgboost-master/tests/python/test_tree_regularization.py
import numpy as np from numpy.testing import assert_approx_equal import xgboost as xgb train_data = xgb.DMatrix(np.array([[1]]), label=np.array([1])) class TestTreeRegularization: def test_alpha(self): params = { "tree_method": "exact", "verbosity": 0, "objective": "r...
2,356
27.059524
78
py
xgboost
xgboost-master/tests/python/test_collective.py
import multiprocessing import socket import sys import time import numpy as np import pytest import xgboost as xgb from xgboost import RabitTracker, build_info, federated if sys.platform.startswith("win"): pytest.skip("Skipping collective tests on Windows", allow_module_level=True) def run_rabit_worker(rabit_e...
4,053
36.192661
104
py
xgboost
xgboost-master/tests/python/test_basic_models.py
import json import locale import os import tempfile import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm dpath = tm.data_dir(__file__) rng = np.random.RandomState(1994) def json_model(model_path: str, parameters: dict) -> dict: datasets = pytest.importorskip("sklearn.datase...
26,002
37.183554
88
py
xgboost
xgboost-master/tests/python/with_omp_limit.py
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...
683
23.428571
72
py
xgboost
xgboost-master/tests/python/test_demos.py
import os import subprocess import sys import tempfile import pytest import xgboost from xgboost import testing as tm pytestmark = tm.timeout(30) DEMO_DIR = tm.demo_dir(__file__) PYTHON_DEMO_DIR = os.path.join(DEMO_DIR, 'guide-python') CLI_DEMO_DIR = os.path.join(DEMO_DIR, 'CLI') def test_basic_walkthrough(): ...
6,699
28.777778
78
py
xgboost
xgboost-master/tests/python/test_monotone_constraints.py
import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm dpath = 'demo/data/' def is_increasing(y): return np.count_nonzero(np.diff(y) < 0.0) == 0 def is_decreasing(y): return np.count_nonzero(np.diff(y) > 0.0) == 0 def is_correctly_constrained(learner, feature_names=None...
5,360
34.269737
92
py
xgboost
xgboost-master/tests/python/test_with_arrow.py
import os import unittest import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm try: import pandas as pd import pyarrow as pa import pyarrow.csv as pc except ImportError: pass pytestmark = pytest.mark.skipif( tm.no_arrow()["condition"] or tm.no_pandas()["condit...
3,020
32.197802
84
py
xgboost
xgboost-master/tests/python/test_early_stopping.py
import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm from xgboost.testing.updater import get_basescore rng = np.random.RandomState(1994) class TestEarlyStopping: @pytest.mark.skipif(**tm.no_sklearn()) def test_early_stopping_nonparallel(self): from sklearn.dataset...
4,658
37.825
90
py
xgboost
xgboost-master/tests/python/test_updaters.py
import json from string import ascii_lowercase from typing import Any, Dict, List import numpy as np import pytest from hypothesis import given, note, settings, strategies import xgboost as xgb from xgboost import testing as tm from xgboost.testing.params import ( cat_parameter_strategy, exact_parameter_strat...
19,708
34.384201
105
py
xgboost
xgboost-master/tests/python/test_with_shap.py
import numpy as np import pytest import xgboost as xgb try: import shap except Exception: shap = None pass pytestmark = pytest.mark.skipif(shap is None, reason="Requires shap package") # xgboost removed ntree_limit in 2.0, which breaks the SHAP package. @pytest.mark.xfail def test_with_shap() -> None:...
832
24.242424
77
py
xgboost
xgboost-master/tests/python/test_parse_tree.py
import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm pytestmark = pytest.mark.skipif(**tm.no_pandas()) dpath = 'demo/data/' rng = np.random.RandomState(1994) class TestTreesToDataFrame: def build_model(self, max_depth, num_round): dtrain, _ = tm.load_agaricus(__file...
2,770
36.958904
81
py
xgboost
xgboost-master/tests/python-gpu/test_large_input.py
import cupy as cp import numpy as np import pytest import xgboost as xgb # Test for integer overflow or out of memory exceptions def test_large_input(): available_bytes, _ = cp.cuda.runtime.memGetInfo() # 15 GB required_bytes = 1.5e10 if available_bytes < required_bytes: pytest.skip("Not enou...
670
25.84
77
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_linear.py
import pytest from hypothesis import assume, given, note, settings, strategies import xgboost as xgb from xgboost import testing as tm pytestmark = tm.timeout(10) parameter_strategy = strategies.fixed_dictionaries({ 'booster': strategies.just('gblinear'), 'eta': strategies.floats(0.01, 0.25), 'tolerance'...
2,973
36.175
93
py
xgboost
xgboost-master/tests/python-gpu/test_device_quantile_dmatrix.py
import sys import numpy as np import pytest from hypothesis import given, settings, strategies import xgboost as xgb from xgboost import testing as tm from xgboost.testing.data import check_inf sys.path.append("tests/python") import test_quantile_dmatrix as tqd class TestQuantileDMatrix: cputest = tqd.TestQuan...
7,477
30.821277
85
py
xgboost
xgboost-master/tests/python-gpu/conftest.py
import pytest from xgboost import testing as tm def has_rmm(): return tm.no_rmm()["condition"] @pytest.fixture(scope="session", autouse=True) def setup_rmm_pool(request, pytestconfig): tm.setup_rmm_pool(request, pytestconfig) def pytest_addoption(parser: pytest.Parser) -> None: parser.addoption( ...
992
28.205882
81
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_data_iterator.py
import sys import pytest from hypothesis import given, settings, strategies from xgboost.testing import no_cupy sys.path.append("tests/python") from test_data_iterator import run_data_iterator from test_data_iterator import test_single_batch as cpu_single_batch def test_gpu_single_batch() -> None: cpu_single_b...
1,008
23.609756
83
py
xgboost
xgboost-master/tests/python-gpu/load_pickle.py
"""Loading a pickled model generated by test_pickling.py, only used by `test_gpu_with_dask.py`""" import json import os import numpy as np import pytest from test_gpu_pickling import build_dataset, load_pickle, model_path import xgboost as xgb from xgboost import testing as tm class TestLoadPickle: def test_loa...
2,464
35.25
88
py
xgboost
xgboost-master/tests/python-gpu/test_monotonic_constraints.py
import sys import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm sys.path.append("tests/python") import test_monotone_constraints as tmc rng = np.random.RandomState(1994) def non_decreasing(L): return all((x - y) < 0.001 for x, y in zip(L, L[1:])) def non_increasing(L): ...
1,609
23.769231
78
py
xgboost
xgboost-master/tests/python-gpu/test_from_cudf.py
import json import sys import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm sys.path.append("tests/python") from test_dmatrix import set_base_margin_info def dmatrix_from_cudf(input_type, DMatrixT, missing=np.NAN): '''Test constructing DMatrix from cudf''' import cudf ...
12,553
33.584022
96
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_updaters.py
import sys from typing import Any, Dict import numpy as np import pytest from hypothesis import assume, given, note, settings, strategies import xgboost as xgb from xgboost import testing as tm from xgboost.testing.params import cat_parameter_strategy, hist_parameter_strategy from xgboost.testing.updater import ( ...
9,527
33.647273
88
py
xgboost
xgboost-master/tests/python-gpu/test_from_cupy.py
import json import sys import numpy as np import pytest import xgboost as xgb sys.path.append("tests/python") from test_dmatrix import set_base_margin_info from xgboost import testing as tm cupy = pytest.importorskip("cupy") def test_array_interface() -> None: arr = cupy.array([[1, 2, 3, 4], [1, 2, 3, 4]]) ...
7,908
31.681818
95
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_with_sklearn.py
import json import os import sys import tempfile import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm from xgboost.testing.ranking import run_ranking_qid_df sys.path.append("tests/python") import test_with_sklearn as twskl # noqa pytestmark = pytest.mark.skipif(**tm.no_sklearn()...
4,774
28.115854
80
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_basic_models.py
import os import sys import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm sys.path.append("tests/python") import test_basic_models as test_bm # Don't import the test class, otherwise they will run twice. import test_callback as test_cb # noqa rng = np.random.RandomState(1994) ...
2,714
30.941176
82
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_training_continuation.py
import json import numpy as np import xgboost as xgb rng = np.random.RandomState(1994) class TestGPUTrainingContinuation: def test_training_continuation(self): kRows = 64 kCols = 32 X = np.random.randn(kRows, kCols) y = np.random.randn(kRows) dtrain = xgb.DMatrix(X, y) ...
1,870
34.980769
78
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_eval_metrics.py
import json import sys import pytest import xgboost from xgboost import testing as tm from xgboost.testing.metrics import check_precision_score, check_quantile_error sys.path.append("tests/python") import test_eval_metrics as test_em # noqa class TestGPUEvalMetrics: cpu_test = test_em.TestEvalMetrics() @...
2,281
29.837838
85
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_demos.py
import os import subprocess import sys import pytest from xgboost import testing as tm sys.path.append("tests/python") import test_demos as td # noqa @pytest.mark.skipif(**tm.no_cupy()) def test_data_iterator(): script = os.path.join(td.PYTHON_DEMO_DIR, 'quantile_data_iterator.py') cmd = ['python', script...
669
21.333333
74
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_plotting.py
import sys import pytest from xgboost import testing as tm sys.path.append("tests/python") import test_plotting as tp pytestmark = pytest.mark.skipif(**tm.no_multiple(tm.no_matplotlib(), tm.no_graphviz())) class TestPlotting: cputest = tp.TestPlotting() @pytest.mark.skipif(**tm.no_pandas()) def test_...
388
19.473684
87
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_pickling.py
"""Test model IO with pickle.""" import os import pickle import subprocess import numpy as np import pytest import xgboost as xgb from xgboost import XGBClassifier from xgboost import testing as tm model_path = "./model.pkl" pytestmark = tm.timeout(30) def build_dataset(): N = 10 x = np.linspace(0, N * N,...
5,400
27.882353
84
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_ranking.py
import os from typing import Dict import numpy as np import pytest import xgboost from xgboost import testing as tm pytestmark = tm.timeout(30) def comp_training_with_rank_objective( dtrain: xgboost.DMatrix, dtest: xgboost.DMatrix, rank_objective: str, metric_name: str, tolerance: float = 1e-02...
3,649
27.294574
87
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_prediction.py
import sys from copy import copy import numpy as np import pytest from hypothesis import assume, given, settings, strategies import xgboost as xgb from xgboost import testing as tm from xgboost.compat import PANDAS_INSTALLED if PANDAS_INSTALLED: from hypothesis.extra.pandas import column, data_frames, range_inde...
20,606
34.963351
88
py
xgboost
xgboost-master/tests/python-gpu/test_gpu_interaction_constraints.py
import sys import numpy as np import pandas as pd import xgboost as xgb sys.path.append("tests/python") # Don't import the test class, otherwise they will run twice. import test_interaction_constraints as test_ic # noqa rng = np.random.RandomState(1994) class TestGPUInteractionConstraints: cputest = test_ic....
1,551
30.04
82
py
xgboost
xgboost-master/tests/test_distributed/test_federated/test_federated.py
#!/usr/bin/python import multiprocessing import sys import time import xgboost as xgb import xgboost.federated SERVER_KEY = 'server-key.pem' SERVER_CERT = 'server-cert.pem' CLIENT_KEY = 'client-key.pem' CLIENT_CERT = 'client-cert.pem' def run_server(port: int, world_size: int, with_ssl: bool) -> None: if with_s...
3,078
34.390805
94
py
xgboost
xgboost-master/tests/test_distributed/test_with_dask/test_with_dask.py
"""Copyright 2019-2022 XGBoost contributors""" import asyncio import json import os import pickle import socket import tempfile from concurrent.futures import ThreadPoolExecutor from functools import partial from itertools import starmap from math import ceil from operator import attrgetter, getitem from pathlib import...
78,178
34.089318
96
py
xgboost
xgboost-master/tests/test_distributed/test_with_dask/test_demos.py
import os import subprocess import pytest from xgboost import testing as tm @pytest.mark.skipif(**tm.no_dask()) def test_dask_cpu_training_demo(): script = os.path.join(tm.demo_dir(__file__), "dask", "cpu_training.py") cmd = ["python", script] subprocess.check_call(cmd) @pytest.mark.skipif(**tm.no_das...
1,004
26.162162
83
py
xgboost
xgboost-master/tests/test_distributed/test_gpu_with_spark/test_data.py
import pytest from xgboost import testing as tm pytestmark = pytest.mark.skipif(**tm.no_spark()) from ..test_with_spark.test_data import run_dmatrix_ctor @pytest.mark.skipif(**tm.no_cudf()) @pytest.mark.parametrize( "is_feature_cols,is_qdm", [(True, True), (True, False), (False, True), (False, False)], ) d...
446
25.294118
67
py
xgboost
xgboost-master/tests/test_distributed/test_gpu_with_spark/test_gpu_spark.py
import json import logging import subprocess import pytest import sklearn from xgboost import testing as tm pytestmark = pytest.mark.skipif(**tm.no_spark()) from pyspark.ml.linalg import Vectors from pyspark.ml.tuning import CrossValidator, ParamGridBuilder from pyspark.sql import SparkSession from xgboost.spark i...
8,564
34.83682
88
py
xgboost
xgboost-master/tests/test_distributed/test_with_spark/test_data.py
from typing import List import numpy as np import pandas as pd import pytest from xgboost import testing as tm pytestmark = [pytest.mark.skipif(**tm.no_spark())] from xgboost import DMatrix, QuantileDMatrix from xgboost.spark.data import ( _read_csr_matrix_from_unwrapped_spark_vec, alias, create_dmatrix...
5,132
31.903846
88
py
xgboost
xgboost-master/tests/test_distributed/test_with_spark/utils.py
import contextlib import logging import shutil import sys import tempfile import unittest from io import StringIO import pytest from xgboost import testing as tm pytestmark = [pytest.mark.skipif(**tm.no_spark())] from pyspark.sql import SparkSession from xgboost.spark.utils import _get_default_params_from_func c...
4,058
27.1875
92
py
xgboost
xgboost-master/tests/test_distributed/test_with_spark/test_spark_local.py
import glob import logging import random import tempfile import uuid from collections import namedtuple from typing import Generator, Sequence, Type import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm from xgboost.spark.data import pred_contribs pytestmark = [tm.timeout(60), pyte...
55,161
37.227304
98
py
xgboost
xgboost-master/tests/test_distributed/test_with_spark/test_spark_local_cluster.py
import json import logging import os import random import tempfile import uuid from collections import namedtuple import numpy as np import pytest import xgboost as xgb from xgboost import testing as tm from xgboost.callback import LearningRateScheduler pytestmark = pytest.mark.skipif(**tm.no_spark()) from typing i...
18,886
37.623722
106
py
xgboost
xgboost-master/tests/test_distributed/test_gpu_with_dask/conftest.py
from typing import Generator, Sequence import pytest from xgboost import testing as tm @pytest.fixture(scope="session", autouse=True) def setup_rmm_pool(request, pytestconfig: pytest.Config) -> None: tm.setup_rmm_pool(request, pytestconfig) @pytest.fixture(scope="class") def local_cuda_client(request, pytestc...
1,302
29.302326
86
py
xgboost
xgboost-master/tests/test_distributed/test_gpu_with_dask/test_gpu_demos.py
import os import subprocess import pytest from xgboost import testing as tm @pytest.mark.skipif(**tm.no_dask()) @pytest.mark.skipif(**tm.no_dask_cuda()) @pytest.mark.skipif(**tm.no_cupy()) @pytest.mark.mgpu def test_dask_training(): script = os.path.join(tm.demo_dir(__file__), "dask", "gpu_training.py") cmd...
644
23.807692
83
py
xgboost
xgboost-master/tests/test_distributed/test_gpu_with_dask/test_gpu_with_dask.py
"""Copyright 2019-2022 XGBoost contributors""" import asyncio import json from collections import OrderedDict from inspect import signature from typing import Any, Dict, Type, TypeVar import numpy as np import pytest from hypothesis import given, note, settings, strategies from hypothesis._settings import duration im...
20,069
33.484536
86
py
xgboost
xgboost-master/tests/benchmark/benchmark_linear.py
#pylint: skip-file import argparse import xgboost as xgb import numpy as np from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split import time import ast rng = np.random.RandomState(1994) def run_benchmark(args): try: dtest = xgb.DMatrix('dtest.dm') ...
2,912
40.614286
143
py
xgboost
xgboost-master/tests/benchmark/benchmark_tree.py
"""Run benchmark on the tree booster.""" import argparse import ast import time import numpy as np import xgboost as xgb RNG = np.random.RandomState(1994) def run_benchmark(args): """Runs the benchmark.""" try: dtest = xgb.DMatrix('dtest.dm') dtrain = xgb.DMatrix('dtrain.dm') if no...
3,021
33.735632
100
py
xgboost
xgboost-master/demo/nvflare/horizontal/custom/controller.py
""" Example of training controller with NVFlare =========================================== """ import multiprocessing from nvflare.apis.client import Client from nvflare.apis.fl_context import FLContext from nvflare.apis.impl.controller import Controller, Task from nvflare.apis.shareable import Shareable from nvflare...
2,587
36.507246
89
py
xgboost
xgboost-master/demo/nvflare/horizontal/custom/trainer.py
import os from nvflare.apis.executor import Executor from nvflare.apis.fl_constant import FLContextKey, ReturnCode from nvflare.apis.fl_context import FLContext from nvflare.apis.shareable import Shareable, make_reply from nvflare.apis.signal import Signal import xgboost as xgb from xgboost import callback class Su...
3,971
42.648352
84
py
xgboost
xgboost-master/demo/nvflare/vertical/custom/controller.py
""" Example of training controller with NVFlare =========================================== """ import multiprocessing from nvflare.apis.client import Client from nvflare.apis.fl_context import FLContext from nvflare.apis.impl.controller import Controller, Task from nvflare.apis.shareable import Shareable from nvflare...
2,587
36.507246
89
py
xgboost
xgboost-master/demo/nvflare/vertical/custom/trainer.py
import os from nvflare.apis.executor import Executor from nvflare.apis.fl_constant import FLContextKey, ReturnCode from nvflare.apis.fl_context import FLContext from nvflare.apis.shareable import Shareable, make_reply from nvflare.apis.signal import Signal import xgboost as xgb from xgboost import callback class Su...
4,015
39.979592
95
py
xgboost
xgboost-master/demo/aft_survival/aft_survival_demo_with_optuna.py
""" Demo for survival analysis (regression) with Optuna. ==================================================== Demo for survival analysis (regression) using Accelerated Failure Time (AFT) model, using Optuna to tune hyperparameters """ import numpy as np import optuna import pandas as pd from sklearn.model_selection i...
3,655
42.52381
112
py
xgboost
xgboost-master/demo/aft_survival/aft_survival_viz_demo.py
""" Visual demo for survival analysis (regression) with Accelerated Failure Time (AFT) model. ========================================================================================= This demo uses 1D toy data and visualizes how XGBoost fits a tree ensemble. The ensemble model starts out as a flat line and evolves in...
4,167
28.985612
89
py
xgboost
xgboost-master/demo/aft_survival/aft_survival_demo.py
""" Demo for survival analysis (regression). ======================================== Demo for survival analysis (regression). using Accelerated Failure Time (AFT) model. """ import os import numpy as np import pandas as pd from sklearn.model_selection import ShuffleSplit import xgboost as xgb # The Veterans' Admi...
2,291
35.380952
87
py
xgboost
xgboost-master/demo/multiclass_classification/train.py
#!/usr/bin/python from __future__ import division import numpy as np import xgboost as xgb # label need to be 0 to num_class -1 data = np.loadtxt('./dermatology.data', delimiter=',', converters={33: lambda x:int(x == '?'), 34: lambda x:int(x) - 1}) sz = data.shape train = data[:int(sz[0] * 0.7), :] test = ...
1,553
28.884615
73
py
xgboost
xgboost-master/demo/gpu_acceleration/cover_type.py
import time from sklearn.datasets import fetch_covtype from sklearn.model_selection import train_test_split import xgboost as xgb # Fetch dataset using sklearn cov = fetch_covtype() X = cov.data y = cov.target # Create 0.75/0.25 train/test split X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0....
1,333
30.761905
90
py
xgboost
xgboost-master/demo/dask/cpu_survival.py
""" Example of training survival model with Dask on CPU =================================================== """ import os import dask.dataframe as dd from dask.distributed import Client, LocalCluster import xgboost as xgb from xgboost.dask import DaskDMatrix def main(client): # Load an example survival data f...
2,404
32.402778
91
py
xgboost
xgboost-master/demo/dask/sklearn_cpu_training.py
""" Use scikit-learn regressor interface with CPU histogram tree method =================================================================== """ from dask import array as da from dask.distributed import Client, LocalCluster import xgboost def main(client): # generate some random data for demonstration n = 100...
1,186
27.95122
74
py
xgboost
xgboost-master/demo/dask/sklearn_gpu_training.py
""" Use scikit-learn regressor interface with GPU histogram tree method =================================================================== """ from dask import array as da from dask.distributed import Client # It's recommended to use dask_cuda for GPU assignment from dask_cuda import LocalCUDACluster import xgboost...
1,375
28.276596
73
py
xgboost
xgboost-master/demo/dask/gpu_training.py
""" Example of training with Dask on GPU ==================================== """ import dask_cudf from dask import array as da from dask import dataframe as dd from dask.distributed import Client from dask_cuda import LocalCUDACluster import xgboost as xgb from xgboost import dask as dxgb from xgboost.dask import Das...
2,919
33.352941
88
py
xgboost
xgboost-master/demo/dask/cpu_training.py
""" Example of training with Dask on CPU ==================================== """ from dask import array as da from dask.distributed import Client, LocalCluster import xgboost as xgb from xgboost.dask import DaskDMatrix def main(client): # generate some random data for demonstration m = 100000 n = 100 ...
1,408
27.755102
70
py
xgboost
xgboost-master/demo/dask/dask_callbacks.py
""" Example of using callbacks with Dask ==================================== """ import numpy as np from dask.distributed import Client, LocalCluster from dask_ml.datasets import make_regression from dask_ml.model_selection import train_test_split import xgboost as xgb from xgboost.dask import DaskDMatrix def proba...
2,965
31.955556
87
py
xgboost
xgboost-master/demo/guide-python/predict_first_ntree.py
""" Demo for prediction using number of trees ========================================= """ import os import numpy as np from sklearn.datasets import load_svmlight_file import xgboost as xgb CURRENT_DIR = os.path.dirname(__file__) train = os.path.join(CURRENT_DIR, "../data/agaricus.txt.train") test = os.path.join(CU...
1,942
30.852459
87
py
xgboost
xgboost-master/demo/guide-python/external_memory.py
""" Experimental support for external memory ======================================== This is similar to the one in `quantile_data_iterator.py`, but for external memory instead of Quantile DMatrix. The feature is not ready for production use yet. .. versionadded:: 1.5.0 See :doc:`the tutorial </tutorials/exter...
3,179
30.8
89
py
xgboost
xgboost-master/demo/guide-python/quantile_data_iterator.py
""" Demo for using data iterator with Quantile DMatrix ================================================== .. versionadded:: 1.2.0 The demo that defines a customized iterator for passing batches of data into :py:class:`xgboost.QuantileDMatrix` and use this ``QuantileDMatrix`` for training. The feature is used pri...
3,624
28.713115
86
py
xgboost
xgboost-master/demo/guide-python/callbacks.py
''' Demo for using and defining callback functions ============================================== .. versionadded:: 1.3.0 ''' import argparse import os import tempfile import numpy as np from matplotlib import pyplot as plt from sklearn.datasets import load_breast_cancer from sklearn.model_selection import train_...
4,631
33.311111
92
py
xgboost
xgboost-master/demo/guide-python/generalized_linear_model.py
""" Demo for GLM ============ """ import os import xgboost as xgb ## # this script demonstrate how to fit generalized linear model in xgboost # basically, we are using linear model, instead of tree for our boosters ## CURRENT_DIR = os.path.dirname(__file__) dtrain = xgb.DMatrix( os.path.join(CURRENT_DIR, "../da...
1,425
26.423077
80
py
xgboost
xgboost-master/demo/guide-python/learning_to_rank.py
""" Getting started with learning to rank ===================================== .. versionadded:: 2.0.0 This is a demonstration of using XGBoost for learning to rank tasks using the MSLR_10k_letor dataset. For more infomation about the dataset, please visit its `description page <https://www.microsoft.com/en-us/res...
6,345
28.516279
87
py
xgboost
xgboost-master/demo/guide-python/continuation.py
""" Demo for training continuation ============================== """ import os import pickle import tempfile from sklearn.datasets import load_breast_cancer import xgboost def training_continuation(tmpdir: str, use_pickle: bool) -> None: """Basic training continuation.""" # Train 128 iterations in 1 sessi...
3,807
33.306306
88
py
xgboost
xgboost-master/demo/guide-python/custom_rmsle.py
""" Demo for defining a custom regression objective and metric ========================================================== Demo for defining customized metric and objective. Notice that for simplicity reason weight is not used in following example. In this script, we implement the Squared Log Error (SLE) objective and...
6,450
31.094527
86
py
xgboost
xgboost-master/demo/guide-python/cat_in_the_dat.py
""" Train XGBoost with cat_in_the_dat dataset ========================================= A simple demo for categorical data support using dataset from Kaggle categorical data tutorial. The excellent tutorial is at: https://www.kaggle.com/shahules/an-overview-of-encoding-techniques And the data can be found at: https:...
3,744
28.722222
86
py
xgboost
xgboost-master/demo/guide-python/sklearn_examples.py
''' Collection of examples for using sklearn interface ================================================== For an introduction to XGBoost's scikit-learn estimator interface, see :doc:`/python/sklearn_estimator`. Created on 1 Apr 2015 @author: Jamie Hall ''' import pickle import numpy as np from sklearn.datasets impo...
2,644
32.910256
79
py
xgboost
xgboost-master/demo/guide-python/update_process.py
""" Demo for using `process_type` with `prune` and `refresh` ======================================================== Modifying existing trees is not a well established use for XGBoost, so feel free to experiment. """ import numpy as np from sklearn.datasets import fetch_california_housing import xgboost as xgb d...
3,247
32.833333
89
py
xgboost
xgboost-master/demo/guide-python/feature_weights.py
""" Demo for using feature weight to change column sampling ======================================================= .. versionadded:: 1.3.0 """ import argparse import numpy as np from matplotlib import pyplot as plt import xgboost def main(args: argparse.Namespace) -> None: rng = np.random.RandomState(199...
1,383
22.066667
85
py
xgboost
xgboost-master/demo/guide-python/gamma_regression.py
""" Demo for gamma regression ========================= """ import numpy as np import xgboost as xgb # this script demonstrates how to fit gamma regression model (with log link function) # in xgboost, before running the demo you need to generate the autoclaims dataset # by running gen_autoclaims.R located in xgboo...
1,098
35.633333
99
py
xgboost
xgboost-master/demo/guide-python/categorical.py
""" Getting started with categorical data ===================================== Experimental support for categorical data. In before, users need to run an encoder themselves before passing the data into XGBoost, which creates a sparse matrix and potentially increase memory usage. This demo showcases the experimental...
2,833
31.204545
88
py