python_code stringlengths 0 679k | repo_name stringlengths 9 41 | file_path stringlengths 6 149 |
|---|---|---|
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
"""EmotionNet visualization util scripts."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import cv2
import errno
import os
import numpy as np
import json
import argparse
def mkdir_p(new_p... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/emotionnet/ckplus_convert.py |
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
"""TLT YOLOv4 example."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
| tao_tutorials-main | notebooks/tao_launcher_starter_kit/yolo_v4/__init__.py |
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
"""Script to prepare train/val dataset for Unet tutorial."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import os
import cv2
import numpy as np
from PIL import Image,... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/unet/tao_isbi/prepare_data_isbi.py |
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
"""Script to visualize the Ground truth masks overlay for Unet tutorial."""
import os
import random
import argparse
import cv2
import numpy as np
def get_color_id(num_classes):
"""Function to return a list of color values for each class."""
... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/unet/tao_isbi/vis_annotation_isbi.py |
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
"""TLT YOLO example."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
| tao_tutorials-main | notebooks/tao_launcher_starter_kit/yolo_v3/__init__.py |
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
"""Script to prepare train/val dataset for Unet tutorial."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import os
import cv2
import numpy as np
from PIL import Image,... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/segformer/prepare_data_isbi.py |
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
"""Script to visualize the Ground truth masks overlay for Unet tutorial."""
import os
import random
import argparse
import cv2
import numpy as np
def get_color_id(num_classes):
"""Function to return a list of color values for each class."""
... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/segformer/vis_annotation_isbi.py |
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
"""TLT RetinaNet example."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
| tao_tutorials-main | notebooks/tao_launcher_starter_kit/retinanet/__init__.py |
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
"""Script to transform Wider face dataset to kitti format for Facenet tutorial."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import os
import cv2
import numpy as np
... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/facenet/convert_wider_to_kitti.py |
import os
import shutil
from tqdm import tqdm
DATA_DIR=os.environ.get('LOCAL_DATA_DIR')
with open("imagenet_valprep.txt", "r") as f:
for line in tqdm(f):
img_name, dir_name = line.rstrip().split(" ")
target_dir = os.path.join(DATA_DIR, "imagenet", "val", dir_name)
os.makedirs(target_dir, e... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/classification_tf2/byom_voc/prepare_imagenet.py |
import os
from os.path import join as join_path
import re
import glob
import shutil
from random import shuffle
from tqdm import tqdm
DATA_DIR=os.environ.get('LOCAL_DATA_DIR')
source_dir_orig = join_path(DATA_DIR, "VOCdevkit/VOC2012")
target_dir_orig = join_path(DATA_DIR, "formatted")
suffix = '_trainval.txt'
classes... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/classification_tf2/byom_voc/prepare_voc.py |
# Convert RGB images to (fake) 16-bit grayscale
import os
import numpy as np
from PIL import Image
from tqdm import tqdm
from os.path import join as join_path
def to16bit(images_dir, img_file, images_dir_16_bit):
image = Image.open(os.path.join(images_dir,img_file)).convert("L")
# shifted to the higher byte ... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/classification_tf2/tao_voc/prepare_16bit.py |
import os
from os.path import join as join_path
import re
import glob
import shutil
import sys
from random import shuffle
from tqdm import tqdm
DATA_DIR=os.environ.get('LOCAL_DATA_DIR')
source_dir_orig = join_path(DATA_DIR, "VOCdevkit/VOC2012")
target_dir_orig = join_path(DATA_DIR, "formatted")
suffix = '_trainval.t... | tao_tutorials-main | notebooks/tao_launcher_starter_kit/classification_tf2/tao_voc/prepare_voc.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/lprnet/preprocess_openalpr_benchmark.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/fpenet/data_utils.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/metric_learning_recognition/process_retail_product_checkout_dataset.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/kitti/kitti_to_coco.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/pointpillars/calibration_kitti.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/pointpillars/drop_class.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/pointpillars/gen_lidar_labels.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/pointpillars/kitti_split.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/pointpillars/object3d_kitti.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/pointpillars/gen_lidar_points.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/unet/prepare_data_isbi.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/re_identification/obtain_subset_data.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/pose_classification/select_subset_actions.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/api/dataset_prepare/ocrnet/preprocess_label.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/lprnet/preprocess_openalpr_benchmark.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/fpenet/data_utils.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/heartratenet/process_cohface.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/metric_learning_recognition/process_retail_product_checkout_dataset.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/kitti/kitti_to_coco.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/pointpillars/calibration_kitti.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/pointpillars/drop_class.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/pointpillars/gen_lidar_labels.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/pointpillars/kitti_split.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/pointpillars/object3d_kitti.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/pointpillars/gen_lidar_points.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/unet/prepare_data_isbi.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/re_identification/obtain_subset_data.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/pose_classification/select_subset_actions.py |
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by appli... | tao_tutorials-main | notebooks/tao_api_starter_kit/client/dataset_prepare/ocrnet/preprocess_label.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 = d... | spark-xgboost-nv-release_1.4.0 | demo/multiclass_classification/train.py |
from dask_cuda import LocalCUDACluster
from dask.distributed import Client
from dask import array as da
import xgboost as xgb
from xgboost import dask as dxgb
from xgboost.dask import DaskDMatrix
import cupy as cp
import argparse
def using_dask_matrix(client: Client, X, y):
# DaskDMatrix acts like normal DMatrix,... | spark-xgboost-nv-release_1.4.0 | demo/dask/gpu_training.py |
import xgboost as xgb
from xgboost.dask import DaskDMatrix
from dask.distributed import Client
from dask.distributed import LocalCluster
from dask import array as da
def main(client):
# generate some random data for demonstration
m = 100000
n = 100
X = da.random.random(size=(m, n), chunks=100)
y =... | spark-xgboost-nv-release_1.4.0 | demo/dask/cpu_training.py |
'''Dask interface demo:
Use scikit-learn regressor interface with GPU histogram tree method.'''
from dask.distributed import Client
# It's recommended to use dask_cuda for GPU assignment
from dask_cuda import LocalCUDACluster
from dask import array as da
import xgboost
def main(client):
# generate some random d... | spark-xgboost-nv-release_1.4.0 | demo/dask/sklearn_gpu_training.py |
'''Dask interface demo:
Use scikit-learn regressor interface with CPU histogram tree method.'''
from dask.distributed import Client
from dask.distributed import LocalCluster
from dask import array as da
import xgboost
def main(client):
# generate some random data for demonstration
n = 100
m = 10000
p... | spark-xgboost-nv-release_1.4.0 | demo/dask/sklearn_cpu_training.py |
#!/usr/bin/python
import sys
import random
if len(sys.argv) < 2:
print ('Usage:<filename> <k> [nfold = 5]')
exit(0)
random.seed( 10 )
k = int( sys.argv[2] )
if len(sys.argv) > 3:
nfold = int( sys.argv[3] )
else:
nfold = 5
fi = open( sys.argv[1], 'r' )
ftr = open( sys.argv[1]+'.train', 'w' )
fte = op... | spark-xgboost-nv-release_1.4.0 | demo/CLI/binary_classification/mknfold.py |
#!/usr/bin/python
def loadfmap( fname ):
fmap = {}
nmap = {}
for l in open( fname ):
arr = l.split()
if arr[0].find('.') != -1:
idx = int( arr[0].strip('.') )
assert idx not in fmap
fmap[ idx ] = {}
ftype = arr[1].strip(':')
conte... | spark-xgboost-nv-release_1.4.0 | demo/CLI/binary_classification/mapfeat.py |
import sys
fo = open(sys.argv[2], 'w')
for l in open(sys.argv[1]):
arr = l.split(',')
fo.write('%s' % arr[0])
for i in range(len(arr) - 1):
fo.write(' %d:%s' % (i, arr[i+1]))
fo.close()
| spark-xgboost-nv-release_1.4.0 | demo/CLI/yearpredMSD/csv2libsvm.py |
#!/usr/bin/python
import sys
import random
if len(sys.argv) < 2:
print('Usage:<filename> <k> [nfold = 5]')
exit(0)
random.seed(10)
k = int(sys.argv[2])
if len(sys.argv) > 3:
nfold = int(sys.argv[3])
else:
nfold = 5
fi = open(sys.argv[1], 'r')
ftr = open(sys.argv[1] + '.train', 'w')
fte = open(sys.ar... | spark-xgboost-nv-release_1.4.0 | demo/CLI/regression/mknfold.py |
#!/usr/bin/python
fo = open('machine.txt', 'w')
cnt = 6
fmap = {}
for l in open('machine.data'):
arr = l.split(',')
fo.write(arr[8])
for i in range(0, 6):
fo.write(' %d:%s' % (i, arr[i + 2]))
if arr[0] not in fmap:
fmap[arr[0]] = cnt
cnt += 1
fo.write(' %d:1' % fmap[arr[0]... | spark-xgboost-nv-release_1.4.0 | demo/CLI/regression/mapfeat.py |
'''Demonstration for parsing JSON tree model file generated by XGBoost. The
support is experimental, output schema is subject to change in the future.
'''
import json
import argparse
class Tree:
'''A tree built by XGBoost.'''
# Index into node array
_left = 0
_right = 1
_parent = 2
_ind = 3
... | spark-xgboost-nv-release_1.4.0 | demo/json-model/json_parser.py |
import xgboost as xgb
from sklearn.datasets import make_classification
import dask
from dask.distributed import Client
from dask_cuda import LocalCUDACluster
def main(client):
# Inform XGBoost that RMM is used for GPU memory allocation
xgb.set_config(use_rmm=True)
X, y = make_classification(n_samples=1000... | spark-xgboost-nv-release_1.4.0 | demo/rmm_plugin/rmm_mgpu_with_dask.py |
import xgboost as xgb
import rmm
from sklearn.datasets import make_classification
# Initialize RMM pool allocator
rmm.reinitialize(pool_allocator=True)
# Inform XGBoost that RMM is used for GPU memory allocation
xgb.set_config(use_rmm=True)
X, y = make_classification(n_samples=10000, n_informative=5, n_classes=3)
dtr... | spark-xgboost-nv-release_1.4.0 | demo/rmm_plugin/rmm_singlegpu.py |
"""
Demo for survival analysis (regression) using Accelerated Failure Time (AFT) model, using Optuna
to tune hyperparameters
"""
from sklearn.model_selection import ShuffleSplit
import pandas as pd
import numpy as np
import xgboost as xgb
import optuna
# The Veterans' Administration Lung Cancer Trial
# The Statistical... | spark-xgboost-nv-release_1.4.0 | demo/aft_survival/aft_survival_demo_with_optuna.py |
"""
Demo for survival analysis (regression) using Accelerated Failure Time (AFT) model
"""
import os
from sklearn.model_selection import ShuffleSplit
import pandas as pd
import numpy as np
import xgboost as xgb
# The Veterans' Administration Lung Cancer Trial
# The Statistical Analysis of Failure Time Data by Kalbflei... | spark-xgboost-nv-release_1.4.0 | demo/aft_survival/aft_survival_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 into a step function in order to account for all ranged
labels.
"""
import numpy as np
impor... | spark-xgboost-nv-release_1.4.0 | demo/aft_survival/aft_survival_viz_demo.py |
#!/usr/bin/python
import numpy as np
import xgboost as xgb
### load data in do training
train = np.loadtxt('./data/training.csv', delimiter=',', skiprows=1, converters={32: lambda x:int(x=='s'.encode('utf-8')) } )
label = train[:,32]
data = train[:,1:31]
weight = train[:,31]
dtrain = xgb.DMatrix( data, label=label,... | spark-xgboost-nv-release_1.4.0 | demo/kaggle-higgs/higgs-cv.py |
#!/usr/bin/python
# this is the example script to use xgboost to train
import numpy as np
import xgboost as xgb
test_size = 550000
# path to where the data lies
dpath = 'data'
# load in training data, directly use numpy
dtrain = np.loadtxt( dpath+'/training.csv', delimiter=',', skiprows=1, converters={32: lambda x:... | spark-xgboost-nv-release_1.4.0 | demo/kaggle-higgs/higgs-numpy.py |
#!/usr/bin/python
# this is the example script to use xgboost to train
import numpy as np
import xgboost as xgb
from sklearn.ensemble import GradientBoostingClassifier
import time
test_size = 550000
# path to where the data lies
dpath = 'data'
# load in training data, directly use numpy
dtrain = np.loadtxt( dpath+'/t... | spark-xgboost-nv-release_1.4.0 | demo/kaggle-higgs/speedtest.py |
#!/usr/bin/python
# make prediction
import numpy as np
import xgboost as xgb
# path to where the data lies
dpath = 'data'
modelfile = 'higgs.model'
outfile = 'higgs.pred.csv'
# make top 15% as positive
threshold_ratio = 0.15
# load in training data, directly use numpy
dtest = np.loadtxt( dpath+'/test.csv', delimiter... | spark-xgboost-nv-release_1.4.0 | demo/kaggle-higgs/higgs-pred.py |
import os
import xgboost as xgb
### simple example for using external memory version
# this is the only difference, add a # followed by a cache prefix name
# several cache file with the prefix will be generated
# currently only support convert from libsvm file
CURRENT_DIR = os.path.dirname(__file__)
dtrain = xgb.DMat... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/external_memory.py |
'''Demo for creating customized multi-class objective function. This demo is
only applicable after (excluding) XGBoost 1.0.0, as before this version XGBoost
returns transformed prediction for multi-class objective function. More
details in comments.
'''
import numpy as np
import xgboost as xgb
from matplotlib impor... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/custom_softmax.py |
'''A demo for defining data iterator.
.. versionadded:: 1.2.0
The demo that defines a customized iterator for passing batches of data into
`xgboost.DeviceQuantileDMatrix` and use this `DeviceQuantileDMatrix` for
training. The feature is used primarily designed to reduce the required GPU
memory for training on di... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/data_iterator.py |
import os
import xgboost as xgb
CURRENT_DIR = os.path.dirname(__file__)
dtrain = xgb.DMatrix(os.path.join(CURRENT_DIR, '../data/agaricus.txt.train'))
dtest = xgb.DMatrix(os.path.join(CURRENT_DIR, '../data/agaricus.txt.test'))
watchlist = [(dtest, 'eval'), (dtrain, 'train')]
###
# advanced: start from a initial base p... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/boost_from_prediction.py |
'''Using feature weight to change column sampling.
.. versionadded:: 1.3.0
'''
import numpy as np
import xgboost
from matplotlib import pyplot as plt
import argparse
def main(args):
rng = np.random.RandomState(1994)
kRows = 1000
kCols = 10
X = rng.randn(kRows, kCols)
y = rng.randn(kRows)
... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/feature_weights.py |
'''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 RMSLE metric as customized
functions, then compare it with native implementation in XGBoost.
See doc/tutorials/custom_... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/custom_rmsle.py |
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import load_boston
import xgboost as xgb
import multiprocessing
if __name__ == "__main__":
print("Parallel Parameter optimization")
boston = load_boston()
y = boston['target']
X = boston['data']
xgb_model = xgb.XGBRegressor(n_j... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/sklearn_parallel.py |
'''
Created on 1 Apr 2015
@author: Jamie Hall
'''
import pickle
import xgboost as xgb
import numpy as np
from sklearn.model_selection import KFold, train_test_split, GridSearchCV
from sklearn.metrics import confusion_matrix, mean_squared_error
from sklearn.datasets import load_iris, load_digits, load_boston
rng = np... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/sklearn_examples.py |
###
# advanced: customized loss function
#
import os
import numpy as np
import xgboost as xgb
print('start running example to used customized objective function')
CURRENT_DIR = os.path.dirname(__file__)
dtrain = xgb.DMatrix(os.path.join(CURRENT_DIR, '../data/agaricus.txt.train'))
dtest = xgb.DMatrix(os.path.join(CURR... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/custom_objective.py |
import xgboost as xgb
import numpy as np
# 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 xgboost/demo/data.
data = np.genfromtxt('../data/autoclaims.csv',... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/gamma_regression.py |
import os
import numpy as np
import xgboost as xgb
from sklearn.datasets import load_svmlight_file
CURRENT_DIR = os.path.dirname(__file__)
train = os.path.join(CURRENT_DIR, "../data/agaricus.txt.train")
test = os.path.join(CURRENT_DIR, "../data/agaricus.txt.test")
def native_interface():
# load data in do traini... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/predict_first_ntree.py |
'''
Demo for using and defining callback functions.
.. versionadded:: 1.3.0
'''
import xgboost as xgb
import tempfile
import os
import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from matplotlib import pyplot as plt
import argparse
class Plotti... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/callbacks.py |
##
# This script demonstrate how to access the eval metrics in xgboost
##
import os
import xgboost as xgb
CURRENT_DIR = os.path.dirname(__file__)
dtrain = xgb.DMatrix(os.path.join(CURRENT_DIR, '../data/agaricus.txt.train'))
dtest = xgb.DMatrix(os.path.join(CURRENT_DIR, '../data/agaricus.txt.test'))
param = [('max_de... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/evals_result.py |
import os
import xgboost as xgb
# load data in do training
CURRENT_DIR = os.path.dirname(__file__)
dtrain = xgb.DMatrix(os.path.join(CURRENT_DIR, '../data/agaricus.txt.train'))
dtest = xgb.DMatrix(os.path.join(CURRENT_DIR, '../data/agaricus.txt.test'))
param = {'max_depth': 2, 'eta': 1, 'objective': 'binary:logistic'}... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/predict_leaf_indices.py |
##
# This script demonstrate how to access the xgboost eval metrics by using sklearn
##
import xgboost as xgb
import numpy as np
from sklearn.datasets import make_hastie_10_2
X, y = make_hastie_10_2(n_samples=2000, random_state=42)
# Map labels from {-1, 1} to {0, 1}
labels, y = np.unique(y, return_inverse=True)
X... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/sklearn_evals_result.py |
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, '../data/agaricus.txt.train'))
dtest = xgb.DMat... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/generalized_linear_model.py |
import os
import numpy as np
import xgboost as xgb
# load data in do training
CURRENT_DIR = os.path.dirname(__file__)
dtrain = xgb.DMatrix(os.path.join(CURRENT_DIR, '../data/agaricus.txt.train'))
param = {'max_depth':2, 'eta':1, 'objective':'binary:logistic'}
num_round = 2
print('running cross validation')
# do cross... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/cross_validation.py |
import numpy as np
import scipy.sparse
import pickle
import xgboost as xgb
import os
# Make sure the demo knows where to load the data.
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
XGBOOST_ROOT_DIR = os.path.dirname(os.path.dirname(CURRENT_DIR))
DEMO_DIR = os.path.join(XGBOOST_ROOT_DIR, 'demo')
# simple e... | spark-xgboost-nv-release_1.4.0 | demo/guide-python/basic_walkthrough.py |
import xgboost as xgb
from sklearn.datasets import fetch_covtype
from sklearn.model_selection import train_test_split
import time
# 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.25... | spark-xgboost-nv-release_1.4.0 | demo/gpu_acceleration/cover_type.py |
#!/usr/bin/python
import xgboost as xgb
from sklearn.datasets import load_svmlight_file
# This script demonstrate how to do ranking with XGBRanker
x_train, y_train = load_svmlight_file("mq2008.train")
x_valid, y_valid = load_svmlight_file("mq2008.vali")
x_test, y_test = load_svmlight_file("mq2008.test")
group_train ... | spark-xgboost-nv-release_1.4.0 | demo/rank/rank_sklearn.py |
import sys
def save_data(group_data,output_feature,output_group):
if len(group_data) == 0:
return
output_group.write(str(len(group_data))+"\n")
for data in group_data:
# only include nonzero features
feats = [ p for p in data[2:] if float(p.split(':')[1]) != 0.0 ]
output_fe... | spark-xgboost-nv-release_1.4.0 | demo/rank/trans_data.py |
#!/usr/bin/python
import xgboost as xgb
from xgboost import DMatrix
from sklearn.datasets import load_svmlight_file
# This script demonstrate how to do ranking with xgboost.train
x_train, y_train = load_svmlight_file("mq2008.train")
x_valid, y_valid = load_svmlight_file("mq2008.vali")
x_test, y_test = load_svmlight_... | spark-xgboost-nv-release_1.4.0 | demo/rank/rank.py |
import boto3
import json
lambda_client = boto3.client('lambda', region_name='us-west-2')
# Source code for the Lambda function is available at https://github.com/hcho3/xgboost-devops
r = lambda_client.invoke(
FunctionName='XGBoostCICostWatcher',
InvocationType='RequestResponse',
Payload='{}'.encode('utf-8... | spark-xgboost-nv-release_1.4.0 | tests/jenkins_get_approval.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... | spark-xgboost-nv-release_1.4.0 | tests/benchmark/benchmark_tree.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')
... | spark-xgboost-nv-release_1.4.0 | tests/benchmark/benchmark_linear.py |
"""Generate synthetic data in LibSVM format."""
import argparse
import io
import time
import numpy as np
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
RNG = np.random.RandomState(2019)
def generate_data(args):
"""Generates the data."""
print("Generati... | spark-xgboost-nv-release_1.4.0 | tests/benchmark/generate_libsvm.py |
import sys
import re
import zipfile
import glob
if len(sys.argv) != 2:
print('Usage: {} [wheel]'.format(sys.argv[0]))
sys.exit(1)
vcomp140_path = 'C:\\Windows\\System32\\vcomp140.dll'
for wheel_path in sorted(glob.glob(sys.argv[1])):
m = re.search(r'xgboost-(.*)-py3', wheel_path)
assert m, f'wheel_pa... | spark-xgboost-nv-release_1.4.0 | tests/ci_build/insert_vcomp140.py |
import sys
import os
from contextlib import contextmanager
@contextmanager
def cd(path):
path = os.path.normpath(path)
cwd = os.getcwd()
os.chdir(path)
print("cd " + path)
try:
yield path
finally:
os.chdir(cwd)
if len(sys.argv) != 4:
print('Usage: {} [wheel to rename] [comm... | spark-xgboost-nv-release_1.4.0 | tests/ci_build/rename_whl.py |
import argparse
import os
import subprocess
ROOT = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), os.path.pardir,
os.path.pardir))
r_package = os.path.join(ROOT, 'R-package')
class DirectoryExcursion:
def __init__(self, path: os.PathLike):
self.path = path... | spark-xgboost-nv-release_1.4.0 | tests/ci_build/test_r_package.py |
#!/usr/bin/env python
import subprocess
import yaml
import json
from multiprocessing import Pool, cpu_count
import shutil
import os
import sys
import re
import argparse
from time import time
def call(args):
'''Subprocess run wrapper.'''
completed = subprocess.run(args,
stdout=su... | spark-xgboost-nv-release_1.4.0 | tests/ci_build/tidy.py |
import xgboost as xgb
import testing as tm
import numpy as np
import pytest
import os
rng = np.random.RandomState(1337)
class TestTrainingContinuation:
num_parallel_tree = 3
def generate_parameters(self):
xgb_params_01_binary = {
'nthread': 1,
}
xgb_params_02_binary = {
... | spark-xgboost-nv-release_1.4.0 | tests/python/test_training_continuation.py |
# -*- coding: utf-8 -*-
import numpy as np
import os
import xgboost as xgb
import pytest
import json
from pathlib import Path
import tempfile
import testing as tm
dpath = 'demo/data/'
rng = np.random.RandomState(1994)
class TestBasic:
def test_compat(self):
from xgboost.compat import lazy_isinstance
... | spark-xgboost-nv-release_1.4.0 | tests/python/test_basic.py |
import xgboost as xgb
import testing as tm
import numpy as np
import pytest
rng = np.random.RandomState(1994)
class TestEarlyStopping:
@pytest.mark.skipif(**tm.no_sklearn())
def test_early_stopping_nonparallel(self):
from sklearn.datasets import load_digits
try:
from sklearn.mode... | spark-xgboost-nv-release_1.4.0 | tests/python/test_early_stopping.py |
# -*- coding: utf-8 -*-
import numpy as np
import xgboost as xgb
import testing as tm
import pytest
try:
import matplotlib
matplotlib.use('Agg')
from matplotlib.axes import Axes
from graphviz import Source
except ImportError:
pass
pytestmark = pytest.mark.skipif(**tm.no_multiple(tm.no_matplotlib(... | spark-xgboost-nv-release_1.4.0 | tests/python/test_plotting.py |
import xgboost
import os
import generate_models as gm
import testing as tm
import json
import zipfile
import pytest
import copy
import urllib.request
def run_model_param_check(config):
assert config['learner']['learner_model_param']['num_feature'] == str(4)
assert config['learner']['learner_train_param']['boo... | spark-xgboost-nv-release_1.4.0 | tests/python/test_model_compatibility.py |
# -*- coding: utf-8 -*-
import numpy as np
import xgboost
import testing as tm
import pytest
dpath = 'demo/data/'
rng = np.random.RandomState(1994)
class TestInteractionConstraints:
def run_interaction_constraints(self, tree_method):
x1 = np.random.normal(loc=1.0, scale=1.0, size=1000)
x2 = np.ra... | spark-xgboost-nv-release_1.4.0 | tests/python/test_interaction_constraints.py |
import numpy as np
import xgboost as xgb
from numpy.testing import assert_approx_equal
train_data = xgb.DMatrix(np.array([[1]]), label=np.array([1]))
class TestTreeRegularization:
def test_alpha(self):
params = {
'tree_method': 'exact', 'verbosity': 0,
'objective': 'reg:squareder... | spark-xgboost-nv-release_1.4.0 | tests/python/test_tree_regularization.py |
# -*- coding: utf-8 -*-
import numpy as np
import xgboost as xgb
import itertools
import re
import scipy
import scipy.special
dpath = 'demo/data/'
rng = np.random.RandomState(1994)
class TestSHAP:
def test_feature_importances(self):
data = np.random.randn(100, 5)
target = np.array([0, 1] * 50)
... | spark-xgboost-nv-release_1.4.0 | tests/python/test_shap.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.