安装
本机环境
-
操作系统:WIN10
Python:3.7.4
conda -v:4.8.2
尝试conda install xgboost不行,然后用下面三个命令
-
1、输入
anaconda search -t conda xgboost
来查找适合本机环境的包名,我的是
anaconda/py-xgboost
2、输入:
anaconda show anaconda/py-xgboost
来查看其安装命令
3、复制安装命令:
conda install --channel https://conda.anaconda.org/anaconda py-xgboost
使用
import numpy as np, matplotlib.pyplot as mp
from sklearn.datasets import make_moons
from xgboost import XGBClassifier as Clf
X, y = make_moons(n_samples=200, noise=.2)
clf = Clf()
clf.fit(X, y)
x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
xx, yy = np.meshgrid(np.arange(x_min, x_max, .01), np.arange(y_min, y_max, .01))
Z = clf.predict_proba(np.c_[xx.ravel(), yy.ravel()])[:, 1].reshape(xx.shape)
mp.contourf(xx, yy, Z, alpha=.3)
mp.scatter(X[:, 0], X[:, 1], s=50, c=y)
mp.show()
