-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxgboost_visual_explanation.py
More file actions
69 lines (34 loc) · 939 Bytes
/
xgboost_visual_explanation.py
File metadata and controls
69 lines (34 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# coding: utf-8
# # Setup
# In[24]:
get_ipython().magic('matplotlib inline')
import numpy as np
import pandas as pd
import xgboost
import sklearn.datasets
import sklearn.model_selection
import sklearn.metrics
# # [Example 1](http://machinelearningmastery.com/develop-first-xgboost-model-python-scikit-learn/)
# In[25]:
data = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data',
header=None)
data = np.array(data)
X_train = data[:, :-1]
y_train = data[:, -1]
mdl = xgboost.XGBClassifier()
mdl.fit(X_train, y_train)
# In[26]:
xgboost.plot_importance(mdl)
# In[27]:
xgboost.plot_tree(mdl)
# # Example 2: Iris
# In[28]:
data = sklearn.datasets.load_iris()
X_train = data.data
y_train = data.target
mdl = xgboost.XGBClassifier()
mdl.fit(X_train, y_train)
# In[29]:
xgboost.plot_tree(mdl)
# In[30]:
xgboost.plot_importance(mdl)