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()
作者:基基伟