-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from dmlc/master
Getting latest version from dmlc
- Loading branch information
Showing
6 changed files
with
168 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## | ||
# This script demonstrate how to access the eval metrics in xgboost | ||
## | ||
|
||
import xgboost as xgb | ||
dtrain = xgb.DMatrix('../data/agaricus.txt.train', silent=True) | ||
dtest = xgb.DMatrix('../data/agaricus.txt.test', silent=True) | ||
|
||
param = [('max_depth', 2), ('objective', 'binary:logistic'), ('eval_metric', 'logloss'), ('eval_metric', 'error')] | ||
|
||
num_round = 2 | ||
watchlist = [(dtest,'eval'), (dtrain,'train')] | ||
|
||
evals_result = {} | ||
bst = xgb.train(param, dtrain, num_round, watchlist, evals_result=evals_result) | ||
|
||
print('Access logloss metric directly from evals_result:') | ||
print(evals_result['eval']['logloss']) | ||
|
||
print('') | ||
print('Access metrics through a loop:') | ||
for e_name, e_mtrs in evals_result.items(): | ||
print('- {}'.format(e_name)) | ||
for e_mtr_name, e_mtr_vals in e_mtrs.items(): | ||
print(' - {}'.format(e_mtr_name)) | ||
print(' - {}'.format(e_mtr_vals)) | ||
|
||
print('') | ||
print('Access complete dictionary:') | ||
print(evals_result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
## | ||
# 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_train, X_test = X[:1600], X[1600:] | ||
y_train, y_test = y[:1600], y[1600:] | ||
|
||
param_dist = {'objective':'binary:logistic', 'n_estimators':2} | ||
|
||
clf = xgb.XGBModel(**param_dist) | ||
# Or you can use: clf = xgb.XGBClassifier(**param_dist) | ||
|
||
clf.fit(X_train, y_train, | ||
eval_set=[(X_train, y_train), (X_test, y_test)], | ||
eval_metric='logloss', | ||
verbose=True) | ||
|
||
# Load evals result by calling the evals_result() function | ||
evals_result = clf.evals_result() | ||
|
||
print('Access logloss metric directly from validation_0:') | ||
print(evals_result['validation_0']['logloss']) | ||
|
||
print('') | ||
print('Access metrics through a loop:') | ||
for e_name, e_mtrs in evals_result.items(): | ||
print('- {}'.format(e_name)) | ||
for e_mtr_name, e_mtr_vals in e_mtrs.items(): | ||
print(' - {}'.format(e_mtr_name)) | ||
print(' - {}'.format(e_mtr_vals)) | ||
|
||
print('') | ||
print('Access complete dict:') | ||
print(evals_result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters