Update Python demos with tests. (#5651)
* Remove GPU memory usage demo. * Add tests for demos. * Remove `silent`. * Remove shebang as it's not portable.
This commit is contained in:
@@ -1,29 +1,11 @@
|
||||
import os
|
||||
from sklearn.model_selection import GridSearchCV
|
||||
from sklearn.datasets import load_boston
|
||||
import xgboost as xgb
|
||||
|
||||
if __name__ == "__main__":
|
||||
# NOTE: on posix systems, this *has* to be here and in the
|
||||
# `__name__ == "__main__"` clause to run XGBoost in parallel processes
|
||||
# using fork, if XGBoost was built with OpenMP support. Otherwise, if you
|
||||
# build XGBoost without OpenMP support, you can use fork, which is the
|
||||
# default backend for joblib, and omit this.
|
||||
try:
|
||||
from multiprocessing import set_start_method
|
||||
except ImportError:
|
||||
raise ImportError("Unable to import multiprocessing.set_start_method."
|
||||
" This example only runs on Python 3.4")
|
||||
set_start_method("forkserver")
|
||||
|
||||
import numpy as np
|
||||
from sklearn.model_selection import GridSearchCV
|
||||
from sklearn.datasets import load_boston
|
||||
import xgboost as xgb
|
||||
|
||||
rng = np.random.RandomState(31337)
|
||||
|
||||
print("Parallel Parameter optimization")
|
||||
boston = load_boston()
|
||||
|
||||
os.environ["OMP_NUM_THREADS"] = "2" # or to whatever you want
|
||||
y = boston['target']
|
||||
X = boston['data']
|
||||
xgb_model = xgb.XGBRegressor()
|
||||
|
||||
Reference in New Issue
Block a user