July 2019
Beginner to intermediate
298 pages
7h 20m
English
For classification purposes, the corresponding class is implemented in XGBClassifier. The constructor's parameters are the same as the regression implementation. For our example, we use the hand-written digit classification problem. We set the n_estimators parameter to 100 and n_jobs to 4. The rest of the code follows the usual template:
# --- SECTION 1 ---# Libraries and data loadingfrom sklearn.datasets import load_digitsfrom xgboost import XGBClassifierfrom sklearn import metricsimport numpy as npdigits = load_digits()train_size = 1500train_x, train_y = digits.data[:train_size], digits.target[:train_size]test_x, test_y = digits.data[train_size:], digits.target[train_size:]np.random.seed(123456)# --- SECTION ...
Read now
Unlock full access