Simplify Python getting started example (#8153)
Load data set via `sklearn` rather than a local file path.
This commit is contained in:
parent
d868126c39
commit
20d1bba1bb
@ -19,16 +19,18 @@ Python
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
import xgboost as xgb
|
from xgboost import XGBClassifier
|
||||||
# read in data
|
# read data
|
||||||
dtrain = xgb.DMatrix('demo/data/agaricus.txt.train')
|
from sklearn.datasets import load_iris
|
||||||
dtest = xgb.DMatrix('demo/data/agaricus.txt.test')
|
from sklearn.model_selection import train_test_split
|
||||||
# specify parameters via map
|
data = load_iris()
|
||||||
param = {'max_depth':2, 'eta':1, 'objective':'binary:logistic' }
|
X_train, X_test, y_train, y_test = train_test_split(data['data'], data['target'], test_size=.2)
|
||||||
num_round = 2
|
# create model instance
|
||||||
bst = xgb.train(param, dtrain, num_round)
|
bst = XGBClassifier(n_estimators=2, max_depth=2, learning_rate=1, objective='binary:logistic')
|
||||||
# make prediction
|
# fit model
|
||||||
preds = bst.predict(dtest)
|
bst.fit(X_train, y_train)
|
||||||
|
# make predictions
|
||||||
|
preds = bst.predict(X_test)
|
||||||
|
|
||||||
***
|
***
|
||||||
R
|
R
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user